Minute clock text?
by Isaac Barbosa · in Torque Game Builder · 01/27/2007 (9:53 am) · 11 replies
%timeSurvived = $GAME_LEVEL::playedTime + %this.getSceneTime(); %timeSurvived = mFloor ( %timeSurvived + 0.5); PlayedTime.text = "Time:" SPC %timeSurvived;
I have this code to count the time a player survive a level. Everything it's fine, except that after second 60 a get second 61 and so on... is there a way to see my game a normal minutes? I mean 0:01 -- 1:01 and so on?
Thanks for the help!
#2
01/27/2007 (5:18 pm)
Hi, I'm not sure if this will help, but I had a question about making a timer also, here's the thread: www.garagegames.com/mg/forums/result.thread.php?qt=56547
#3
Now my problem is that I cannot reset the seconds to zero once a minute is completed... and get:
1:61, 1:62, 1:63 and so on...
this code is in my onUpdateScene function... it has to do with this?
Thanks
01/28/2007 (9:24 am)
Thanks Matthew, that code is very useful to split the time into seconds and minutes...%timeSurvived = $GAME_LEVEL::playedTime + %this.getSceneTime() * 1000; //convert into senconds %secondsSurvived = mFloor ( %timeSurvived / 1000); // extract the number of minutes if (%secondsSurvived > 59) %minutesSurvided = mFloor(%secondsSurvived / 60); // get remainder of seconds %secondsSurvived = %secondsSurvived - (%minutesSurvived * 60); if (%secondsSurvived > 59) %timeSurvived = 0 @ %secondsSurvived; //display time GamePlayedTime.text = "Time:" SPC (%minutesSurvided @ ":" @ %secondsSurvived);
Now my problem is that I cannot reset the seconds to zero once a minute is completed... and get:
1:61, 1:62, 1:63 and so on...
this code is in my onUpdateScene function... it has to do with this?
Thanks
#4
01/28/2007 (3:55 pm)
if (%secondsSurvived > 59) %timeSurvived = 0 @ %secondsSurvived;There's you're problem. You should be resetting $GAME_LEVEL::playedTime to 0
#5
%temp = mFloor(%this.getSceneTime());
%sec = %temp % 60;
%temp -= %sec;
%temp /= 60;
%min = %temp % 60;
%temp -= %min;
%temp /= 60;
%hour = %temp % 24;
%temp -= %hour;
%temp /= 24;
%day = %temp;
echo(%day @ "d " @ %hour @ "h " @ %min @ "m " @ %sec @ "s");
01/29/2007 (8:52 am)
Here's how I would have written it. It gives you hours and days also. If you don't need them just ignore those variables.%temp = mFloor(%this.getSceneTime());
%sec = %temp % 60;
%temp -= %sec;
%temp /= 60;
%min = %temp % 60;
%temp -= %min;
%temp /= 60;
%hour = %temp % 24;
%temp -= %hour;
%temp /= 24;
%day = %temp;
echo(%day @ "d " @ %hour @ "h " @ %min @ "m " @ %sec @ "s");
#6
01/29/2007 (8:54 am)
Thanks Drew... I miss that! now is working :)
#7
01/29/2007 (8:56 am)
Thanks Nicolas, actually I will not use getSceneTime since I need start counting after pressing a button. But that code seems pretty neat for late use :).
#8
Now this works pretty well. This is for a survived time counter for my game :)
Thanks community!
01/29/2007 (9:04 am)
function gameLevel::updateGameTimer(%this)
{
$elapsedGameTime++;
%gameTimePlayed = $elapsedGameTime;
// convert into seconds
%secondsSurvived = %gameTimePlayed;
//add zero to left if seconds are less than 10
if (%secondsSurvived < 10)
%secondsSurvived = "0" @ %secondsSurvived;
// extract the number of minutes
if (%secondsSurvived > 59)
{
$elapsedGameTime = 0;
%secondsSurvived = "00";
$minutesSurvived++;
}
MolePlayedTime.text = "Time:" SPC ($minutesSurvived @ ":" @ %secondsSurvived);
}Now this works pretty well. This is for a survived time counter for my game :)
Thanks community!
#9
Ok, this code is working pretty nice in a countdown clock. The only problem is that is not showing 4:09 (as example) instead of 4:9 ....
What can I do in this specific case (I have struggled my brain unsuccessfully) to show that zero when seconds are less than 10?
Thanks!
07/12/2007 (5:24 pm)
if($QuitarTiempo $= true)
{
%this.setScenePause(false);
%timeLeft = $BOARD_LEVEL::timePerGame - %this.getSceneTime();
// Round it to full seconds
%timeLeft = mFloor(%timeLeft + 0.5);
// Time-check
%sec = %timeLeft % 60;
%timeLeft -= %sec;
%timeLeft /= 60;
%min = %timeLeft % 60;
if( %timeLeft < 0 )
{
%this.setScenePause(true);
exec("./gameOver.cs");
}
// Update the GuiTextCtrl
LevelTimer.text = "Tiempo:" SPC %min @ ":" @ %sec;
}Ok, this code is working pretty nice in a countdown clock. The only problem is that is not showing 4:09 (as example) instead of 4:9 ....
What can I do in this specific case (I have struggled my brain unsuccessfully) to show that zero when seconds are less than 10?
Thanks!
#10
07/12/2007 (5:40 pm)
Isaac, if you want to turn those variables into properly formatted string you could do something like this:if (%sec >= 10)
{
%strSec = %sec;
}
else
{
%strSec = "0" @ %sec;
}
#11
07/13/2007 (8:12 am)
Thanks Nicholas!4
Torque Owner Ben R Vesco