Game Development Community

passing a %var to another behavior

by rennie moffat · in iTorque 2D · 09/22/2011 (8:57 am) · 3 replies

Hi there, I know I can getBehavior() to collect info from another behavior, but can I "setBehavior"? Meaning, if %var = true; send that non global to another behavior.




edit,
sorry I am thinking this out loud, but I suppose getBehavior would work, I just need to bump up the var in the behavior I wanted to send info to.....


so, if x dies (noted in its behvaior), it getBehavior of sceneManager and its var %this.numberOfDead and changes it to %this.numberOfDead + 1;


I think that will get it. Please jump in if need be.

Cheers.

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
09/22/2011 (9:45 am)
On second thought, get behavior, will not trigger any function in another behavior per say, only get information. So, I could just run a schedule to constantly check, but is there a way for one behavior function to trigger another function in a separate behavior, with out using update schedules?



#2
09/23/2011 (4:29 pm)
It should be possible to do something like

%behavior = %someObject.getBehavior("SomeBehavior");

%behavior.someFunction(%var);
#3
09/24/2011 (5:46 pm)
Thanks Ben,
I am having trouble defining what %someObject is. Let me explain.

I have used %dstObject with sucess, a collision happens, I pass %dstObject into the argument of the function and use it, to getBehavior.. of which it (%dstObject) is the owner. No problem, works.

function onCollison(%srcObject, %dstObject)
{
if(%dstObject.class $= "manClass")
%srcObject.doThatThang(%dstObject);
}

function doThatThang(%this, %dstObject)
{
%ohYeah = %dstObject.getBehavior("%dstObjectsBehavior");
}

got info, no problem.



What I am having trouble with is, I have a behavior with a child, childX. On an update running in the parent, I want to check the status of a var in the child. So, I have been using this...
function update(%this)
{
%behavior = %this.childX.getBehavior("childXBehavior");
///%this.childX is a behaviorField of the owner parent
echo("the var I want bool " @ %this.var);
}

The return for %this.var, should be true, or false, however, I get no return. Can you see what I am doing wrong?

Thanks.





EDIT:
Thanks, just figured it out. %behavior = %this.getBehavior();
it was %behavior that I was not using. Thanks.