Solved Looping commands

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

Status
Not open for further replies.

JackyBoy

Member
Feb 4, 2017
104
1
18
Hey there, I am currently working on a new script and I was unsure if there is a way to loop a command for a certain time. The command would be something like this

/test 5 3
(The 5 stands for the present system that I have and the 3 stands for a number of seconds the loop will run for)

if arg 1 is "5":
loop in game command here which is run from console for 3 seconds using the %arg-2%
 
code_language.skript:
loop arg-2 times:
    make player execute command "/Im loop this ""%arg-2%"" times"
    make console execute command "/lel, console can this too"
 
code_language.skript:
loop arg-2 times:
    make player execute command "/Im loop this ""%arg-2%"" times"
    make console execute command "/lel, console can this too"
Thanks :emoji_slight_smile:
[doublepost=1499953649,1499952368][/doublepost]Hey, it is saying that the loop arg-2 times part is not working (this is the error message when I reload the script file)
Screenshot_25.png
 
This wouldn't do what you want anyways. It would just run the code 3 times, not for 3 seconds like you said you wanted.

I think something like this is more what you want:
code_language.skript:
command /test <integer> <integer>:
    trigger:
        if arg-1 is 5:
            set {looping.%player%} to true
            set {elapsed_time.%player%} to 0
            while {looping.%player%} is true:
                if {elapsed_time.%player%} is greater than (arg-2 * 20): #you need to multiply arg-2 by 20 since it's in seconds and elapsed time is in ticks
                    set {looping.%player%} to false
                    stop
                execute console command "whatever"
                add 1 to {elapsed_time.%player%}
                wait a tick
 
Last edited by a moderator:
Thanks but is there a way to make it so the loop is will repeat the command inside of the loop for a number of seconds?
 
The code I posted up there ^ will repeat the command every tick for arg-2 seconds
 
The code I posted up there ^ will repeat the command every tick for arg-2 seconds

Oh, I see. One last thing you said "#you need to multiply elapsed time by" what do I multiply by?
 
20. I wrote that does it not show up lol? I also included it in the code
 
Wait I meant you need to multiply arg-2 by 20 sorry my bad
 
Status
Not open for further replies.