Why wont this work?
by rennie moffat · in Torque Game Builder · 02/08/2010 (2:06 pm) · 7 replies
This behavior needs to set the position of starsStar2 if starsStar1 is not in that position. I am not sure why this will not work, can some one please point out the error of my ways?
if(!isObject(starRejenerator))
{
%template = new BehaviorTemplate(starRejenerator);
%template.friendlyName = "star rejenerator";
%template.description = "adds new star to scene when one is dropped";
%template.behaviorType = "AI";
%template.addBehaviorField(starsStar1, "object behavior must clone", object, "", t2dSceneObject);
%template.addBehaviorField(starsStar2, "object behavior must clone", object, "", t2dSceneObject);
%template.addBehaviorField(starsStarLoaderPosX, "", float, 15);
%template.addBehaviorField(starsStarLoaderPosY, "", float, 15);
}
function starRejenerator::onBehaviorAdd(%this)
{
%this.owner.enableUpdateCallback();
}
function starRejenerator::onUpdate(%this)
{
%this.updateLoader();
}
function starRejenerator::updateLoader(%this)
{
%starsStar1Pos = starsStar1.getPosition();
%starsStar2Pos = starsStar2.getPosition();
if(%starsStar1Pos != %this.owner.getPosition())
{
starsStar2.setPosition(%this.starsStarLoaderPosX, %this.starsStarLoaderPosY);
}
}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.
#2
Patrick Roller Jesus just said the same thing.
Why does a vector compare work better?
02/08/2010 (7:23 pm)
Thanks William, Patrick Roller Jesus just said the same thing.
Why does a vector compare work better?
#3
You'll see it returns "1" (which means true). The reasons are beyond a quick reponse, but that is why you MUST use t2dVectorCompare. "==" is really just for single numbers, not vectors or strings.
02/08/2010 (8:04 pm)
Try this in the console:echo( "1 2" == "1 3" );
You'll see it returns "1" (which means true). The reasons are beyond a quick reponse, but that is why you MUST use t2dVectorCompare. "==" is really just for single numbers, not vectors or strings.
#4
I was wondering today actually, can I make a vector part of a behavior field?
If so how would I declare it? is it a float?
02/08/2010 (9:12 pm)
great thank you William.I was wondering today actually, can I make a vector part of a behavior field?
If so how would I declare it? is it a float?
#5
02/08/2010 (10:28 pm)
Personally, I'm lazy and will use "string" as the type for most of my behavior fields. But it looks like there is a "Point2F" field, according to www.torquepowered.com/community/forums/viewthread/68163/.
#6
so in theory i just pop in Point2F and all should go.
nice.
thanks man.
02/08/2010 (10:58 pm)
hmm, so in theory i just pop in Point2F and all should go.
nice.
thanks man.
#7
but it does not work and I am unsure why.
02/09/2010 (11:12 am)
I have used this, if(!isObject(starRejenerator))
{
%template = new BehaviorTemplate(starRejenerator);
%template.friendlyName = "star rejenerator";
%template.description = "adds new star to scene when one is dropped";
%template.behaviorType = "AI";
%template.addBehaviorField(starsStar1, "object behavior must clone", object, "", t2dSceneObject);
%template.addBehaviorField(starsStar2, "object behavior must clone", object, "", t2dSceneObject);
%template.addBehaviorField(loadPoint, "", Point2F, "15 15");
}
function starRejenerator::onBehaviorAdd(%this)
{
%this.owner.enableUpdateCallback();
}
function starRejenerator::onUpdate(%this)
{
if(!t2dVectorCompare(starsStar1.getPosition(), %this.loadPoint))
{
starsStar2.setPosition(%this.loadPoint);
}
if(!t2dVectorCompare(starsStar2.getPosition(), %this.loadPoint))
{
starsStar1.setPosition(%this.loadPoint);
}
}but it does not work and I am unsure why.
Associate William Lee Sims
Machine Code Games