T3D 1.1 Beta 3 - Order of evaluating variables in script - NOT A BUG
by Nathan Bowhay - ESAL · in Torque 3D Professional · 10/25/2010 (7:55 pm) · 10 replies
Build: 1.1 Beta 3
Platform: Windows Vista
Target: Torque Script evaluation
Issues: When you use assignment and the not operator on a variable. So if I have:
Steps to Repeat:
1. Launch the game
2. Hit F11 and create a Tree or something and give it a name or remember it's id (or give an existing object a name or remember it's id)
3. Hit F11 again to go out of the object editor
4. Hit F10 and Create a window and call it "MyWindow"
5. Add a dynamic field to it called "curObj" and set it equal to the name or id of the object you just created
6. Hit F10 again to go out of the gui editor
7. Hit Tilda to open the console
8. Type
This has probably been an issue for a while and isn't a big deal cause there are ways around it, but just thought I would point it out. Also I am sure there are other more complex or similar cases that reproduce the same behavior.
NOTE: PLEASE READ THE COMMENTS FOR THE ACTUAL BUG AND SOLUTION.
Platform: Windows Vista
Target: Torque Script evaluation
Issues: When you use assignment and the not operator on a variable. So if I have:
MyWindow.curObj = new SceneObject(){...};Then try and use the not operator on a dynamic field of that it doesn't behave as expected. Here is an example:MyWindow.curObj.isRenderEnabled = !(MyWindow.curObj.isRenderEnabled);This does not work either:
%val = MyWindow.curObj.isRenderEnabled ; MyWindow.curObj.isRenderEnabled = !%val;
Steps to Repeat:
1. Launch the game
2. Hit F11 and create a Tree or something and give it a name or remember it's id (or give an existing object a name or remember it's id)
3. Hit F11 again to go out of the object editor
4. Hit F10 and Create a window and call it "MyWindow"
5. Add a dynamic field to it called "curObj" and set it equal to the name or id of the object you just created
6. Hit F10 again to go out of the gui editor
7. Hit Tilda to open the console
8. Type
MyWindow.curObj.isRenderEnabled = !(MyWindow.curObj.isRenderEnabled);and it should toggle the visibility, but it doesn't NOTE: if you set it equal to false or true it does change the visibility.
This has probably been an issue for a while and isn't a big deal cause there are ways around it, but just thought I would point it out. Also I am sure there are other more complex or similar cases that reproduce the same behavior.
NOTE: PLEASE READ THE COMMENTS FOR THE ACTUAL BUG AND SOLUTION.
#2
Oh wait so echo(!MyWindow.curObj.isRenderEnabled); seems to work. Maybe it was just with assignment cause that is what I originally did.
Yeah I guess echo works, just tested it. I will revise my Post. It is only with assignment so this code causes it:
10/25/2010 (10:13 pm)
Well I think my object is client side only if I remember correctly, but I know it works because of this:echo(MyWindow.curObj.isRenderEnabled); //echos true MyWindow.curObj.isRenderEnabled = false; //Object stops rendering echo(MyWindow.curObj.isRenderEnabled); //echos false
Oh wait so echo(!MyWindow.curObj.isRenderEnabled); seems to work. Maybe it was just with assignment cause that is what I originally did.
Yeah I guess echo works, just tested it. I will revise my Post. It is only with assignment so this code causes it:
echo(MyWindow.curObj.isRenderEnabled); //echos true MyWindow.curObj.isRenderEnabled = !MyWindow.curObj.isRenderEnabled; //Still visible echo(MyWindow.curObj.isRenderEnabled); //echos true MyWindow.curObj.isRenderEnabled = !(MyWindow.curObj.isRenderEnabled); //Still visible echo(MyWindow.curObj.isRenderEnabled); //echos true
#3
10/25/2010 (10:18 pm)
Oh and just to let you know when I call isServerObject() on MyWindow.curObj it does return false, but like I said we are working with client side only objects and if I say MyWindow.curObj.isRenderEnabled = false; it stops rendering and when I echo it, it has a value.
#4
10/25/2010 (10:25 pm)
Wow this doesn't work either:%val = MyWindow.curObj.isRenderEnabled; MyWindow.curObj.isRenderEnabled = !%val;but this does:
MyWindow.curObj.isRenderEnabled = !true;
#5
10/29/2010 (6:07 pm)
Where you able to reproduce that Danial?
#6
10/29/2010 (10:17 pm)
From the console, yes. But only because local variables are lost between each line evaluated. If I use $val or put it in a function, it works fine.
#7
or
MyWindow.curObj.isRenderEnabled = !(MyWindow.curObj.isRenderEnabled);
I guess it is just evaluating it like this:
MyWindow.curObj.isRenderEnabled = !MyWindow;
or
MyWindow.curObj.isRenderEnabled = !MyWindow.curObj;
I still feel like it is being evaluated incorrectly, definitely makes sense with the local variable way since it is lost between lines like you said.
It isn't lost though on the same line is it? so if you do this:
It should work, but it doesn't. Or does it just end up evaluating it as separate statements and then the local variable is lost.
11/01/2010 (6:38 pm)
So why doesn't this work: MyWindow.curObj.isRenderEnabled = !MyWindow.curObj.isRenderEnabled;or
MyWindow.curObj.isRenderEnabled = !(MyWindow.curObj.isRenderEnabled);
I guess it is just evaluating it like this:
MyWindow.curObj.isRenderEnabled = !MyWindow;
or
MyWindow.curObj.isRenderEnabled = !MyWindow.curObj;
I still feel like it is being evaluated incorrectly, definitely makes sense with the local variable way since it is lost between lines like you said.
It isn't lost though on the same line is it? so if you do this:
%val = MyWindow.curObj.isRenderEnabled;MyWindow.curObj.isRenderEnabled = !%val;
It should work, but it doesn't. Or does it just end up evaluating it as separate statements and then the local variable is lost.
#8
This doesn't
11/08/2010 (8:49 pm)
I think what may actually be happening is it is treating it as a string, because this works:function myFoo(%curObj)
{
if(isObject(%curObj))
{
%enabled = %curObj.isRenderEnabled;
if(%enabled $= "true")
{
%curObj.isRenderEnabled = false;
}
else
{
%curObj.isRenderEnabled = true;
}
}
}This doesn't
function myFoo(%curObj)
{
if(isObject(%curObj))
{
%enabled = %curObj.isRenderEnabled;
if(%enabled)
{
%curObj.isRenderEnabled = false;
}
else
{
%curObj.isRenderEnabled = true;
}
}
}
#9
11/08/2010 (9:03 pm)
Yeah this has nothing to do with the order of evaluation it has to do with the getter for the protected function. Here is how to fix it. Change:const char* SceneObject::_getRenderEnabled( void* object, const char* data )
{
SceneObject* obj = reinterpret_cast< SceneObject* >( object );
if( obj->mObjectFlags.test( RenderEnabledFlag ) )
return "true";
else
return "false";
}toconst char* SceneObject::_getRenderEnabled( void* object, const char* data )
{
SceneObject* obj = reinterpret_cast< SceneObject* >( object );
if( obj->mObjectFlags.test( RenderEnabledFlag ) )
return "1";
else
return "0";
}
#10
11/08/2010 (9:05 pm)
Just let me know if I should edit my original post, post this as a new item, or just leave it like this since I figured out what is actually going on and it is different than what I originally thought.
Torque 3D Owner Daniel Eden