Waiting or delaying an amount of time.
by Don Hogan · in Torque Game Builder · 12/05/2005 (10:30 am) · 5 replies
In the back of my mind I feel like I've seen this topic somewhere here before, but haven't been able to turn it up through searches. I'd given up for the time being, since it's not terribly pressing, then I saw this thread www.garagegames.com/mg/forums/result.thread.php?qt=35188 and it got me thinking about it again.
Rather than hijack that discussion, and since I'm wanting to do this in T2D, I wanted to post here.
Say for example I want to display mission instructions for 20 seconds at the beginning of the level, without anything starting or show a tutorial tip when a particular event happens.
I know I could use $timescale or the scenePause function to get the action stopped, but how do I specify the amount of time for them to last? I tried using a 'while' loop but that didn't seem to work, I looked in 3DGPAIO but didn't see any examples, searched TDN using wait, delay and pause.
Any thoughts on a good way to do this?
***********
As I was typing and thinking through everything I've tried so far, I had an idea. Would it make sense to use scenePause and call a GUI that's just a window on top of the sceneWindow? I think that's what I'll try next, but I'd like to hear what others think about doing this sort of thing.
Thanks,
- Don
Rather than hijack that discussion, and since I'm wanting to do this in T2D, I wanted to post here.
Say for example I want to display mission instructions for 20 seconds at the beginning of the level, without anything starting or show a tutorial tip when a particular event happens.
I know I could use $timescale or the scenePause function to get the action stopped, but how do I specify the amount of time for them to last? I tried using a 'while' loop but that didn't seem to work, I looked in 3DGPAIO but didn't see any examples, searched TDN using wait, delay and pause.
Any thoughts on a good way to do this?
***********
As I was typing and thinking through everything I've tried so far, I had an idea. Would it make sense to use scenePause and call a GUI that's just a window on top of the sceneWindow? I think that's what I'll try next, but I'd like to hear what others think about doing this sort of thing.
Thanks,
- Don
#2
Sort of like:
12/05/2005 (11:30 am)
Have you thought about using "schedule" for a specific function?Sort of like:
function PauseAndSplash ( %dlgToShow )
{
Canvas.pushDialog ( %dlgToShow );
setScenePause ( true );
schedule ( 20000, UnpauseAndContinue, %dlgToShow );
}
function UnpauseAndContinue ( %dlgToShow )
{
setScenePause ( false );
Canvas.popDialog ( %dlgToShow );
}
#3
Unfortuantely, i wouldn't have a clue as to how to go about getting the time. That would be nice, though, I can thikn of lots of other things to do with the actual time.
@Scott
I wish I could use SVN from work, so I could see how it was I tried using schedule. I'm pretty certain though that I was trying to cram it into one function. I'll give your solution a try tonight, I really like it. I can also see including 'tutorial complete' flags in the unpause function, and I'm sure that it could be used to track other variables of that type as well.
Thanks to you both,
Don
12/05/2005 (11:35 am)
@Jason Unfortuantely, i wouldn't have a clue as to how to go about getting the time. That would be nice, though, I can thikn of lots of other things to do with the actual time.
@Scott
I wish I could use SVN from work, so I could see how it was I tried using schedule. I'm pretty certain though that I was trying to cram it into one function. I'll give your solution a try tonight, I really like it. I can also see including 'tutorial complete' flags in the unpause function, and I'm sure that it could be used to track other variables of that type as well.
Thanks to you both,
Don
#4
Something like what Scott suggested would work, but you can't do anything while the splash screen is showing (like cross-fade it with the next one).
So instead you could create a timed object which gets timer updates from the time manager which you control. For instance, pause the time manager and all the sub-managers will pause. Or you can have submanagers pause themselves without affecting anything else (unlike $timescale). In my current game, popping up the menu during a level stops the updates to the level objects but nothing else. The game is broken into various "states" which receive time deltas and input events (dispatched by the top-level manager) which then control the objects each state manages.
Basically I've got a framework within a framework because I want to control input, animation, etc but Torque just doesn't make that easy. Sorry this is all probably really cryptic and vague, but eventually I might post some code to demonstrate things somewhat. It's not really that much code, and it's all 100% TorqueScript because that allows me to port from Mac to PC or back with no hassles at all.
Good luck with your explorations! :)
12/06/2005 (2:52 am)
I set up my own time manager which basically gets the current scenetime (%scenegraph.getSceneTime()) and then calculates a delta since last update and hands the delta to other managers. They all use this single delta and thus are in sync (or if delta becomes 0 they all pause). I used $timescale for pausing in my last game, but that freezes everything (ie, animations etc) so it's no good for that. Schedule is useful, but it ignores scenetime (uses simtime) and you have to keep track of each scheduled event if you need to possibly cancel it.Something like what Scott suggested would work, but you can't do anything while the splash screen is showing (like cross-fade it with the next one).
So instead you could create a timed object which gets timer updates from the time manager which you control. For instance, pause the time manager and all the sub-managers will pause. Or you can have submanagers pause themselves without affecting anything else (unlike $timescale). In my current game, popping up the menu during a level stops the updates to the level objects but nothing else. The game is broken into various "states" which receive time deltas and input events (dispatched by the top-level manager) which then control the objects each state manages.
Basically I've got a framework within a framework because I want to control input, animation, etc but Torque just doesn't make that easy. Sorry this is all probably really cryptic and vague, but eventually I might post some code to demonstrate things somewhat. It's not really that much code, and it's all 100% TorqueScript because that allows me to port from Mac to PC or back with no hassles at all.
Good luck with your explorations! :)
#5
Hmm - I understand the concept behind what you're doing, but that's a little beyond me at this point. Fundamentally, I didn't realize the engine was using 2 different clocks - i.e. Sim and Scene times. (There are some gaping holes in my understanding of the GG engines.)
Having fiddled some more, I now understand what you're referring to about $timescale affecting so much. I added $timescale = 0; to my scene pause function and I couldn't figure out why my editors weren't working anymore!
Without $timescale, I did notice what you're referring to about the issues with schedule. I walked away from the editor for a bit and when I came back a spawn enemy loop had been running so long that it crashed T2D when I toggled back over.
Lastly, and I'm embarassed to even admit this, it would seem that in my efforts to keep my scripting clean I erased the section where I was playing with figuring out a wait-type function.
Found it. I was wanting to put in a delay for the player getting control back when restarting after being killed. The goal was to not let the player move until the audio had finished playing. I'd forgotten about it since my enemies are still hardcoded to detect the player and my more pressing task is to get them to leave the player's start point so the player doesn't die immediately.
I still plan to try the GUI idea I had, that might in fact work out to be pretty snazzy even if I still have to sort out the in-game function a different way.
Thanks again,
Don
12/06/2005 (10:11 am)
@JasonM Hmm - I understand the concept behind what you're doing, but that's a little beyond me at this point. Fundamentally, I didn't realize the engine was using 2 different clocks - i.e. Sim and Scene times. (There are some gaping holes in my understanding of the GG engines.)
Having fiddled some more, I now understand what you're referring to about $timescale affecting so much. I added $timescale = 0; to my scene pause function and I couldn't figure out why my editors weren't working anymore!
Without $timescale, I did notice what you're referring to about the issues with schedule. I walked away from the editor for a bit and when I came back a spawn enemy loop had been running so long that it crashed T2D when I toggled back over.
Lastly, and I'm embarassed to even admit this, it would seem that in my efforts to keep my scripting clean I erased the section where I was playing with figuring out a wait-type function.
Found it. I was wanting to put in a delay for the player getting control back when restarting after being killed. The goal was to not let the player move until the audio had finished playing. I'd forgotten about it since my enemies are still hardcoded to detect the player and my more pressing task is to get them to leave the player's start point so the player doesn't die immediately.
I still plan to try the GUI idea I had, that might in fact work out to be pretty snazzy even if I still have to sort out the in-game function a different way.
Thanks again,
Don
Torque Owner Jason Swearingen
though i'm interested in hearing how scenePause works as per your question...