Game Development Community

Object handle changes after being passed, dynamic fields are lost

by John Gregg McCarron · in Technical Issues · 03/15/2011 (1:37 pm) · 0 replies

Ok so I have an object with class "Enemy" in the editor with a dynamic field "health" set to be 100.

And I have a script "enemy.cs" that notes a collision with another object and calls the colliding object's sceneGraph's beginBattle function
with %srcObj as the argument--which is my "Enemy" instance with dynamic field "health":

function Enemy::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
echo(%srcObj);
echo(%srcObj.health);
%dstObj.sceneGraph.beginBattle(%srcObj);
}

Then inside of sceneGraph.cs I have this function:

function sceneGraph::beginBattle(%enemy)
{
$currentEnemy = %enemy;

echo(%enemy);
echo(%enemy.health);
echo($currentEnemy);
echo($currentEnemy.health);
}

Why does echo(%enemy) return a different object handle? And why does echo(%enemy.health) return an empty string--meaning
there is no dynamic field called "health".

Am I missing some principal behind dynamic fields here? I want fields that I can modify for each new enemy that I place in the editor, but use
the same object.

About the author

Recent Threads