Game Development Community

Respawning objects AND their mounted particle effects?

by Robert · in Torque Game Builder · 06/25/2007 (1:47 pm) · 12 replies

I am making a simple space shooter game, and have mounted a jetstream particle effect to each ship. Whenever each ship respawns however, the particle effect does not. I am using behaviors to program the respawning. How can I change it so that the particle effects respawn with the ships? What must I do in order to mount the effects to the ships for good?

#1
06/25/2007 (2:37 pm)
The easiest way to do this would be to create a "template" particle effect, giving it the name jetstreamTemplate. Create a new one every time your ship respawns with %newParticle = jetstreamTemplate.clonewithbehaviors(), then mount it to your new ship with .mount().
#2
06/25/2007 (2:59 pm)
Thanks for the fast response. i don't understand a couple things though.

how do you create a template particle effect and what does that do?

also, I am (unfortunately) an inexperienced programmer and do not understand that line of code u wrote. could you please explain how that line works and how i am supposed to use it? (i was using behaviors because i didnt know how to program anything)

thanks
#3
06/25/2007 (3:23 pm)
A template is just a name for an object from which you can make copies. Just drag a sprite into the world and put it off screen a bit. With the sprite selected, go to the edit tab and scroll down to "Scripting." Name it jetstreamTemplate.

What are you using to respawn your ship? Go to your respawn function and add this:

%newJetstream = jetstreamTemplate.cloneWithBehaviors();
This creates a "%newJetstream" object. cloneWithBehaviors() makes a copy of the template you made in the scene editor, which we call using its name "jetstreamTemplate"

That makes the copy, but then you need to mount the particle effect to your ship. I'm not sure how/where you are respawning your ship. If you post that code, I can be a little more specific, but for now here's this...
Now add this below the last line:

%newJetstream.mount(%newSpawn, "0, 0", 0, false, true, true, true);

This line takes the new jetstream we just created and mounts it to "%newSpawn"--but you should change this to whatever your newly spawned ship is. "0, 0" is the point on the ship that it is linked.

You may need to change the "link point." You can do this manually by changing the numbers yourself, or you can retrieve the place where you mounted the particle effect by using %newSpawn.getLinkPoint(). Let me know if you need any more help.
#4
06/25/2007 (4:08 pm)
Thanks for the detailed response.

you have asked how i am respawning the ship... well to be honest, I am unsure of how to do this as well... I WAS using the Spawn on Remove behavior from the listing at TDN, but that has not been working very well for me because my application of the behavior has been different than the intended one and i am unsure of how to edit the behavior correctly. in other games i used the shooter tutorial at TDN to come up with the code i needed to respawn enemy ships. but that was complex too and i didn't understand it enough to apply it for my own applications. my idea for the game is basically the same as the one in the tutorial, i just wanted to add cool effects. if u think seeing the tutorial and the coding involved can help here is the link to the tutorial.
but what i really need help with is the language. if i just knew how it worked then i might be able to write my own code instead of relying on other people's work. if you don't mind, could you just give me a little overview of the syntax, maybe supply some resources i could look at? i haven't looked too much at any programming tutorials on TDN. maybe those can help me? the thing is, i am ok reading script; i can understand the basic output. i just cannot write it on my own.

once again, thanks so much.
#5
06/25/2007 (4:21 pm)
I suppose the post above has nothing to do with the original topic of the thread.... but thats ok... this is what it all comes down to anyways.
#6
06/25/2007 (4:27 pm)
You may want to check out tdn.garagegames.com/wiki/TorqueScript_Quick_Reference for the basics, and tdn.garagegames.com/wiki/Torque_2D/Reference_Guide this is an excellent resource for all of the methods you can use on objects in your game.

Hrrrrm I guess I could get you started on simple functions/variables, since those are the meat of the thing. Essentially, you write functions like this:
function nameOfObject'sClass::nameOfFunction(%variablePassedIn)
{
   //stuff!
   %variable = "something"; //<--semicolon at the end of lines
   $hey = "this is a global variable because it has a $ before its name";
   echo("this is an echo statement and it can help you debug");
}
You would call this function like this:
nameOfObject'sClass.nameOfFunction(%variablePassedIn);

tdn.garagegames.com/wiki/TGB/Behaviors/CreatingBehaviors is also a resource for writing your own behaviors if you haven't checked it out yet.

If you have more specific questions, I can try to answer them. Looking at the code examples/tutorials and modifying it is a good way to start out.

Also, syntax is definitely a bump in the road when learning a programming language. If you haven't checked out the console feature of TGB, try running a game and hitting the "'" key. It'll pop open a window where you can see errors/echo statements for debugging.

Let me know if you need any more help :D
#7
06/25/2007 (4:45 pm)
Three questions this time:

what do u write inside the function brackets? i mean i know u write what the function is supposed to do there, but is there any method or order to doing that?

also what is the "variablePassedIn"? is that the variable that the function uses?

i also forget what "calling the function" means. is that refering to it in a different part of the code? if so how might you use that?

thanks again for being so patient and responsive.
#8
06/25/2007 (4:59 pm)
Here's an example, hopefully it'll cover your questions:

Calling the function--you're right, it's typically another part of the code. If you have a function like this:

function RespawnBehavior::onLevelLoaded(%this)
{   
   %numberOfBunnies = 10; //a local variable (can only be used in this function unless we pass it to another)
                                             //btw, this is a comment that doesn't affect the code in case you didn't know

   explodeEverythingHahaha(%numberOfBunnies);
  //here we call a function called "explodeEverythingHahaha."  We can "pass" a variable from this function to
  //the other function.  in this case, we passed it %numberOfBunnies.  We can pass in as many variables as
  //we want, separated by commas--now scroll down to the explodeEverything function...

   %this.getBunnies();
   //this time, we call a function associated with an object
   //here, %this is a behavior object.
   //functions that are "associated" with a type of object can only work on that type of object
}

function RespawnBehavior::getBunnies(%this)
{
   //%this is always passed into a function that is "associated" with an object, even if you don't type it in
   //the call...
   //Note the name of this function.  The first part, RespawnBehavior, is what object it is associated with
   //getBunnies is its actual name
   %this.safeDelete(); //this is how you would delete this behavior...this code doesn't exactly make sense :P
}

function explodeEverythingHahaha(%numberOfBunnies)
{
   if (%numberOfBunnies > 5)
   {
       echo("OH NO"); //this function just prints out an echo statement, it isn't that exciting
   }
}

hope this helps a little bit, please don't hesitate to ask questions etc. :D
#9
06/25/2007 (5:27 pm)
Thanks so much this is all coming together now! just a couple more questions and i might be done for the day! :-)

first of all, what exactly is "%this"? i see that everywhere but i don't know what it means or how to use it...

also, why are there two different RespawnBehavior functions. what do the getBunnies and onLevelLoaded parts and the parts in parentheses mean exactly?

also i think the getBunnies function is called in the onLevelLoaded thingy (i dont know what to call it), but what does the safeDeleve() actually delete when it is called in a different function?
#10
06/25/2007 (7:53 pm)
O i get it! reading this more carefully you explain it in the comments. the RespawnBehavior is the object. the getBunnies and onLevelLoaded parts are the actual function names. ok cool. i still dont quite understand what "%this" is though, but i think you explained it, so maybe ill read over a couple times again.
#11
06/26/2007 (8:37 am)
If you had this function, it would activate when the level is loaded:

function playerShip::onLevelLoaded(%this, %scenegraph)
{
   error(%this.class);
}

then %this would refer to playerShip and would print out the "playerShip"
%this is just a pointer to the object/class that is calling the function.

I'd check out some books about programming basics/essentials, maybe look at Java (or VB if you must lol) for more about general programming ideas like class inheritance etc.
#12
06/26/2007 (10:26 am)
Ok thanks for the advice. i am a "master" programmer on my TI-84 calculator, but its a lot different with C++... ;-)