jkub Posted March 13, 2011 Share Posted March 13, 2011 Hy there. It has been quiet a long time since I have request help on this forum and to be honest I've need help quiet a bit of times with getting things moving to pair up with my intentions and my schedule. This "game clock" I am talking about is not like a clock that tells the actual time in your game/server, it is for a mini game that tells you how much time you have left before the game is over. This should be done in a MINUTES:SECONDS format. This all derives from using algorithms or mathmatical formulas on a total ammount of 300000 miliseconds. 300000 Miliseconds = 5 minutes. 300000 = 300 seconds. That part was easy^ and I even got the minute part of the clock to work correctly but I have tried and I have tried countless times to get the seconds part to work but have failed, it is very tricky and I've decided to stop wasting time and ask for help. I figured it would be nice to know how this clock is rendered, I used server side text displays because I feel it was necessary. Here is the current part of my script which handles the clock. clockTimeRaw = 300000 function updateRoundClock() --This function is triggered by a timer every 1 second. totalTime_Seconds = clockTimeRaw/1000 totalTime_Minutes = totalTime_Seconds/60 minutesLeft = string.sub ( totalTime_Minutes, 1, 1 ) secondsLeft = 60 - ( 300 - totalTime_Seconds ) if secondsLeft <= -1 then secondsLeft = 60 end if secondsLeft < 10 then textItemSetText ( roundClock_Time, minutesLeft..":0" ..secondsLeft ) else textItemSetText ( roundClock_Time, minutesLeft.. ":" ..secondsLeft ) end clockTimeRaw = clockTimeRaw - 1000 end I can get the TOTAL number of seconds left over in the clock but I want it to be between 0 and 60. Please help me. Link to comment
Castillo Posted March 13, 2011 Share Posted March 13, 2011 What i get is, that you want to get minutes, seconds of milliseconds, it's that right? if so, i'm using this code for that: function convertTime(milliseconds) local mins = math.floor ( ms/60000 ) local secs = math.floor( (ms/1000)%60 ) return mins, secs end Link to comment
madis Posted March 13, 2011 Share Posted March 13, 2011 It's better to print the time client side only, while keeping the actual ending on server side. If it will be a long time, there could be a time sync once in a while, though it's not problem for usual computers to have 1 second accurate counters for at least a day. Though client computer could have some malfunction, or something sucks the resources temporary. Link to comment
jkub Posted March 13, 2011 Author Share Posted March 13, 2011 Thanks snake That seemed to work wonderfully. I had to edit it a bit to get times less then 10 seconds with a 0 before the other number though. But here is the current code. This is called from a seperate function. updateClock = setTimer ( updateRoundClock, 1000, 0 ) totalTime = 300000 This is the function that is triggered every 1 second. function updateRoundClock ( ms ) local mins = math.floor ( totalTime/60000 ) local secs = math.floor( (totalTime/1000)%60 ) if secs >= 10 then textItemSetText ( roundClock_Time, tostring(mins).. ":" ..tostring(secs) ) elseif secs < 10 then textItemSetText ( roundClock_Time, tostring(mins).. ":0" ..tostring(secs) ) end totalTime = totalTime - 1000 end @madis: I'm using a server text display so I don't have to loop through all the clients and put a load on them. Link to comment
Castillo Posted March 13, 2011 Share Posted March 13, 2011 So, it's working like it should? Link to comment
madis Posted March 14, 2011 Share Posted March 14, 2011 @madis: I'm using a server text display so I don't have to loop through all the clients and put a load on them. Doesn't matter, the server still sents the time every second to everybody behind the scenes. But if you see no issues while testing, then let it be like that. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now