generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Best method of timekeeping?

Previous Thread :: Next Thread 
logarhythm is not online. logarhythm
Joined: 23 Dec 2008
Total Posts: 10267
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
logarhythm is not online. logarhythm
Joined: 23 Dec 2008
Total Posts: 10267
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
06 Apr 2015 07:55 PM
Native Lua 5.1 has a modulo operator.
Report Abuse
logarhythm is not online. logarhythm
Joined: 23 Dec 2008
Total Posts: 10267
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
IntraCloud is not online. IntraCloud
Joined: 13 Mar 2008
Total Posts: 3124
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image