Game Development Community

weird %worldPosition value when passing to a class method

by David Reynolds · in iTorque 2D · 07/18/2009 (9:08 pm) · 2 replies

I have the following:
function sceneWindow2D::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
   echo(%worldPosition);
   $turret.fire(%worldPosition);
}

function turretClass::onLevelLoaded(%this, %scenegraph)
{
   $turret = %this;
}

function turretClass::fire(%worldPos)
{
   echo(%worldPos);
}

onMouseDown will echo out a value like: '-34.166668 -16.875000' while fire will echo out '1311'. Why is the value changing?

If I change the code to:

function sceneWindow2D::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
   echo(%worldPosition);
   fire(%worldPosition);
}

function fire(%worldPos)
{
   echo(%worldPos);
}

both values are correct. (both '-34.166668 -16.875000')

Why doesn't the first example work?

#1
07/18/2009 (9:14 pm)
Because fire needs to have %this as the first argument and %worldPos as the second argument. Your echoing %this in fire instead of the position.
#2
07/18/2009 (9:18 pm)
Thank you! I was stumped for over an hour.