Navigation

Monday, May 1, 2023

Character Building 101: How to Build a Level Up System in Stencyl

What is Character Building?


Character building is the backbone of every great RPG game ever made.It's not only for RPG's, though. Over the past decade we are seeing more and more games of different genre's dip into the realm of character building. Even first person shooters are beginning to adopt character building principles (think Borderlands).

To be concise, when I say character building, I mean that the particular game in question has a built in system where your character accumulates experience. That experience usually translates into higher attack power, higher defense, new magical abilities etc. This style of character building is more commonly known as role playing (RPG  - role playing game).

Another type of character building would be acquiring experience in one form or another, and then using that to purchase upgraded abilities (Dante's Inferno).  We will cover building a skill tree of that nature in another tutorial here in a few days.

Today, we are going to go in depth on the first idea I stated, a classic RPG style level up system. The system is pretty simple overall. We are basically going to create a character behavior to attach to our main actor, or playable character. This behavior will watch for one variable ($experience) to become greater than, or equal to, another variable ($NextLevel). Once the experience surpasses the quota for the next level, it will increment our level up one. It will then increment all of our other character attributes, like attack, defense, and max health. Once all of our character specs have been incremented, it will create a new $NextLevel value, so that the behavior can once again begin to watch for a new level up instance.

The Difference Between Getters/Setters and Game Attributes


Before we get started putting our blocks together, we need to discuss the difference between getter/setters, and game attributes. Getters and setters in stencyl are the equivalent of a variable with local scope in an actual programming language. For those of you who know a bit of programming, you already know where this is heading. For those that don't know, a variable with local scope will only function within the confines of where it's created. Sometimes this means one page of a website, or it could mean one particular function of a whole program. These types of variables are used for things that we don't need to pass on to the rest of the program.

A good example of when to use local scope in a game would be the boss battles in the old Mario games. Instead of coding a health bar and doing math to take damage, in a game like this, you could create a code block that checked how many times the boss has been hit, every time he gets hit. The code block increments the HitCount by 1. It then checks to see if the HitCount is greater than, or equal to, three. If this is the case, Bowser dies (sorry Bowser). All of this would be done locally as we don't need it to carry on to any other part of the game.
An example of how to increment damage for simpler games.

When coding a level up system, we have no use for local scope variables. They won't do us any good if they can't follow us around for the entirety of the game, no matter where the game takes us. But don't you worry your pretty little head. Like a good neighbor... global scope is there!

That's right. With a global scope, a variable and it's contents and be manipulated and called on from anywhere in the game. The stencyl equivalent of global scope is Game Attributes. To access these, while in the coding screen, click on the attribute category of blocks, and then in the sub-categories click on Game Attributes.

If we create all of our characters statistics with game attributes, we are now able to create a very simple code block that allows the game to constantly check to see if our experience is sufficient to level up. If we have enough experience to do so, that same code block will increment all of our character traits, increment the amount of experience needed to level up again, and then just for fun, it will also refill our health and energy meters to our new max health and max energy levels.



Implementation


Code blocks depicting how to create a level up system in stencyl.Now we have our very basic level up system. Our game now knows that once we accrue a certain amount of experience, to let us know that we are a little bit smarter than we were a few seconds ago (and stronger, too). Now, how do we start collecting all that experience?:Easy...peasy...Mrs. pacmans sleazy.

All we need to do is add a little bit of code to all of our enemies to define the amount of experience that they will give us if we completely and utterly destroy them (isn't that nice of them to do that?). Simply create another game attribute with a unique name, that can easily be identified as being the experience given for killing this particular enemy.


An example of how to retrieve experience from enemies in stencyl





Optionally, if you were building a much larger game where you may face the same enemies down the road, but they will be much stronger, you could increment the experience similarly to how I did in our level up blocks. You could also use this method to increment the traits of the enemy it's self, instead of creating a whole new actor with the same graphics.





What's Next?


My next few tutorials are going to walk you through the advanced mechanics of character building. Here are just a few of the topics that we are going to discuss:

  1. HUD's, or Heads Up Displays. I am going to show you how to implement health bars, energy bars, magic bars, etc.
  2.  I am going to get a little more in depth with the math behind  this level up system.
  3. Leveling up for RPG style games where you control more than one character, I.E. leveling up several playable characters separately (Final Fantasy Series).
  4. Skill Tree's ( I told ya so)
  5. Status Effects (poison, sleep, etc.)
  6. Stat boosting based on equipped items (think Diablo).
  7. Xbox style achievements
  8. And a whole lot more...

1 comment:

  1. So.... how do I access the other 9 steps? I cannot find them.

    ReplyDelete