Solved Trouble with optimizing skript

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Doodle

Well-Known Member
Sep 3, 2023
490
63
28
I was trying to simplify my skript since it took up 75 lines, and I was making progress until I got stumped. I don't know what to do in this situation:

Code:
else:
    set {_amount} to min(arg-1, 6)
    loop {_amount} times:
        add player's tool to player's inventory
    if {_amount} is 1:
        send action bar "&aSuccessfully duped item." to player
    else:
        send action bar "&aSuccessfully duped %{_amount}% items." to player
    if player has permission "everyitem.invest.dupe":
        remove 100$ from player's balance
    else:
        remove 250$ from player's balance

If you don't see the problem, there are two if:'s on the same indent. Is there any work-around, or is the code fine like this? Please let me know.
 
I was trying to simplify my skript since it took up 75 lines, and I was making progress until I got stumped. I don't know what to do in this situation:

Code:
else:
    set {_amount} to min(arg-1, 6)
    loop {_amount} times:
        add player's tool to player's inventory
    if {_amount} is 1:
        send action bar "&aSuccessfully duped item." to player
    else:
        send action bar "&aSuccessfully duped %{_amount}% items." to player
    if player has permission "everyitem.invest.dupe":
        remove 100$ from player's balance
    else:
        remove 250$ from player's balance

If you don't see the problem, there are two if:'s on the same indent. Is there any work-around, or is the code fine like this? Please let me know.
You can use ‘else if’ statements. I think that could make your code a bit more effective.
 
You can use ‘else if’ statements. I think that could make your code a bit more effective.
See, that's the problem. It's two different lines of code that both do different things. If I were to use an else if: statement, it could potentially prevent some of my code from running.
 
See, that's the problem. It's two different lines of code that both do different things. If I were to use an else if: statement, it could potentially prevent some of my code from running.
Code:
function checkperm(p: player):
   if {_p} has permission "every item.invest.dupe":
      remove 100 from {_p}'s balance
  else:
      remove 250 from {_p}'s balance
Maybe you can use this function and call it before any if and else statement below your first else statement, ie:

Code:
else:
   checkperm(player)
# The rest of your code here
 
  • Like
Reactions: Doodle
Code:
function checkperm(p: player):
   if {_p} has permission "every item.invest.dupe":
      remove 100 from {_p}'s balance
  else:
      remove 250 from {_p}'s balance
Maybe you can use this function and call it before any if and else statement below your first else statement, ie:

Code:
else:
   checkperm(player)
# The rest of your code here
Hypothetically, could I write it like this:

Code:
checkperm(player)
if {_amount} is 1:
    send action bar "text bc I'm too lazy to write" to player
else:
    send action bar "more useless text" to player
 
I just realized I could have just used the word stop after the first 'else:' condition, but you gave me the motivation to learn more about functions and really helped me with making my code more efficient and keeping it simple at the same time. Thanks!
 
  • Like
Reactions: Luke_Sky_Walker