T3D 1.1 Final - getDynamicField() Returns Strange Extra Characters [NOT A BUG]
by Steve Acaster · in Torque 3D Professional · 11/02/2011 (3:58 pm) · 7 replies
T3d 1.1 Final
Windows7 32bit
target: script getDynamicField
Issue:
The function GetDynamicField(%index) returns the correct string but slap ^0 on the end of it ... so the dynamicField myPants is returned as myPants^0
... er ... is this expected function? And if so, how do I get rid of the last 2 characters to turn it into a useable string for TS?
Repeat:
Boot up t3d
Go into a level
Add a dynamic field to an object (remember object name or ID)
remember the index of your new field (probably 1 after locked which is 0)
Get the console down and enter
%objID.getDynamicField(%index);
And watch it return the dynamicField with these 2 extra charcaters
Suggest:
Fix it, or explain what possible use this is.
Note: this doesn't happen with the standard "getField" functions.
Okay not a bug - some sort of baffling divider between string and value
Windows7 32bit
target: script getDynamicField
Issue:
The function GetDynamicField(%index) returns the correct string but slap ^0 on the end of it ... so the dynamicField myPants is returned as myPants^0
... er ... is this expected function? And if so, how do I get rid of the last 2 characters to turn it into a useable string for TS?
Repeat:
Boot up t3d
Go into a level
Add a dynamic field to an object (remember object name or ID)
remember the index of your new field (probably 1 after locked which is 0)
Get the console down and enter
%objID.getDynamicField(%index);
And watch it return the dynamicField with these 2 extra charcaters
Suggest:
Fix it, or explain what possible use this is.
Note: this doesn't happen with the standard "getField" functions.
edit
1 second after pressing post ...Okay not a bug - some sort of baffling divider between string and value
About the author
One Bloke ... In His Bedroom ... Making Indie Games ...
#2
11/02/2011 (4:50 pm)
%obj.getDynamicField(%idx) returns tab-separated field-name and value:for(%i=0;%i<%obj.getDynamicFieldCount();%i++)
{
%field = %obj.getDynamicField(%i);
%fieldName = getField(%field, 0);
%fieldValue = getFields(%field, 1); // not using getField(%field,1) In case value is tab-separated too
echo("Field" SPC %fieldName SPC "have value: '" SPC %fieldValue);
}
#3
11/02/2011 (5:15 pm)
Thanks for that info, Fyodor. Result in 1 line of script now. :)
#4
I just spent a lot of time debugging my code to find out there is a stupid tab in the data with the actual value. It turns out it is hard coded this way. Strange...what is the reason for this?
Edit:
And in the 2 places this function is used it does not make use of the fact that it returns both values!:
So why does it return both?
07/29/2013 (1:27 am)
Why in the hell does GetDynamicField behave this way?I just spent a lot of time debugging my code to find out there is a stupid tab in the data with the actual value. It turns out it is hard coded this way. Strange...what is the reason for this?
Edit:
And in the 2 places this function is used it does not make use of the fact that it returns both values!:
// line 324 in guiEditorUndo.ed.cs %field = %object.getDynamicField(%i); %this.fieldNames[%object] = %this.fieldNames[%object] SPC %field; %this.fieldValues[%object, %field] = %object.getFieldValue(%field); // line 353 in guiEditorUndo.ed.cs %field = %object.getDynamicField(%i); %this.newFieldNames[%object] = %this.newFieldNames[%object] SPC %field; %this.newFieldValues[%object, %field] = %object.getFieldValue(%field);Notice the call to get the value again!
So why does it return both?
#5
EDIT: Actually never mind me. Just realised the function takes an index not a field name :P.
07/29/2013 (1:52 am)
Yeah, this seems a bit silly. On the plus side, I didn't know this was exposed to scripts! One step closer to making TS work like Javascript :P.EDIT: Actually never mind me. Just realised the function takes an index not a field name :P.
#6
Because GetDynamicField is suppose to be used exactly how Bank is using it in his for() loop example.
As for why the undo history code in the GUI Editor is making unnecessary calls, it seems more than likely whoever wrote that part of the code didn't know how to use the function call either.
07/29/2013 (5:15 am)
Demolishun:Quote:Why in the hell does GetDynamicField behave this way?
I just spent a lot of time debugging my code to find out there is a stupid tab in the data with the actual value. It turns out it is hard coded this way. Strange...what is the reason for this?
Because GetDynamicField is suppose to be used exactly how Bank is using it in his for() loop example.
Quote:So why does it return both?Call time efficiency and it is called GetDynamicField() after all and not GetDynamicFieldName() nor GetDynamicFieldValue(). It also helps to use the console to dump the help info on the object method to know what it does too.
As for why the undo history code in the GUI Editor is making unnecessary calls, it seems more than likely whoever wrote that part of the code didn't know how to use the function call either.
#7
The only two places it is used in the engine it is used incorrectly. On top of that it is inconsistent with the usage of SimObject.getField:
Where SimObject.getDyanmicField looks like this:
So according to the official docs they should be returning the same type of information. The only problem is they don't so they are inconsistent. There is enough confusion already about this function that the only place in the engine that it is actually used it is used incorrectly. So I still vote that this is stupid.
Edit:
07/29/2013 (11:55 am)
@Nathan,The only two places it is used in the engine it is used incorrectly. On top of that it is inconsistent with the usage of SimObject.getField:
string SimObject::getField ( int index ) Retrieve the value of a static field by index. Parameters: index The index of the static field. Returns: The value of the static field with the given index or "".SimObject.getField returns ONLY the name of the field.
Where SimObject.getDyanmicField looks like this:
string SimObject::getDynamicField ( int index ) Get a value of a dynamic field by index. Parameters: index The index of the dynamic field. Returns: The value of the dynamic field at the given index or "".
So according to the official docs they should be returning the same type of information. The only problem is they don't so they are inconsistent. There is enough confusion already about this function that the only place in the engine that it is actually used it is used incorrectly. So I still vote that this is stupid.
Edit:
==>4117.getField(); <input> (0): SimObject::getField - wrong number of arguments (got 2, expected min 3 and max 3). <input> (0): usage: Retrieve the value of a static field by index. @param index The index of the static field. @return The value of the static field with the given index or "". ==>4117.getDynamicField(); <input> (0): SimObject::getDynamicField - wrong number of arguments (got 2, expected min 3 and max 3). <input> (0): usage: Get a value of a dynamic field by index. @param index The index of the dynamic field. @return The value of the dynamic field at the given index or "".So the in game "help" shows that both commands should be returning a field value. For getField the value is the name of the field, and for getDynamicField it is the name of the field, at tab, and the field value. Confused yet?
Associate Steve Acaster
[YorkshireRifles.com]
Okay it only adds 2 extra lines of script, but feel free to use the full power of CAPSLOCK below if there's an easier way of doing this ...