Spawning Interiors During Runtime...
by Welias D. Willie II · in Torque Game Engine · 11/27/2004 (1:24 pm) · 6 replies
I have searched the forums, reviewed Ken's book and I am sure it is something simple that I am missing, however, can someone tell me why this code causes my torque to crash...
I have used echo() on every step and it seems to work all the way to setting %obj = new Interior Instance() as I get a new Object ID number in that variable. That is the moment it crashes.
I have removed the position and rotation settings and defaulted them to position = "0 0 0"; and rotation = "1 0 0 0"; this seems to work BUT no object appears in the mission and if I use the console to adjust the position manually of the new object (pulling the id from %obj) it crashes. The object does not appear in the World Editor tree either.
By the way, %client.getSelectedObj(); works perfectly in my other functions. This script is an attempt at copying an existing object and placing it in the mission just above the original object.
function serverCmdduplicateObject(%client)
{
%obj = %client.getSelectedObj();
%pos = %obj.getTransform();
%name = %obj.interiorFile;
%ax = getWord(%pos,0);
%ay = getWord(%pos,1);
%az = getWord(%pos,2);
%aa = getWord(%pos,3);
%ab = getWord(%pos,4);
%ac = getWord(%pos,5);
%ad = getWord(%pos,6);
%az += 5.0;
// setting %obj to the new Interior:
%obj = new InteriorInstance()
{
position = %ax SPC %ay SPC %az;
rotation = %aa SPC %ab SPC %ac SPC %ad;
scale = "1 1 1";
interiorFile = %name;
showTerrainInside = "0";
};
}I have used echo() on every step and it seems to work all the way to setting %obj = new Interior Instance() as I get a new Object ID number in that variable. That is the moment it crashes.
I have removed the position and rotation settings and defaulted them to position = "0 0 0"; and rotation = "1 0 0 0"; this seems to work BUT no object appears in the mission and if I use the console to adjust the position manually of the new object (pulling the id from %obj) it crashes. The object does not appear in the World Editor tree either.
By the way, %client.getSelectedObj(); works perfectly in my other functions. This script is an attempt at copying an existing object and placing it in the mission just above the original object.
About the author
#2
%obj = %client.getSelectedObject(); // usually returns 1414 (a valid DIF object currently visible in the mission)
%pos = %obj.getTransform(); // works great
%name = %obj.interiorFile; // works great - gives me the path to the DIF of object 1414
Like I said, I pulled out all the getWords and simply did this:
For good measure I even added this after the above code:
I can use the console and view the tree(); and the object appears in the following location:
xxxx: ServerGroup - SimGroup
|__ xxxx: MissionGroup - SimGroup
|__ xxxx: InteriorInstance
When I view the object I just inserted into the mission and try to change the location by copy/paste of another items location (that is visible in the mission) and when I click "apply", torque crashes hard.
InteriorInstance is a sub group of MissionGroup (formatting didn't work above)
11/27/2004 (2:46 pm)
Yes, I have confirmed that the path is correct. I defined it in %name....%obj = %client.getSelectedObject(); // usually returns 1414 (a valid DIF object currently visible in the mission)
%pos = %obj.getTransform(); // works great
%name = %obj.interiorFile; // works great - gives me the path to the DIF of object 1414
Like I said, I pulled out all the getWords and simply did this:
%obj = new InteriorInstance()
{
position = "0 0 0";
rotation = "0 0 0";
scale = "1 1 1";
interiorFile = %name; // I confirmed the path is correct
showTerrainInside = "0";
};For good measure I even added this after the above code:
MissionGroup.add(%obj);
I can use the console and view the tree(); and the object appears in the following location:
xxxx: ServerGroup - SimGroup
|__ xxxx: MissionGroup - SimGroup
|__ xxxx: InteriorInstance
When I view the object I just inserted into the mission and try to change the location by copy/paste of another items location (that is visible in the mission) and when I click "apply", torque crashes hard.
InteriorInstance is a sub group of MissionGroup (formatting didn't work above)
#3
This:
should be:
This fix allows the object to actually be placed in the tree (per my post just above) but when I try to setTransform either manually or in the editor Torque crashes.
11/27/2004 (2:51 pm)
Actually I found an error in my first post, however, it has not corrected the problem.This:
rotation = %aa SPC %ab SPC %ac SPC %ad; or when I just hard coded it and dropped the use of getWord(); rotation = "0 1 0 0";
should be:
rotation = "0 0 0";
This fix allows the object to actually be placed in the tree (per my post just above) but when I try to setTransform either manually or in the editor Torque crashes.
#4
For future reference, if anyone is dynamically loading DIF objects here is the fix (yes it requires a C mod):
CORRECTED LINK:
http://www.garagegames.com/mg/forums/result.thread.php?qt=19877
11/27/2004 (6:57 pm)
I did some more searching on the forums and founda solution to the error I was having here. For the record, I stated that rotation should only have 3 numbers, when in fact it should be 4 numbers (quarternion rotation as normally required throughout torque).For future reference, if anyone is dynamically loading DIF objects here is the fix (yes it requires a C mod):
CORRECTED LINK:
http://www.garagegames.com/mg/forums/result.thread.php?qt=19877
#5
11/27/2004 (7:04 pm)
What forum is that thread in? First one I found that I didn't have permissions for :(
#6
" to the end of the link which would of course make qt=19877
instead of the required resource of qt=19877 - I corrected the link in the post above.
or just copy this:
http://www.garagegames.com/mg/forums/result.thread.php?qt=19877
11/27/2004 (7:58 pm)
Sorry, I posted the link wrong - it was adding "" to the end of the link which would of course make qt=19877
instead of the required resource of qt=19877 - I corrected the link in the post above.
or just copy this:
http://www.garagegames.com/mg/forums/result.thread.php?qt=19877
Torque Owner Stefan Lundmark
Have you really made sure the GetWord part is working and giving the expected values? Try echoing %obj.position and &obj.rotation when it has been created or when you want to create it.
Edit: Nevermind the latter, I didn't think when I read the code.