Game Development Community

Experience system, for leveling, how to stop a function with an if statement

by Michael S · in Torque 3D Professional · 03/30/2012 (5:18 pm) · 5 replies

Ok everyone, I now made an experience system, for leveling, its quite simple, I have not made gui assets for it yet, but thats so simply because the script is not done, and this is because I need help with one thing. I need to know how to stop a function with an if statment, as in if($playerLevel == 40)
{
STOPFUNCTIONFORLEVELING!
}




#1
03/30/2012 (5:31 pm)
I would do it something along like this:
// set the maximum level a player can achieve
$Game::MaxPlayerLevel = 40;


// determine if the player meets requirements to level up
if($player.currentLevel < $Game::MaxPlayerLevel)
{
   // level up player code goes here..
}

Now if you're in the leveling up function and simply just want to abort out then do it like this:
function PlayerLevelUp(%player)
{
   // enforce maximum player level limit
   if(!(%player.currentLevel < $Game::MaxPlayerLevel))
      return; // player has reached maximum level possible, abort out

   // level up player code goes here..
}

Enjoy! :)
#2
03/30/2012 (9:35 pm)
Thanks, helped immensely. I now got most of the things I need working, just need to set up the gui for them, then I can get on to some gameplay features. Learning torque script is ending up to be a great idea :D
#3
03/30/2012 (10:49 pm)
Instead of making a new post, I figured I would ask one more question here, which is how do I load a particle system upon leveling? Thanks in advance.
#4
04/01/2012 (3:06 pm)
I'd like to know something similar myself, any help is appreciated :)

Edit: I saw you made a new thread about the previous question, ignore this :)
#5
04/09/2012 (6:13 pm)
@Mighty Mike, if I were you, I would just instantiate a new Particle Emitter object everytime the player levels up. (I do suggest you should learn torquescript though). Example:

%particle = new ParticleEmitter() {
   emitterNode = YourParticleNode; //you would replace this with your node
   emitter = yourparticleemitterdatablock; //you would have to create that
   position = localclientconnection.player.getWorldBoxCenter(); // "x y z"
   rotation = "1 0 0 0"; //can be replaced "x y z angle"
   scale = "1 1 1"; //"x y z"
};
if (!isObject(MissionCleanup)) {
   new SimGroup(MissionCleanup);
   ServerGroup.add(MissionCleanup);
}
Missioncleanup.add(%particle);
%particle.schedule(2000,"delete"); //deletes the object from the world

was doing this from memory, code may slightly vary

Hope this helped.