Solved Question about looping.

  • 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 comminuty!

    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!

Status
Not open for further replies.

zaaaaak

VIP
Aug 8, 2017
8
0
1
Looping help since I am new to Skript.
Let's say you had your average command.

command /hi:
trigger:
message "hi"


How would I add a looping system to this so when the player types the /hi command, the code will continue to run to the player every 40 seconds?

So 40 seconds pass by and they receive "Hi"
Another 40 seconds "Hi", etc...

But once they type /hi, this loop stops. Also, it is okay if it still says the "Hi" message one last time after the command is typed again.

Thanks for the help :emoji_grinning:
 
You would need to use a variable to store a value, such as a boolean, and a while loop. So while something is true the loop will continue, as soon as they run the command again, set the variable to false and the loop will stop
code_language.skript:
on join:
    set {loopHI::%player%} to false
    
command /hi:
    trigger:
        if {loopHI::%player%} is false:
            set {loopHI::%player%} to true
        else:
            set {loopHI::%player%} to false
        while {loopHI::%player%} is true:
            send "hi" to player
            wait 40 seconds
 
  • Like
Reactions: zaaaaak
You would need to use a variable to store a value, such as a boolean, and a while loop. So while something is true the loop will continue, as soon as they run the command again, set the variable to false and the loop will stop
code_language.skript:
on join:
    set {loopHI::%player%} to false
   
command /hi:
    trigger:
        if {loopHI::%player%} is false:
            set {loopHI::%player%} to true
        else:
            set {loopHI::%player%} to false
        while {loopHI::%player%} is true:
            send "hi" to player
            wait 40 seconds
You could as well just clear the variable instead of setting it to false
[doublepost=1562162468,1562162435][/doublepost]And pretty sure it'd error when the player leaves
 
  • Like
Reactions: zaaaaak
Status
Not open for further replies.