1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Stopwatch help?

Discussion in 'Skript' started by lonelypotato99, May 28, 2020.

Thread Status:
Not open for further replies.
  1. lonelypotato99

    Joined:
    May 27, 2020
    Messages:
    4
    Likes Received:
    1
    I'm trying to make a very simple stopwatch. Here's what I have so far:
    Code (Text):
    1. on event 1:
    2.    set {_start.%player%} to now
    3.  
    4. on event 2:
    5.    set {_diff} to difference between now and {_start}
    6.    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.

     
    #1 lonelypotato99, May 28, 2020
    Last edited: May 28, 2020
  2. Best Answer:
    Post #3 by lonelypotato99, May 28, 2020
  3. WeeHee

    WeeHee Active Member

    Joined:
    Mar 4, 2017
    Messages:
    108
    Likes Received:
    21
    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 Like x 1
  4. lonelypotato99

    Joined:
    May 27, 2020
    Messages:
    4
    Likes Received:
    1
    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 (Text):
    1. every 0.2 seconds:
    2.    if {isRunning} is true:
    3.       add 0.2 to {time}
    4.  
    5. on event 1:
    6.    set {time} to 0
    7.    set {isRunning} to true
    8.  
    9. on event 2:
    10.    set {isRunning} to false
    11.    message "Ran for %{time}% seconds!"
     
    #3 lonelypotato99, May 28, 2020
    Last edited: May 28, 2020
  5. WeeHee

    WeeHee Active Member

    Joined:
    Mar 4, 2017
    Messages:
    108
    Likes Received:
    21
    You could use timestamps to make it more efficient. (Also wouldn't execute something every 0.2 seconds, so less lag)

    Code (Text):
    1. set {starttime} to unix timestamp of now
    2.  
    3. set {_time} to {starttime}-(unix timestamp of now)
     
Thread Status:
Not open for further replies.

Share This Page

Loading...