|
| 06 Apr 2015 07:42 PM |
Hi, I'm making a round timer for my game. I'm unsure of the best method for keeping track of time. Currently, I'm just using a while loop and changing the value of the condition after a wait(1). What do you recommend?
This won't make much sense outside of context, but I'll just paste the whole section of my script so I don't miss anything:
while true do w = 120 while w >= 0 do wait(1) local sec = tostring(w - math.floor(w/60)*60) -- no modulo in Lua if (w - math.floor(w/60)*60 < 10) or (w - math.floor(w/60)*60 == 0) then updateGui("Time: " .. tostring(math.floor(w/60)) .. ":0" .. sec) else updateGui("Time: " .. tostring(math.floor(w/60)) .. ":" .. sec) end w = w - 1 -- w += -1 causes an error? end updateGui("The round is over!") wait(5) colorPart(workspace) end
There are some repetitive parts, and I'm not sure why the condition in my "if" statement doesn't work when w == 0 (which is why I added the "or" condition).
Is there a better method than using wait(1)? How would you count 1 second? Will my method cause any issues? Thanks. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2015 07:52 PM |
"No modulo in Lua"
A % B How much more obvious can it get? % is the standard modulo operator. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2015 07:54 PM |
| Oh, if it exists, it's exclusive to ROBLOX. Native Lua does not have a modulo operator. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2015 07:55 PM |
| Native Lua 5.1 has a modulo operator. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2015 08:02 PM |
Okay, it appears I'm mistaken. Thanks. I know my method isn't ideal, but I like it. I know right where to put the math.floor() to have exact seconds. :) |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2015 08:03 PM |
I just finished off a timer for my game that counts to 300 and resets to mark the spawn waves of bad guys
while true do for counter = 0, 300 do wait(1) script.Parent.Text = "The Snappers will arrive in: ".. counter end end
SATURDAYS NIGHTS ALL RIGHT FOR FIGHTING |
|
|
| Report Abuse |
|
|
vat21s
|
  |
| Joined: 07 Jun 2010 |
| Total Posts: 2508 |
|
|
| 06 Apr 2015 08:33 PM |
| Use tick() and then when the ∆tick() is >= to 30000 milliseconds end your round. This way you don't have to keep a timer loop running somewhere. |
|
|
| Report Abuse |
|
|