Solved Script that makes you slow down when tired, but you're always tired

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

Chociily

New Member
Mar 8, 2023
6
0
1
Skript Version: 2.6.4
Minecraft Version: 1.19.3

This is my 5th day learning Skript, and I've run across a problem... If you sprint for a certain duration of time while not flying, you gain tiredness. It slowly goes away as you avoid sprinting. However, for some reason no matter what I am always slow. I reused part of the code for something else I made that worked fine, so I am completely lost here.

Any help would be appreciated.

Code:
on every tick:
    loop all players:
        set {_uuid} to uuid of loop-player
        if loop-player is sprinting:

            # Reverts/ignores tiredness if the player is flying
            if loop-player is flying:
                if {-tiredness.%uuid of loop-player%} > 0:
                    remove 1 from {-tiredness.%uuid of loop-player%}

            # Makes the player slowly become tired if they are not flying
            else if {-tiredness.%uuid of loop-player%} <= 500:
                add 1 to {-tiredness.%uuid of loop-player%}

        # Takes away tiredness when the player is not sprinting
        else if {-tiredness.%uuid of loop-player%} > 0:
            remove 1 from {-tiredness.%uuid of loop-player%}

        # Determines effects on players based on tiredness levels

        # Not tired
        if {-tiredness.%uuid of loop-player%} < 200:
            reset walk speed of loop-player

        # Tired
        else:
            set loop-player's walk speed to 0.15
 
Hi. Some debugging steps would be to send {-tiredness.%uuid of loop-player%} to loop-player to actually be able to see how the variable is treated. Additionally, I would recommend using :: instead of . ({-tiredness::%uuid of loop-player%}). It lets you do more things with the variable such as looping through it or getting the amount of variables set. I believe it's also stored more efficiently.

Regardless, all of your variable changing relies on the variable actually being set, which it isn't. Right when you loop all players, if the variable isn't set, set it to 0.

Hope this helped.
 
Hi. Some debugging steps would be to send {-tiredness.%uuid of loop-player%} to loop-player to actually be able to see how the variable is treated. Additionally, I would recommend using :: instead of . ({-tiredness::%uuid of loop-player%}). It lets you do more things with the variable such as looping through it or getting the amount of variables set. I believe it's also stored more efficiently.

Regardless, all of your variable changing relies on the variable actually being set, which it isn't. Right when you loop all players, if the variable isn't set, set it to 0.

Hope this helped.
How do I make the debugging stuff show up? It just gives me an error. Sorry, I'm new to this.
upload_2023-3-8_17-41-47.png


I also tried setting tiredness to 0, but it was stuck at being not tired. When I deleted the line that set it to 0 and reloaded the script, it was stuck again at being tired. This is so frustrating because none of my other scripts are doing this, and none of them have anything set initially.
 
That's not what I meant. Disregard my comment about :: for now, and just look up list variables later.
- To send a message, you need to send a text. Your variable is a number. Do:
Code:
send "%{-tiredness.%uuid of loop-player%}%" to loop-player
for that.
Additionally, it sounds like you didn't add the if statement I mentioned:
Code:
if {-tiredness.%uuid of loop-player%} isn't set:
  set {-tiredness.%uuid of loop-player%} to 0
[doublepost=1678315671,1678315605][/doublepost]
That's not what I meant. Disregard my comment about :: for now, and just look up list variables later.
- To send a message, you need to send a text. Your variable is a number. Do:
Code:
send "%{-tiredness.%uuid of loop-player%}%" to loop-player
for that.
Additionally, it sounds like you didn't add the if statement I mentioned:
Code:
if {-tiredness.%uuid of loop-player%} isn't set:
  set {-tiredness.%uuid of loop-player%} to 0
Double reply, sorry. The reason other scripts don't need to set variables initially is likely because they don't *only* change the variable within if statements that require it to be set. For more clarification, all of your if statements require the variable to be compared with something, and it needs to be set to be compared.
 
upload_2023-3-8_17-47-33.png

I am so confused, all I did was add that line with showing debugging and now it works. I did not add the other line with setting it.
 
Super odd. Mind posting the new code..?
Code:
on every tick:
    loop all players:
        set {_uuid} to uuid of loop-player
        if loop-player is sprinting:

            # Reverts/ignores tiredness if the player is flying
            if loop-player is flying:
                if {-tiredness.%uuid of loop-player%} > 0:
                    remove 1 from {-tiredness.%uuid of loop-player%}

            # Makes the player slowly become tired if they are not flying
            else if {-tiredness.%uuid of loop-player%} <= 500:
                add 1 to {-tiredness.%uuid of loop-player%}

        # Takes away tiredness when the player is not sprinting
        else if {-tiredness.%uuid of loop-player%} > 0:
            remove 1 from {-tiredness.%uuid of loop-player%}

        # Determines effects on players based on tiredness levels

        # Not tired
        if {-tiredness.%uuid of loop-player%} < 10:
            reset walk speed of loop-player

        # Tired
        else:
            set loop-player's walk speed to 0.05
 
That honestly just looks the exact same, with the exception of the number being changed on 22. Was that the issue? I'm genuinely at a loss here.
 
I don't know. Basically, it didn't work before, and now it works just by adding that debug code. I find it so weird that it was acting this way when my other codes worked... and now it works fine when I force it to show the variables. I remember trying everything like changing the range at which tiredness starts, etc. including flipping the greater than sign and both ways would be stuck at being permanently tired. Maybe it's a bug with Skript itself?
 
Maybe it's a bug with Skript itself?
I doubt that's the case. Either way, it works now? If it operates how you want it, please mark this as solved (it's in some edit title button).
 
Status
Not open for further replies.