Game Development Community

Behavior troubles - values not set - owner lost

by Andy Hawkins · in iTorque 2D · 07/20/2012 (11:11 pm) · 1 replies

I'm doing a simple little game to mess around with physics and pipeline to get it from PC to iPhone.

I started with a ball and some paddles and made the ball bounce around and the paddles bounce the ball too.

Then I added a space invader to have something to hit with the ball for points and added these two behaviors.

1. in the first code - MoveOnScreenRandom::onUpdate - it can't find the owner.
"scripts/behaviors/moveOnScreenRandom.cs (36): Unable to find object: '' attempting to call function 'setLinearVelocityX'";

2. in the second piece of code - the level - I have set the verticalSpeed and horizontalSpeed to something other than the defaults and they are not being recorder in the level file...

Do I have to do something special for behaviors in iTorque2D?
//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
// 
// behaviour written by Andy Hawkins 2011
//-----------------------------------------------------------------------------

if (!isObject(MoveOnScreenRandom))
{
   %template = new BehaviorTemplate(MoveOnScreenRandom);
   
   %template.friendlyName = "Move On Screen Random";
   %template.behaviorType = "Movement";
   %template.description  = "Makes object move around screen starting with a random direction based on the max number you typed in.";
   
   %template.addBehaviorField(verticalSpeed, "Vertical speed", float, 5);
   %template.addBehaviorField(horizontalSpeed, "Horizontal speed", float, 5);
}

function MoveOnScreenRandom::onLevelLoaded(%this)
{
   %this.verticalSpeed = getRandom(-%this.verticalSpeed,%this.verticalSpeed);
   %this.horizontalSpeed = getRandom(-%this.horizontalSpeed,%this.horizontalSpeed);
   %this.owner.enableUpdateCallback();
}


function MoveOnScreenRandom::onBehaviorRemove(%this)
{
   %this.owner.disableUpdateCallback();
}


function MoveOnScreenRandom::onUpdate(%this)
{
   %this.owner.setLinearVelocityX(%this.horizontalSpeed); // ERROR!!!! Can't find owner
   %this.owner.setLinearVelocityY(%this.verticalSpeed);
}

function MoveOnScreenRandom::setVerticalSpeed(%this, %val)
{
   %this.verticalSpeed = %val;
   %this.verticalSpeed = getRandom(-%this.verticalSpeed,%this.verticalSpeed);

}

function MoveOnScreenRandom::setHorizontalSpeed(%this, %val)
{
   %this.horizontalSpeed = %val;
   %this.horizontalSpeed = getRandom(-%this.horizontalSpeed,%this.horizontalSpeed);
}

new t2dAnimatedSprite() {
         animationName = "Invader1Animation";
         canSaveDynamicFields = "1";
         PlatformTarget = "UNIVERSAL";
         Position = "-46.891 -28.109";
         size = "23.782 23.782";
         WorldLimitMode = "NULL";
         WorldLimitMin = "-240.000 -125.000";
         WorldLimitMax = "240.000 161.959";
         WorldLimitCallback = "1";
         CollisionMaxIterations = "3";
         AlphaTestValue = "-1";
            mountID = "9";
         _behavior0 = "WorldLimitWrapBehavior ";  // ERROR SHOULD BE VALUES HERE
         _behavior1 = "MoveOnScreenRandom";
      };

#1
07/21/2012 (4:04 am)
Ahh... couple of things.

1. Torsion bites... meaning it doesn't work with iTorque2D. I can't get values out of it when I debug... anyone know what this is about?

2. If I don't tick Use Physics then it won't respond to setLinearVelocity call in script.

So anyone know what's up with Torsion and iTorque2D? It's not showing values when I wave the mouse over it, but it will echo the right values.