Random Homebrew: Oblivion vista portal 1.0
windows Vista flash portal for 2.70+PSP'S.WIDE SELECTION of flash games and apps.
By Oliver C.f [...]
Friends: Coding 'n Cracking - Nymphaea - PS3 Forum - darkforestgroup - daxhordes.org - Tgames - coldbird - gopsp.it - pspstation.org - prometheus - hgoel.info - MakeSmartTV - ps vita

Lua timer problem

Forum rules
Any post not directly related to programming will be moderated.
Do not request people to code something for you.
Avoid posting messages that do not bring anything to the conversation. We want the threads in this subforum to stay focused.

Lua timer problem

Postby cmbeke » Fri Sep 16, 2011 2:05 am

i have a timer code that will take a time and return it as minutes and seconds:
Code: Select all
function truncate()
   local timer = math.floor(time:time()/1000)
   local minutes = math.floor(timer/60)
   local seconds = timer-(minutes*60)
   if minutes < 10 then
      minutes  = "0"..minutes
   end
   if seconds < 10 then
      seconds = "0"..seconds
   end
   return minutes..":"..seconds
end

but it always goes like this:
00:00
00:01
...
00:59
00:60
01:01

is there any way to make it not show 00:60 and show 01:00? i'm pretty sure there should be an easy way but my brain isn't really working at the moment :oops:
You probably didn't know that you don't know that you don't know what you don't know.
I know I'm crazy, the real question is are you?
Life is nothing but discrimination, likes, dislikes, any choice made ... all a product of discrimination.
User avatar
cmbeke
 
Posts: 49
Joined: Tue Apr 12, 2011 9:51 pm

Re: Lua timer problem

Postby snailface » Fri Sep 16, 2011 2:32 am

Use the modulus operator (%). It returns the remainder of whatever it what divides by. It always works for me in my c and lua programs.

ex.
seconds = counter % 60
print (seconds) --or whatever print is in lua, I'm forgetful :p

--displays 0-59 seconds in a looping fashion
Image
snailface
 
Posts: 100
Joined: Tue May 24, 2011 8:02 pm

Re: Lua timer problem

Postby m0skit0 » Fri Sep 16, 2011 10:01 am

LUA coderz... :roll:
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4787
Joined: Mon Sep 27, 2010 6:01 pm

Re: Lua timer problem

Postby cmbeke » Fri Sep 16, 2011 5:31 pm

@m0skit0 and proud of it 8-)
modulus didn't work either (my math was fine ... i re-rechecked it) so i'm guessing that its a problem with interpreter, but i got it to work in the end with a couple more lines.
You probably didn't know that you don't know that you don't know what you don't know.
I know I'm crazy, the real question is are you?
Life is nothing but discrimination, likes, dislikes, any choice made ... all a product of discrimination.
User avatar
cmbeke
 
Posts: 49
Joined: Tue Apr 12, 2011 9:51 pm

Re: Lua timer problem

Postby m0skit0 » Fri Sep 16, 2011 8:11 pm

:D ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"
User avatar
m0skit0
Guru
 
Posts: 4787
Joined: Mon Sep 27, 2010 6:01 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest