Strange Loop Behavior

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

DannyDaMannyy

Member
Dec 16, 2023
20
1
3
Hey, I can't figure out why this code is acting so strangely. It should add 1 to {timerGREEN} every 10 seconds, as long as there is a black standing banner in that specific zone, and under no other circumstances. However, it seems to spuratically and semi randomly add points, all in the range of 1-5 points, in 2-10 seconds. Its very frustrating. As far as I can tell, theres no other code that should change its behavior in the script.


Code:
on click:
    wait 1 tick
    if block at location at 12026, 70, 1409 in world "SMP_World" is not black standing banner:
        if "%region at event-block%" contains "green in world SMP_World":
            wait 1 tick           
            set block at location at 12026, 70, 1409 in world "SMP_World" to air
on load:
    loop 1000000000 times:
        wait 1 tick
        if block at location at 12026, 70, 1409 in world "SMP_World" is black standing banner:
            loop 1000000000 times:
                add 1 to {timerGREEN}
                wait 10 seconds
                if block at location at 12026, 70, 1409 in world "SMP_World" is not black standing banner:
                    stop loop
 
Hey, I can't figure out why this code is acting so strangely. It should add 1 to {timerGREEN} every 10 seconds, as long as there is a black standing banner in that specific zone, and under no other circumstances. However, it seems to spuratically and semi randomly add points, all in the range of 1-5 points, in 2-10 seconds. Its very frustrating. As far as I can tell, theres no other code that should change its behavior in the script.


Code:
on click:
    wait 1 tick
    if block at location at 12026, 70, 1409 in world "SMP_World" is not black standing banner:
        if "%region at event-block%" contains "green in world SMP_World":
            wait 1 tick        
            set block at location at 12026, 70, 1409 in world "SMP_World" to air
on load:
    loop 1000000000 times:
        wait 1 tick
        if block at location at 12026, 70, 1409 in world "SMP_World" is black standing banner:
            loop 1000000000 times:
                add 1 to {timerGREEN}
                wait 10 seconds
                if block at location at 12026, 70, 1409 in world "SMP_World" is not black standing banner:
                    stop loop
I think you're doing too many loops there. What I would do: If the banner is set, I would then set a separate variable to "true". Then every 10 seconds (Not a loop), it will check if that value is true (If true, it will add to that timer). Loops are if you wanna do things multiple times. You're looping it to add 1 to Green's Timer then wait to seconds but to do that MANY times. It also has no delay before that which would explain its sporadic nature. My solution would eliminate the need to have an on load event and would also likely have your code running smoother :emoji_slight_smile:
 
Last edited:
  • Like
Reactions: DannyDaMannyy
Oh! I hadnt though about all the loops. Now that you point it out, I see how it's an inneficient code. I'll try your suggestions, and get back to ya! Thank you:emoji_stuck_out_tongue:
-Dan
 
Got rid of all the loops, tweaked the code a little (because event-block is not a possible term outside a loop, apparently)
Thank you! -Dan