Stalling a script?
by Chris "DiGi" Timberlake · in Torque Game Engine · 08/10/2005 (1:04 pm) · 6 replies
Is it possible to stall a script, like with HL you can do (wait;)? I want to wait a few seconds before doing the 2nd stage of something in an if statement.
About the author
#2
08/10/2005 (10:04 pm)
I'm talking about mid statement, in an if statement.
#3
Your fuction split up how I was suggesting:
Or you can use threads.. see class Thread in platformThread.h
08/11/2005 (10:48 am)
I know what you meant.. Here's what I meant...function YourFunctionNow()
{
%pause = DoSomething();
if ( %pause == true )
{
// I want to wait here for a time
%waitTime = 1000.0f;
Wait( %waitTime); // ficticous function
// do more stuff
// ...
}
DoSomethingElse();
}Your fuction split up how I was suggesting:
function YourFunctionNow()
{
%pause = DoSomething();
if ( %pause == true )
{
%waitTime = 1000.0f; // milliseconds
schedule( %waitTime, 0, "DoMoreStuff");
}
}
function DoMoreStuff()
{
// do more stuff
// ...
DoSomethingElse();
}Or you can use threads.. see class Thread in platformThread.h
#4
08/11/2005 (10:54 am)
The only way I can think of is to either use schedules or write your own C++ script function which will let you do this.
#5
For example (modified from a NWN example, but simplified a little)
It's actually very easy to do... except without modifying or creating your own scripting engine, you'd have to do conditionals like this:
But... I'd wager that you're not really looking for something like that.
Edit: Oh, and variables would be different too. It sounds like a fun task, but I really think it requires a new scripting language that coexists with the current one, and that's the language you'd expose to your end-user base that's interested in creating RPG style modules.
08/11/2005 (11:42 am)
Another way to do it, depending on what you're doing, is to use something like the AI manager where you're basically interpreting a script within a script. It's like giving your objects a list of things to do. More of an event driven approach, rather than the procedural approach of Torque Script.For example (modified from a NWN example, but simplified a little)
function NPC::onStartScene()
{
while(IsSceneActive())
{
oPatron = GetNearestCreature();
if(!oPatron.isObject())
return;
ActionMoveToObject(oPatron);
ActionSpeakString("What's your poison?");
ActionWait(2.0);
if (!DrinkOrder())
{
ActionSpeak("Suit yourself.");
ActionWait(1.0);
continue;
}
MoveToBar();
ActionWait(2.0);
ActionMoveToObject(oPatron);
ActionSpeakString("That'll be 2 copper, please.");
oPatron.schedule(oPatron, ActionGiveAnimation);
}
}It's actually very easy to do... except without modifying or creating your own scripting engine, you'd have to do conditionals like this:
BeginConditionalLoop();
IsSceneActive();
BeginLoop();
BeginConditional();
DrinkOrder();
IfTrue();
// Don't really do anything
IfFalse();
ActionSpeak("Suit yourself.");
ActionWait(1.0);
ContinueLoop();
EndConditional();
EndLoop();But... I'd wager that you're not really looking for something like that.
Edit: Oh, and variables would be different too. It sounds like a fun task, but I really think it requires a new scripting language that coexists with the current one, and that's the language you'd expose to your end-user base that's interested in creating RPG style modules.
#6
08/11/2005 (12:15 pm)
Thanks guys! I think this should work!
Torque Owner Kirk Haynes
Here's an example from starter.racing's game.cs script file that uses schedule() to count down from 3, 2, 1, then start the race:
function countThree() { // Tell the client to count. for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) { %cl = ClientGroup.getObject( %clientIndex ); commandToClient(%cl, 'SetCounter', 3); } schedule(1000, 0, "countTwo"); } function countTwo() { // Tell the client to count. for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) { %cl = ClientGroup.getObject( %clientIndex ); commandToClient(%cl, 'SetCounter', 2); } schedule(1000, 0, "countOne"); } function countOne() { // Tell the client to count. for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) { %cl = ClientGroup.getObject( %clientIndex ); commandToClient(%cl, 'SetCounter', 1); } schedule(1000, 0, "startRace"); } function startRace() { // Inform the client we're starting up for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) { %cl = ClientGroup.getObject( %clientIndex ); commandToClient(%cl, 'GameStart'); // Other client specific setup.. %cl.lap = 0; %cl.nextCheck = 1; %cl.setControlObject(%cl.car); %cl.camera.setFlyMode(); } // Start the game timer // if ($Game::Duration) // $Game::Schedule = schedule($Game::Duration * 1000, 0, "onGameDurationEnd" ); $Game::Running = true; $Game::Running = true; }