Solved Stopwatch help?

  • 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.
May 27, 2020
4
1
3
28
I'm trying to make a very simple stopwatch. Here's what I have so far:
Code:
on event 1:
   set {_start.%player%} to now

on event 2:
   set {_diff} to difference between now and {_start}
   message "%{_diff}% is the difference"

That's a small part of the much larger, messier code, but you get the idea.
Adding or removing the %player% after {_start} makes no difference.
When debug testing, both {_diff} and {_start} output to chat as <none> and I have no clue why.

Am I missing something? This is the code I found on a different forum post somewhere else, but it isn't working for me.

I'm using minehut's custom version of Skript, so I have no clue which version it is, sorry.
 
Last edited:
When using the underscores _ you're making the variable local. That means it can only be accessed in the event it was created in and will be deleted as soon as the event is done.
 
  • Like
Reactions: lonelypotato99
That worked, but I'm just realizing, does "now" only go down to minutes? How can I make a timer that can do 0.2 or 0.5 of a second then?

Edit: Solved, this is a much better way of achieving a stopwatch than whatever I was trying to do:

Code:
every 0.2 seconds:
   if {isRunning} is true:
      add 0.2 to {time}

on event 1:
   set {time} to 0
   set {isRunning} to true

on event 2:
   set {isRunning} to false
   message "Ran for %{time}% seconds!"
 
Last edited:
You could use timestamps to make it more efficient. (Also wouldn't execute something every 0.2 seconds, so less lag)

Code:
set {starttime} to unix timestamp of now

set {_time} to {starttime}-(unix timestamp of now)
 
Status
Not open for further replies.