Game Development Community

Accessing non-global script variable from source

by Chris Jorgensen · in iTorque 2D · 01/16/2011 (5:13 am) · 3 replies

So here's what I'm trying to do. Let's say I make a sprite in script and give it the class "testClass". I'll name the sprite $testObject. So far so good. Now I make a custom property of it, say "$testObject.isCool = true;".

Now, how do I get at that "isCool" value in source? I can use Con::getVariable("$testObject"), for example, to get the object ID. But I can't do Con::getVariable("$testObject.isCool"). That doesn't work!

Obviously, I can point to sprites in source easily. And it's easy to manipulate its standard fields, like position, speed, etc... but I can't seem to figure out how to get at these "additional" fields that are declared / set in script.

Can anyone help?

#1
01/16/2011 (6:01 am)
You could, instead of using Global variables, use a ScriptObject instead and get their field values from source.

edit **** Oh.. wait I think I miss understood the question. You could just use
object->getDataField(fieldName, NULL);
#2
01/16/2011 (8:35 am)
WIthout actually testing, I think I can confirm this. I couldn't think of the exact function call, but I think Aun has it.
#3
01/16/2011 (6:09 pm)
I thought it looked right too. But it didn't work when I tried. I was able to put in a workaround though. :)