Game Development Community

Have Behavior update a Datablock?

by Drethon · in Torque Game Builder · 05/01/2009 (6:23 am) · 5 replies

I'm trying to figure out how to have a behavior update a datablock so an onUpdate function for that datablock can act on the updates to the datablock. I want to do it this way so the datablock and its associated function can handle the standard actions for a class of objects but the behavior can still span multiple classes of objects.

I've tried looking though the documentation on this but either I'm looking in the wrong place or it doesn't properly describe how this type of interaction would work.

#1
05/01/2009 (8:42 am)
Try ssigning the datablock to the scene object (documented). Then in the behavior also attached to the object, call the datablock function:

datablock myPlayer(...)
{
     stuff = 3;
}

myPlayer::foo(...)
{
     echo(%this.stuff);
}

In the behavior
function behaviorName::onUpdate(%this)
{
    %this.owner.foo(...);
}

Give that a shot.
#2
05/01/2009 (7:07 pm)
Yeah I tried the following with the same object having config datablock of SpaceshipData and behavior of ShipMovementBehavior but I get an error "Unknown command updateMovement":

datablock t2dSceneObjectDatablock ( SpaceshipData )
{
...
}

...

function SpaceshipData::updateMovement ( %this )
{
...
}

...

function ShipMovementBehavior::turnRight(%this, %val)
{
   %this.owner.updateMovement(%this) ;
}
#3
05/02/2009 (4:27 pm)
Might this have something to do with it? What does it mean?

Namespace::unlinkClass - cannot unlink namespace parent linkage for PlayerShip for t2dTileLayer.
Error: cannot change namespace parent linkage of PlayerShip from t2dTileLayer to t2dStaticSprite.
#4
05/02/2009 (7:45 pm)
Do not put datablock t2dscenobjectdatablock. My code was just pseudo code.

Just use t2dSceneObjectDatablock.
#5
05/04/2009 (2:02 pm)
I found the namespaces tutorial and the examples got the concept through my head.

Any day you don't feel like an idiot is a day you aren't coding...