Jump to content

Variables


Ikey

Recommended Posts

Hey. I'm writing a skript for my server for the boat race event im working on. I have got stuck at the highscore stage.

What I'm trying to do:
When you complete the event, it will check if your highscore is greater than the current time, if it is then it will set the highscore to the time that you just done on the event.

If its not less than your current highscore, then it will just say the time you completed.

Whats wrong:
Whenever I try the skript it breaks. The highscore is never really set to anything and if it is set to something then it is set to <none>

The skript doesn't whats inside the timer variable, and if its grater than or less than the highscore.

The skript (important parts from it):

command /highscore:
   trigger:
      send "{@prefix} &fYour highscore on the Boat Race is &6{event.highscore.%player%}%"

#Part where I think it doesn't work. I dont know to either set it as a integer or number or what
if {timer.total.%player%} < {event.highscore.%player%}:
   set {timer.total.%player%} to {event.highscore.%player%}
   send "{@prefix} &fYou have beat your highscore with the time of &6%{event.highscore.%player%}%"
if {timer.total.%player%} > {event.highscore.%player%}:
   send "{@prefix} &fYou have finished the boat race with the time of &6%{timer.total.%player%}%"
 
command /timer:
   trigger:
      set {timer.%player%} to true
      set {_start} to now
      while {timer.%player%} is true:
         set {timer.total.%player%} to difference between now and {_start}
         set {event.boatrace.lap} to 0
         send action bar "&bLap %{lap.%player%}%/3 &b%{timer.total.%player%}" to player
         wait 1 second
command /timerstop:
    trigger:
        set {timer.%player%} to false

 

Edited by Ikey

Owner of ikeysurviv.minehut.gg

 

⊱------------------------------⊰

[LEGEND] on Minehut

⊱------------------------------⊰

In-game name - ikeyIX

Discord name - ikeyIX#2007

Link to comment
Share on other sites

So, I think I have found the error.

Here is the code from where I expect its going wrong:
 

command /timer:
   trigger:
      set {timer.%player%} to true
      set {_start} to now
      while {timer.%player%} is true:
         set {timer.total.%player%} to difference between now and {_start}
         set {event.boatrace.lap} to 0
         send action bar "&bLap %{lap.%player%}%/3 &b%{timer.total.%player%}" to player
         wait 1 second
command /timerstop:
    trigger:
        set {timer.%player%} to false

So, here is what I think is happening:

The {timer.total.%player%} variable is getting set to how much seconds that the stopwatch has been on for, but it is adding the "seconds" word to the end of the variable. Has anyone any idea how to remove the "seconds" part out of the variable so I can set it as a integer or number?

Thanks.

Owner of ikeysurviv.minehut.gg

 

⊱------------------------------⊰

[LEGEND] on Minehut

⊱------------------------------⊰

In-game name - ikeyIX

Discord name - ikeyIX#2007

Link to comment
Share on other sites

4 minutes ago, Ikey said:

So, I think I have found the error.

Here is the code from where I expect its going wrong:
 

command /timer:
   trigger:
      set {timer.%player%} to true
      set {_start} to now
      while {timer.%player%} is true:
         set {timer.total.%player%} to difference between now and {_start}
         set {event.boatrace.lap} to 0
         send action bar "&bLap %{lap.%player%}%/3 &b%{timer.total.%player%}" to player
         wait 1 second
command /timerstop:
    trigger:
        set {timer.%player%} to false

So, here is what I think is happening:

The {timer.total.%player%} variable is getting set to how much seconds that the stopwatch has been on for, but it is adding the "seconds" word to the end of the variable. Has anyone any idea how to remove the "seconds" part out of the variable so I can set it as a integer or number?

Thanks.

you can use something like this

replace all "seconds" with "" in {variable}
set {variable} to {variable} parsed as integer

 

 

 

image.png.bc433d6489d70ad831075fe76809b993.png
 

Owner of Lifestealed, Labs, Encore, UNOfficially and Observed
 

OG [VIP] 12/26/20 - 10/27/2021
OG [PRO] 12/27/21 - 11/18/2022
OG [LEGEND] 11/18/2022 - 3/14/2023
[DEFAULT] 3/14/2023 - 5/8/2024

[MOD] 5/8/2024 - Present

 

Link to comment
Share on other sites

3 minutes ago, AgentGamerPro said:

you can use something like this

replace all "seconds" with "" in {variable}
set {variable} to {variable} parsed as integer

 

thanks!

Owner of ikeysurviv.minehut.gg

 

⊱------------------------------⊰

[LEGEND] on Minehut

⊱------------------------------⊰

In-game name - ikeyIX

Discord name - ikeyIX#2007

Link to comment
Share on other sites

11 hours ago, AgentGamerPro said:

you can use something like this

replace all "seconds" with "" in {variable}
set {variable} to {variable} parsed as integer

 

Ok so I've tried a bit of testing.

The problem is still here as it is still sending the "seconds" text string along with the number. Here is the code that I have at the minute which isn't working.

command /timer:
    trigger:
        set {timer.%player%} to true
        set {_start} to now
        while {timer.%player%} is true:
            set {timer.total.%player%} to difference between now and {_start}
            set {event.boatrace.lap} to 0
            send action bar "&bLap %{lap.%player%}%/3 &b%{timer.total.%player%}%" to player
            wait 1 second
command /timerstop:
    trigger:
        set {timer.%player%} to false
        set {total.%player%} to {timer.total.%player%}
        set {timer.total.%player%} to {total.%player%}
        replace all "seconds" with "" in {total.%player%}
        send "{@prefix} &b%{total.%player%}%"

Does it look like I have done anything wrong becau se this is the text feed that is coming back after I do /timerstop:
image.png.148093651d6318658ff7500259224c62.png

The skript has no errors so I'm lost on whats wrong.

Thanks.

Owner of ikeysurviv.minehut.gg

 

⊱------------------------------⊰

[LEGEND] on Minehut

⊱------------------------------⊰

In-game name - ikeyIX

Discord name - ikeyIX#2007

Link to comment
Share on other sites

7 hours ago, Ikey said:

Ok so I've tried a bit of testing.

The problem is still here as it is still sending the "seconds" text string along with the number. Here is the code that I have at the minute which isn't working.

command /timer:
    trigger:
        set {timer.%player%} to true
        set {_start} to now
        while {timer.%player%} is true:
            set {timer.total.%player%} to difference between now and {_start}
            set {event.boatrace.lap} to 0
            send action bar "&bLap %{lap.%player%}%/3 &b%{timer.total.%player%}%" to player
            wait 1 second
command /timerstop:
    trigger:
        set {timer.%player%} to false
        set {total.%player%} to {timer.total.%player%}
        set {timer.total.%player%} to {total.%player%}
        replace all "seconds" with "" in {total.%player%}
        send "{@prefix} &b%{total.%player%}%"

Does it look like I have done anything wrong becau se this is the text feed that is coming back after I do /timerstop:
image.png.148093651d6318658ff7500259224c62.png

The skript has no errors so I'm lost on whats wrong.

Thanks.

ah i think i see it. The problem might be that its parsed as a timespan. Try parsing it as text, then replacing.

 

 

image.png.bc433d6489d70ad831075fe76809b993.png
 

Owner of Lifestealed, Labs, Encore, UNOfficially and Observed
 

OG [VIP] 12/26/20 - 10/27/2021
OG [PRO] 12/27/21 - 11/18/2022
OG [LEGEND] 11/18/2022 - 3/14/2023
[DEFAULT] 3/14/2023 - 5/8/2024

[MOD] 5/8/2024 - Present

 

Link to comment
Share on other sites

52 minutes ago, AgentGamerPro said:

ah i think i see it. The problem might be that its parsed as a timespan. Try parsing it as text, then replacing.

Ok will do

Owner of ikeysurviv.minehut.gg

 

⊱------------------------------⊰

[LEGEND] on Minehut

⊱------------------------------⊰

In-game name - ikeyIX

Discord name - ikeyIX#2007

Link to comment
Share on other sites

55 minutes ago, AgentGamerPro said:

ah i think i see it. The problem might be that its parsed as a timespan. Try parsing it as text, then replacing.

So this is what I've got back after trying.image.png.c9c96f4adcab0cc216748210f8592581.png

Here is the code:

command /timer:
    trigger:
        set {timer.%player%} to true
        set {_start} to now
        while {timer.%player%} is true:
            set {timer.total.%player%} to difference between now and {_start}
            set {event.boatrace.lap} to 0
            send action bar "&bLap %{lap.%player%}%/3 &b%{timer.total.%player%}%" to player
            wait 1 second
command /timerstop:
    trigger:
        set {timer.%player%} to false
        set {total.%player%} to {timer.total.%player%} parsed as text
        replace all "seconds" with "" in {total.%player%}
        set {total.%player%} to {total.%player%} parsed as number
        send "{@prefix} &b%{total.%player%}%"

 

Owner of ikeysurviv.minehut.gg

 

⊱------------------------------⊰

[LEGEND] on Minehut

⊱------------------------------⊰

In-game name - ikeyIX

Discord name - ikeyIX#2007

Link to comment
Share on other sites

2 minutes ago, Ikey said:

So this is what I've got back after trying.image.png.c9c96f4adcab0cc216748210f8592581.png

Here is the code:

command /timer:
    trigger:
        set {timer.%player%} to true
        set {_start} to now
        while {timer.%player%} is true:
            set {timer.total.%player%} to difference between now and {_start}
            set {event.boatrace.lap} to 0
            send action bar "&bLap %{lap.%player%}%/3 &b%{timer.total.%player%}%" to player
            wait 1 second
command /timerstop:
    trigger:
        set {timer.%player%} to false
        set {total.%player%} to {timer.total.%player%} parsed as text
        replace all "seconds" with "" in {total.%player%}
        set {total.%player%} to {total.%player%} parsed as number
        send "{@prefix} &b%{total.%player%}%"

 

ah okay so its already parsed as text then. im not sure what to do then.

 

 

image.png.bc433d6489d70ad831075fe76809b993.png
 

Owner of Lifestealed, Labs, Encore, UNOfficially and Observed
 

OG [VIP] 12/26/20 - 10/27/2021
OG [PRO] 12/27/21 - 11/18/2022
OG [LEGEND] 11/18/2022 - 3/14/2023
[DEFAULT] 3/14/2023 - 5/8/2024

[MOD] 5/8/2024 - Present

 

Link to comment
Share on other sites

1 hour ago, AgentGamerPro said:

ah okay so its already parsed as text then. im not sure what to do then.

ok thanks for trying to help me 🙂

Owner of ikeysurviv.minehut.gg

 

⊱------------------------------⊰

[LEGEND] on Minehut

⊱------------------------------⊰

In-game name - ikeyIX

Discord name - ikeyIX#2007

Link to comment
Share on other sites

Use an integer variable storing the number of tenths of seconds (or whatever your smallest division of time is) and increment that variable by 1 every tenth of a second (or whatever your smallest division of time is). Make sure to only increment while the race is going. 

Owner of oldgaffle.minehut.gg. (my paintball server)

Owner of karted.minehut.gg. (my mario kart server)

Advocate of individual freedom, especially freedom of speech.

Cooler than Stalemate128.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...