Scripting with object created in level builder
by Jordan Hirsh · in Torque Game Builder · 06/20/2006 (4:00 pm) · 8 replies
I am having a hard time figuring out how I should go about changing parameters of objects i created in the level editor via script. In one particular instance I am trying to use the stopEffect() function on a particle effect I mounted to my player object (in the level editor) . I am probably just missing somthing basic but cannot seem to find a resource that explains this procedure.
For instance does anyone know how one would modify the playerjet that is mounted to the player ($pShip) in the shooter demo via script?
If further explanation is needed please let me know,
Jordan Hirsh
For instance does anyone know how one would modify the playerjet that is mounted to the player ($pShip) in the shooter demo via script?
If further explanation is needed please let me know,
Jordan Hirsh
About the author
#2
06/21/2006 (8:34 am)
Really anything, how about stopEffect(); or rotate or change size or whatever. The problem I am having is accessing the object via script.
#3
You can then access the effect in script by using myCoolEffect (note, there is no $ or % in front of it). So now can call myCoolEffect.StopEffect();
This applies to pretty much every object in the TGB, just give it a name and you can access it in script.
Alternately, you can give the object a class and put the class name in the Class textbox under Scripting. In the onAdd method for the class, you can store a reference to the object in a global variable, add it to a simset, etc. For example, if your class name was MyParticleClass, your onAdd method would look like this:
Now you can access your particle effect by using $MyGlobalVariable. Note that if you add another particle effect with the class MyParticleClass, the value for $MyGlobalVariable will be overwritten. $MyGlobalVariable will always refer to the last MyParticleClass object that was created.
06/21/2006 (9:07 am)
Select your particle effect in the level builder. On the right side of the screen, select the Edit tab (the same place you control the emiters). Expand the section named "Scripting". Give your effect a name by entering it in the Name field (for example, myCoolEffect).You can then access the effect in script by using myCoolEffect (note, there is no $ or % in front of it). So now can call myCoolEffect.StopEffect();
This applies to pretty much every object in the TGB, just give it a name and you can access it in script.
Alternately, you can give the object a class and put the class name in the Class textbox under Scripting. In the onAdd method for the class, you can store a reference to the object in a global variable, add it to a simset, etc. For example, if your class name was MyParticleClass, your onAdd method would look like this:
function MyParticleClass::OnAdd(%this)
{
$MyGlobalVariable = %this;
}Now you can access your particle effect by using $MyGlobalVariable. Note that if you add another particle effect with the class MyParticleClass, the value for $MyGlobalVariable will be overwritten. $MyGlobalVariable will always refer to the last MyParticleClass object that was created.
#4
06/21/2006 (9:48 am)
Thank you very much for your concise response. I knew it would be something simple that I had somehow missed.
#5
06/25/2006 (10:39 am)
Also, a little sidenote, from my experience things like rotation and flip don't work while a particle/object is mounted, you have to first unmount the particle (haven't tried while mounted since RC1 though) before you can rotate/flip etc.
#6
The TGB Reference.pdf discusses this in the .mount() section.
06/25/2006 (1:10 pm)
By default, when you mount an object to another object, the "inheritProperties" is defined as true, which means that instead of being able to directly affect basic properties, they only use what the parent has (which means you can't change them while mounted in this state).The TGB Reference.pdf discusses this in the .mount() section.
#7
Here's an example of how to do the same thing without a global by making the particle effect a dynamic field on the player it's mounted to:
You could then access your player's particle effect like so:
I hope that helps.
06/25/2006 (3:42 pm)
Also, it's generally considered to be good programming style to avoid using global variables (and global functions for that matter) whenever possible. This is usually pretty easy and can potentially save you a lot of headaches later on.Here's an example of how to do the same thing without a global by making the particle effect a dynamic field on the player it's mounted to:
function MyParticleClass::onAdd(%this)
{
if(%this.getMountedParent().getClassName() $= "MyPlayerClass")
{
%this.getMountedParent().playerEffect = %this;
}
}You could then access your player's particle effect like so:
function MyPlayerClass::someFunction(%this)
{
...
%this.playerEffect.stopEffect();
...
}I hope that helps.
#8
GG is a great community, thx for all your hard work!
06/26/2006 (7:49 am)
Thomas your implementation def looks like the way to go. Thank you all for the input; I appreciate it. GG is a great community, thx for all your hard work!
Torque Owner Jason McIntosh