Weird Script Issue [Resolved]
by Justin Proffitt · in Torque Game Builder · 09/12/2011 (7:58 pm) · 0 replies
Well it would seem that I have reached an impasse. As I have mentioned before, I use t2dsceneobjectgroups in order to organize my sogui into nice chunks. In order to quickly manipulate whole windows, I defined a function for simsets like so:
This simply overwrites the "setFieldValue" method defined for SimSets to pass the method defined for SimObjects throughout the entire SimSet, making it very easy to enable/disable a group swiftly.
In the case of my pause window, I use this to switch between the various menus. The t2dsceneobjectgroups look roughly like this:
So I start with PauseRootMenu enabled, and then to switch to say my cargo menu, I call a "goToCargoMenu" function that basically does this:
Seems sound, and PauseRootMenu turns off alright, however, my new menu doesn't load.. half the time, sometimes only parts of it comes up. I am confounded because I was using a specific "setEnabled" function that filtered down before this and I never had any problems. The only thing I can possibly think of, is that the fact that $timescale being set to 0 somehow magically bonkifies code executing at roughly the same instant. This doesn't happen anywhere in my other (much more complex) menus that don't manipulate $timescale. And calling a dump on objects located in the troublesome menu reveals that its enabled IS in fact set to "1".
I just don't know, it's very frustrating, I spent a long time expanding what I could do with my simsets and adapting it. : (
Edit: I used my other function, which passes methods of my choice to all objects in a simset, and that works perfectly. So it would seem the issue is something to do with using the method versus setting the value directly.
Edit2: After passing the setEnabled method once, the window will start working perfectly fine with the script again, so now I am even more confused.
Edit3: After further testing, it would seem that indeed that any given field of an object in a $timescale of 0 has a chance of not influencing its behavior until it is specified by a function. So I'm guessing it has to do with the source side being unable to initialize certain behaviors while $timescale is at zero.
Edit4: Aha! Their physics are somehow disabled. Calling "setPosition(%obj.getPosition())" on them fixes them.. though only when their "Enabled" fields are set to "1".
Last edit: Got it, they were not being initialized properly because the ones that inherited an Enabled setting of 0 from its simset couldnt start their physics by setting their position. So I simply changed my initialization code to briefly switch the Enabled status to 1 while initializing, then back to whatever it should be. Now it all works perfectly fine ^^ Sorry for the mess.
function SimSet::setFieldValue( %this, %field, %value ){
for(%i = 0; %i < %this.getCount(); %i++)
%this.getObject(%i).setFieldValue(%field, %value);
eval(%this @ "." @ %field @ " = \"" @ %value @ "\";");
}This simply overwrites the "setFieldValue" method defined for SimSets to pass the method defined for SimObjects throughout the entire SimSet, making it very easy to enable/disable a group swiftly.
In the case of my pause window, I use this to switch between the various menus. The t2dsceneobjectgroups look roughly like this:
PauseScreen{
PauseRootMenu{ objects };
PauseCargoMenu{ objects };
PauseOptionsMenu{ objects};
etc.
};So I start with PauseRootMenu enabled, and then to switch to say my cargo menu, I call a "goToCargoMenu" function that basically does this:
PauseRootMenu.setFieldValue("Enabled","0");
PauseCargoMenu.setFieldValue("Enabled","1");Seems sound, and PauseRootMenu turns off alright, however, my new menu doesn't load.. half the time, sometimes only parts of it comes up. I am confounded because I was using a specific "setEnabled" function that filtered down before this and I never had any problems. The only thing I can possibly think of, is that the fact that $timescale being set to 0 somehow magically bonkifies code executing at roughly the same instant. This doesn't happen anywhere in my other (much more complex) menus that don't manipulate $timescale. And calling a dump on objects located in the troublesome menu reveals that its enabled IS in fact set to "1".
I just don't know, it's very frustrating, I spent a long time expanding what I could do with my simsets and adapting it. : (
Edit: I used my other function, which passes methods of my choice to all objects in a simset, and that works perfectly. So it would seem the issue is something to do with using the method versus setting the value directly.
Edit2: After passing the setEnabled method once, the window will start working perfectly fine with the script again, so now I am even more confused.
Edit3: After further testing, it would seem that indeed that any given field of an object in a $timescale of 0 has a chance of not influencing its behavior until it is specified by a function. So I'm guessing it has to do with the source side being unable to initialize certain behaviors while $timescale is at zero.
Edit4: Aha! Their physics are somehow disabled. Calling "setPosition(%obj.getPosition())" on them fixes them.. though only when their "Enabled" fields are set to "1".
Last edit: Got it, they were not being initialized properly because the ones that inherited an Enabled setting of 0 from its simset couldnt start their physics by setting their position. So I simply changed my initialization code to briefly switch the Enabled status to 1 while initializing, then back to whatever it should be. Now it all works perfectly fine ^^ Sorry for the mess.
About the author
I am a college student majoring in physics. As it so happens I like programming, a hobby which extends my profession in web design.