OnWake and onSleep
by Emil Diego · in Torque Game Engine · 05/25/2005 (9:48 am) · 11 replies
I am starting out with the Torque Engine and I am working n modifying some of the example scripts. I have found 2 functions that I haven't been able to find out too much information about.
onWake and onSleep.
Are they automatically called when you push or pop a dialog?
Do you have to call them manually?
Thanx in advance for the assistance.
onWake and onSleep.
Are they automatically called when you push or pop a dialog?
Do you have to call them manually?
Thanx in advance for the assistance.
#2
05/25/2005 (9:52 am)
OnWake is when a GUI is opened, be it a dialog, a backdrop.. whatever. OnSleep is the opposite.
#3
So when I call
Canvas.pushDialog( frmOptions );
The engice automatically calls frmOptions.onWake().
and when I execute Canvas.popDialog( frmOptions );
The engine will automatically call frmOptions.onSleep().
??
05/25/2005 (9:56 am)
Stefan,So when I call
Canvas.pushDialog( frmOptions );
The engice automatically calls frmOptions.onWake().
and when I execute Canvas.popDialog( frmOptions );
The engine will automatically call frmOptions.onSleep().
??
#4
@Emil: That is what's supposed to happen.
05/25/2005 (10:39 am)
@Viktor: They do not pause the game.@Emil: That is what's supposed to happen.
#5
05/25/2005 (10:40 am)
Thanks for the info.
#6
For example
05/25/2005 (10:42 am)
Yes, OnWake and OnSleep are called automatically on any action that opens or closes a gui element.For example
function MyGUI::OnWake(){
TextBox.setText($MyVariable);
}
function MyGUI::OnSleep(){
$MyVariable = TextBox.getText();
}
#7
05/25/2005 (10:43 am)
That's a decent example, but isn't there a way to tie a gui control directly to a variable?
#8
05/25/2005 (10:55 am)
I was simply showing one way that OnWake and OnSleep are routinely used.
#9
Clear examples (such as the one you gave) are always good, but some kind of caveat when there is a Better Way to do what's in the example is always appreciated.
The generation of Fibbonaci numbers is often used as a way to teach recurssion. It makes for a crystal clear example, but it's seldom pointed out that there are much more efficient ways to generate them than the algorithm that is presented in such examples.
People who are just learning the ropes (such as myself) might get the wrong idea on how to do X when X is used as a Clear-but-suboptimal example.
I didn't indend to put you on the defensive or offend or anything of the sort. If I have, I'm sorry.
05/25/2005 (11:09 am)
Yes, I realize that. I just happen to Not Know (without some reference material to look at), and thought you might. I'm not sure that's the case, so I asked.Clear examples (such as the one you gave) are always good, but some kind of caveat when there is a Better Way to do what's in the example is always appreciated.
The generation of Fibbonaci numbers is often used as a way to teach recurssion. It makes for a crystal clear example, but it's seldom pointed out that there are much more efficient ways to generate them than the algorithm that is presented in such examples.
People who are just learning the ropes (such as myself) might get the wrong idea on how to do X when X is used as a Clear-but-suboptimal example.
I didn't indend to put you on the defensive or offend or anything of the sort. If I have, I'm sorry.
#10
05/25/2005 (11:35 am)
@Mark: I don't think you've offended anyone and you've brought up some very good points regarding the illustration of concepts with the Fibonacci reference. However, as you've pointed out, often times the "better" method is not illustrated. I myself am interested in the whole "tie a gui aspect to a variable" idea. I will post anything I find out.
#11
The "stock" way to tie a gui control to a specific variable is done via the GUI Editor. For any gui control where it is appropriate, you can expand the fields in the bottom right corner, and you'll scroll down to see a line that says "variable". Simply type in the (global) variable name that you want tied to the input from the text control.
You can also of course change the .gui file directly if you like, and change the appropriate GuiControl's field to the value you want, although this can be a lot harder than using the editor, especially with many nested gui controls.
05/25/2005 (4:13 pm)
Understood completely Mark, and you are correct, sometimes a quick example can cause people to think it's the only way of doing things--and please note, I am not dogging the example -at all-!The "stock" way to tie a gui control to a specific variable is done via the GUI Editor. For any gui control where it is appropriate, you can expand the fields in the bottom right corner, and you'll scroll down to see a line that says "variable". Simply type in the (global) variable name that you want tied to the input from the text control.
You can also of course change the .gui file directly if you like, and change the appropriate GuiControl's field to the value you want, although this can be a lot harder than using the editor, especially with many nested gui controls.
Torque Owner Viktor Kuropyatnik