I’ve been searching the forums about this problem of mine but I can’t find anything. My problem is how can I convert seconds into hours, then use it as a countdown timer. Just like in those games which uses energy refilling method.
So far this is what I have:
local function checkSlotTime() local curTime = os.time () print ("os time: " .. curTime) local slotLastUse = upSlotUsed -- this is the time when the user last used the slot machine. print ("slot last used: " .. slotLastUse) local timeSince = (curTime - slotLastUse) if timeSince \>= 21600 then -- 6 hours cooldown print ("slot is ready") else print ("slot is NOT ready") end end
what I want to achieve is convert the “slotLastUse” into hours if hours is not applicable, convert into minutes, if minutes is not applicable then, convert it into seconds. Then display how long the user will have to wait in order to used the slot machine.
I get the logic to it, but I can’t get it into codes, because time and dates freaks me out. I cannot fully understand it well.
If it doesn’t bug you, how can I print in terminal the returned value? when I do print (wrapped_time) it print the address of the function on the memory
it returns syntax error on the terminal, expeting “)”. if put the function on a variable which can solve the error, but still it doesn’t return anything on the terminal.
P.S.
Is there another method regarding my problem, which is convert seconds string into hh:mm:ss format? because I was expecting a short block of code. And I can’t find any references about converting a string of seconds to hh:mm:ss format
local function timeCount(numSec) local nSeconds = numSec if nSeconds == 0 then coolTime.text = "00:00:00"; else local nHours = string.format("%02.f", math.floor(nSeconds/3600)); local nMins = string.format("%02.f", math.floor(nSeconds/60 - (nHours\*60))); local nSecs = string.format("%02.f", math.floor(nSeconds - nHours\*3600 - nMins \*60)); coolTime.text = nHours..":"..nMins..":"..nSecs end end
If it doesn’t bug you, how can I print in terminal the returned value? when I do print (wrapped_time) it print the address of the function on the memory
it returns syntax error on the terminal, expeting “)”. if put the function on a variable which can solve the error, but still it doesn’t return anything on the terminal.
P.S.
Is there another method regarding my problem, which is convert seconds string into hh:mm:ss format? because I was expecting a short block of code. And I can’t find any references about converting a string of seconds to hh:mm:ss format