Can't access Dynamic Fields by use of getObject
by Marge Van Der Straaten · in Torque Game Builder · 01/29/2012 (7:18 am) · 3 replies
Hey,
I've encountered a little problem trying to access and manipulate dynamic fields of objects in a SimSet.
I've initialised the object and added it to the simset like so:
The problem is when trying to access the dynamic fields using the getObject():
And every single time, the console prints out "Can't access Warplane ID".
I've tried adding the fields in another way like so (just in case it got muddled up somehow):
But still, it returned "Can't access Warplane ID".
Can anyone please enlighten me what I did wrong?
Thanks in advance!
I've encountered a little problem trying to access and manipulate dynamic fields of objects in a SimSet.
I've initialised the object and added it to the simset like so:
%WarPlane = new t2dStaticSprite()
{
imageMap = "ImpImageMap";
class = "Imperial";
layer = 0;
size = "1.899 1.899";
Position = (-80)SPC(-30 + %i*5);
ID = "Board"; //set object's location ID if not on trackBoard.
cameFrom = "Board"; //set WarPlane's came from variable
};
warPlaneSet.add(%WarPlane); //add to the related SimSetThe problem is when trying to access the dynamic fields using the getObject():
if(warPlaneSet.getObject(%index).ID == null)
{
echo("Can't access Warplane ID");
}
else
{
echo("Warplane is on the" SPC warPlaneSet.getObject(%index).ID);
}And every single time, the console prints out "Can't access Warplane ID".
I've tried adding the fields in another way like so (just in case it got muddled up somehow):
%WarPlane = new t2dStaticSprite()
{
imageMap = "ImpImageMap";
class = "Imperial";
layer = 0;
size = "1.899 1.899";
Position = (-80)SPC(-30 + %i*5);
};
%Warplane.ID = "Board"; //set object's location ID if not on trackBoard.
%Warplane.cameFrom = "Board"; //set WarPlane's came from variable
warPlaneSet.add(%WarPlane); //add to the related SimSetBut still, it returned "Can't access Warplane ID".
Can anyone please enlighten me what I did wrong?
Thanks in advance!
#2
Additionally, when dealing with strings "null" is not recommended. You should check like this:
01/29/2012 (8:36 am)
What is the result when you echo this:echo(warPlaneSet.getObject(%index).ID);
Additionally, when dealing with strings "null" is not recommended. You should check like this:
if(warPlaneSet.getObject(%index.ID $= "")
#3
Thanks for pointing out my mistake in assuming "null" is a keyword!
I tinkered around with the isObject and it only works on full objects, not dynamic fields, so that's that.
@Michael_Perry:
The result is "Board", just as it was initialised beforehand.
I facepalmed at my incredible ability of making things out to be more complex than they should be.
The testing code that now works is below:
Thanks so much!
01/29/2012 (9:19 am)
@The_Guv:Thanks for pointing out my mistake in assuming "null" is a keyword!
I tinkered around with the isObject and it only works on full objects, not dynamic fields, so that's that.
@Michael_Perry:
The result is "Board", just as it was initialised beforehand.
I facepalmed at my incredible ability of making things out to be more complex than they should be.
The testing code that now works is below:
function warPlaneSet(%index)
{
if(!isObject(warPlaneSet.getObject(%index)))
{
echo("Can't access Warplane");
}
else
{
echo(warPlaneSet.getObject(%index).getPosition());
echo("Warplane is on the" SPC warPlaneSet.getObject(%index).ID);
}
}Thanks so much!
Torque 3D Owner The Guv
subunderground
TGB should complain a compile error. Try something like