Solved Variables getting reset on every while loop

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

MultiverShaun

Member
Aug 8, 2022
27
3
3
Hi, I've set up a simple counter that increases a variable's value by 1 every second. However, it seems that the variable is set to null every start of the while loop. What's weird, though, is that the counter does seem to save while in the while loop, but anything outside the while loop or at the very very start of the while loop will simply display null. Am I doing something wrong? Thanks a lot in advance!

Code:
on join:
    while player is online:
        #Where I suspect the variable gets reset to null
        add 1 to {_counter::%player%}
        send "Counter: &7%{_counter::%player%}%" to player #Outputs the correct values (1, 2, 3, etc.)
        wait 1 second
        #Variable still has value

command /counter:
    trigger:
        send "Counter: &7%{_counter::%player%}%" to player #Returns null
 
That's because an underscore defines a local variable. Instead it should be {counter::%player%}.
 
Status
Not open for further replies.