Incorrect Timer
by Ashley Sidebottom · in Torque 3D Professional · 08/03/2011 (10:36 am) · 8 replies
Hi. I have added a timer to my Game. I used to code;
I added this onto my PlayGUI.cs in the OnWake function
And at the end of the .cs i added a new Function
I also added on the HUD a Textlabel called
'lblTime'
However it doesnt show the time. Im probably doing this all wrong, But in theory it should keep adding one to the Timer Variable
I added this onto my PlayGUI.cs in the OnWake function
schedule(1000,0, updateDisplay);
And at the end of the .cs i added a new Function
function updateDisplay()
{
lblTime.setValue == %timer;
%timer++
schedule(1000,0, updateDisplay);
}I also added on the HUD a Textlabel called
'lblTime'
However it doesnt show the time. Im probably doing this all wrong, But in theory it should keep adding one to the Timer Variable
About the author
Student @ University of Huddersfield | Games Designer | sidearse@live.co.uk http://www.sid3bottom.co.uk http://www.bashgames.co.uk
#2
08/03/2011 (11:07 am)
Thanks :D yeah i solved it so i changed the thread to another question :) Cheers
#3
That compares the two values, it does not change the value. This is what you want:
08/03/2011 (12:31 pm)
@Ashley - Are you saying the value of lblTime is wrong? That is probably due to this:lblTime.setValue == %timer;
That compares the two values, it does not change the value. This is what you want:
lblTime.setValue = %timer;
#4
Thanks, i changed it to that however the time still displays 0 and Doesn't change :S. Even when i declare the %timer = 0 on the onWake function
08/03/2011 (1:23 pm)
The value doesn't show on the HUD.Thanks, i changed it to that however the time still displays 0 and Doesn't change :S. Even when i declare the %timer = 0 on the onWake function
#5
1. %timer is a local variable and will not have a value each time the function is called.
2. I think you need to use setText() to set the text of your label.
Maybe something like this if you don't want to use a global var:
Or you can use a global variable like this:
08/03/2011 (1:25 pm)
Two problems.1. %timer is a local variable and will not have a value each time the function is called.
2. I think you need to use setText() to set the text of your label.
Maybe something like this if you don't want to use a global var:
function updateDisplay()
{
lblTime.timerValue++; // increment the variable
lblTime.setText(lblTime.timerValue); // set the text of the GUI label
schedule(1000,0, updateDisplay);
}
lblTime.timerValue = 0; // adds a field to your label control and init before starting display
schedule(1000,0, updateDisplay); // start the display processOr you can use a global variable like this:
function updateDisplay()
{
$GameTimerValue++; // increment the global variable
lblTime.setText($GameTimerValue); // set the text of the GUI label
schedule(1000,0, updateDisplay);
}
$GameTimerValue = 0; // init global var before starting display
schedule(1000,0, updateDisplay); // start the display process
#6
08/03/2011 (1:38 pm)
Thanks :) got it to work Using your Global Variable method. As this is not set as $GameTimerValue, Would this be usuable in other scripts using that value? For example i can place in the gamecore when to end level, when the timer reaches a certain time? Cheers
#7
08/03/2011 (1:57 pm)
Using the global variable means it can be used anywhere in the game and you can init it wherever makes sense. Also not that the name is made up. Use whatever name is most fitting as long as it doesn't clash with something already in use.
#8
08/03/2011 (2:13 pm)
Thanks alot for your help :)
Torque 3D Owner Ray Batts
Sickhead Games
The script command should be something like Canvas.pushDialog(ChooseLevelDlg); Use that within GameCore::onDeath to launch it.