(TorqueScript) Set an object field virtually?
by Robert Lee · in Torque Game Engine · 01/20/2005 (1:16 pm) · 8 replies
Hi, I'm looking for a way to be able to achieve the following with torque script code:
%obj = GetObjectName();
%field = GetFieldName();
%obj.%field = GetValue(); // this causes an advanced script error
Any suggestions? I also tried shoving the command to be evaluated into a call() function but that doesn't work either.
%obj = GetObjectName();
%field = GetFieldName();
%obj.%field = GetValue(); // this causes an advanced script error
Any suggestions? I also tried shoving the command to be evaluated into a call() function but that doesn't work either.
#2
I'd like the "%data.someField" part of that code to be chosen virtually/dynamically.
For example:
In some cases 'data' will "point" to an Emitter, in another case, a Particle.
In some cases 'someField' will "point" to the ejectionPeriodMS field, in another case, ejectionOffset.
Put another way, I was hoping to write a function similar to...
An then I use it like so ...
I hope that makes more sense.
01/20/2005 (1:50 pm)
Quote:// gets some field value from that objects datablock
%someField = %data.someField;
I'd like the "%data.someField" part of that code to be chosen virtually/dynamically.
For example:
In some cases 'data' will "point" to an Emitter, in another case, a Particle.
In some cases 'someField' will "point" to the ejectionPeriodMS field, in another case, ejectionOffset.
Put another way, I was hoping to write a function similar to...
function SetFieldValue(%objName, %fieldName, %value)
{
%objName.%fieldName = %value;
}An then I use it like so ...
SetFieldValue("CrossbowBoltEmitter", "thetaMax", 10.0);I hope that makes more sense.
#3
Strangely enough, eval() is not listed in the script reference section of Ken Finney's book.
01/20/2005 (2:24 pm)
I just discovered the eval() function, and it allows me to do what I need. I still wonder if there's a better way to do this, but it's no biggie.Strangely enough, eval() is not listed in the script reference section of Ken Finney's book.
#4
("Obj" @ %var).field
And I think (tho am not 100% sure) that
("Obj" @ %var).(%anotherVar)
works. Naturally, if it doesn't you can fall back to eval very easily.
01/20/2005 (11:16 pm)
That's odd. Anyway, yes, eval works good. You can also do things like("Obj" @ %var).field
And I think (tho am not 100% sure) that
("Obj" @ %var).(%anotherVar)
works. Naturally, if it doesn't you can fall back to eval very easily.
#5
(%obj).(%field) = %val;
But it's nice to know I can at least do this ...
(%obj).fleldName
And eval handles the rest.
01/21/2005 (9:14 am)
Thanks. It doesn't look like this works ...(%obj).(%field) = %val;
But it's nice to know I can at least do this ...
(%obj).fleldName
And eval handles the rest.
#6
01/22/2005 (4:17 pm)
Thanks for checking what I said. :)
#8
(%obj).(%field) = %val;
But it's nice to know I can at least do this ...
(%obj).fleldName
And eval handles the rest.
01/24/2005 (8:26 am)
Thanks. It doesn't look like this works ...(%obj).(%field) = %val;
But it's nice to know I can at least do this ...
(%obj).fleldName
And eval handles the rest.
Torque 3D Owner Robert Blanchet Jr.