Letting the Player Set Attributes

The Pixie
A common problem with creating an RPG-style game is getting a way for the player to define attributes for his or her character, and to modify those attributes as the character gains experience (or increases in level). Here is an easy way to do just that.

Import the Library

All the hard work has already been done, and is in LevelLib.aslx.


The first thing you need to do is to include the library in your game, so (once you have it downloaded) expand the "Advanced" object in the left pane, then click on "Included Libraries". In the right pane, click on "Add", and navigate to the downloaded file. Save and reload.

The Player

You need to set up two attributes on the player object, so go to the Attributes tab.

The maxpoints Attribute

The first is called "maxpoints", and must be set to be an integer. This is the number of points the player has to create his character, so you might like to set it to between 5 and 10 at the start, and to slowly increase it as the game progresses (how you do that is very much game dependent, and beyond the scope of this article, but the code would look like this:

game.pov.maxpoints = game.pov.maxpoints + 1


The attlist Attribute

This attribute must be set to be a string list, and to this list you should add the names of the attributes that are important in your game, such as intelligence, charisma, etc. I would suggest between 3 and 5, but you can have as many as you want.

Start Script

Finally, you need to kickstart the process. On the game object, go to the Script tab, and at the top, look for "Start script". Click on "Add new script", and then "Call function" (under "Scripts"). Type "LevelUp" as the name of the function.

All Done

That is all you have to do. If you go into your game, you will find there is a new command, LEVEL, and typing it will allow you to spend points on the attributes you set up.

Now Just...

Of course, you need those attributes to mean something; what bonus does a high charisma give? You need a mechanism for the player to get extra points to spend (and to tell him he has spare points waiting to be spent). All that is up to you.

Turnscripts

One point to be aware of is that any turnscript running will count levelling up as several turns.

There is a way around that, at least for one turnscript. The turns of the levelling process each set an attribute called "notarealturn" to true on the game object. Your turnscript can test if that attribute is set, and if it is, set it to false, and even it is not, proceed as normal. In code, it might look like this:

  if (GetBoolean (game, "notarealturn")) {
game.notarealturn = false
}
else {
game.turn = game.turn + 1
}


Credits

The kernal of the LevelLib was designed by Jay Nabonne

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums