Game Development Community

onStart, onExit

by Toni Weidstätter · in Torque Game Builder · 05/03/2011 (10:03 am) · 4 replies

Hello!

function onExit() 
{
}
and
function onStart() 
{
}

why are these functions never called in my behavior? do i have to enable it?
(behavior is added to an image wih the TorqueGameBuilder - and onBehaviorAdd, onUpdate, onMouseDown are working fine...)

thx4help!

#1
05/03/2011 (12:42 pm)
Do you have any code in those functions? Also, they are stand alone functions and are not used by behaviors.
#2
05/04/2011 (1:31 am)
ok, is there any possibility to get some kind of "onExit" function in a behavior?

reason is that i collect (with onUpdate) all the x and y positions (during the game) an at the end i want to write them into a .txt file. (with onExit() or soemthing like that)

or shouldn't i do that in the behavior? should i put this code somewhere else?

i thought that i'll give that behavior to each object to collect the positions of each object during gameplay.

thx4help!
#3
05/05/2011 (7:50 pm)
Use the onBehaviorAdd, onBehaviorRemove, onLevelLoaded, and onLevelEnded. You can see which one is called when by using this sample:

if(!isObject(TestBehavior))
{
   %template = new BehaviorTemplate(TestBehavior);
   
   %template.friendlyName = "Test Behavior";
   %template.behaviorType = "Data Collection";
   %template.description = "Tests data collection or something.";
}

function TestBehavior::onBehaviorAdd(%this)
{
   %this.addMsg = "TestBehavior Added To Object";
   %this.removeMsg = "TestBehavior Removed From Object";   
   %this.sceneLoadMsg = "TestBehavior caught scene load";
   %this.sceneCloseMsg = "TestBehavior caught scene unload";
   
   echo("++++++++++++++++++++++++++++++++++++++");
   echo("+++ " @ %this.addMsg);
   echo("++++++++++++++++++++++++++++++++++++++");
}

function TestBehavior::onBehaviorRemove(%this)
{
   echo("++++++++++++++++++++++++++++++++++++++");
   echo("+++ " @ %this.removeMsg);
   echo("++++++++++++++++++++++++++++++++++++++");
}

function TestBehavior::onLevelLoaded(%this, %sceneGraph)
{
   echo("++++++++++++++++++++++++++++++++++++++");
   echo("+++ " @ %this.sceneLoadMsg);
   echo("++++++++++++++++++++++++++++++++++++++");
}

function TestBehavior::onLevelEnded(%this, %sceneGraph)
{
   echo("++++++++++++++++++++++++++++++++++++++");
   echo("+++ " @ %this.sceneCloseMsg);
   echo("++++++++++++++++++++++++++++++++++++++");
}

Alternatively, if it's an object that needs to be tracked throughout the game, I would recommend storing the data in global variables (preceded with $, rather than %) and simply outputting them to the file in the onExit code for the game.
#4
05/08/2011 (12:10 pm)
thank you very much!