Tag Archives: statsystem

Happy (Almost) New Year!

Thought I’d write this post now seeing that I’ll likely be MIA for the festivities tomorrow, heh. I took a look back at my new year’s resolutions from last year, which were:

  • Not die during the apocalypse
  • Finish GRIDNET and many other games
  • Move out
  • Get serious enough with TF2 to reach competitive level
  • Socialize more and meet new people
  • Excel in classes
  • Get a part-time job

I (and many others) survived the apocalypse so my first bullet point was a success (yay!). However, I didn’t really hit the other ones so much. Early last year, I dropped development of Gridnet because I was spending far too long on such a behemoth idea. It got to the point where I was stressing about it and actually not looking forward to working on it each day. On the bright side after I shelved Gridnet, I released  two games Infested Space and soon-to-be-released Caved In 2 as well as two open-source projects StatSystem and  TileLighting! So while it wasn’t “many” games, I did at least do a few! As far as a job, I got quite a few interviews for game development positions, although many of them didn’t pan out. However, I did land a contract gig with BulletProofArcade as a game play programmer which has been pretty neat so far. The other bullets on that list were never met, to say the least.

Looking forward, I would like to go through with the #OneGameAMonth challenge for 2013. However I’m not quite sure how it will pan out because this is my final year in college and I’ll likely get quite busy. Nonetheless I’m still going to try because I really would like to have some more games under my belt. I already have an idea for my first game and a few vague plans for later months. I’m hoping to touch on genres that I haven’t before (like puzzle and strategy) and maybe even utilize Unity.

I’m also hoping to walk away from GDC this year with an internship or job. Last year, many of the employers wanted students who were graduating soon so I didn’t quite fit the bill with two years to go. This year however, I’m going to have my fingers crossed and my business cards ready!

Anyway, here’s the New Year’s resolutions list:

  • Get a job or internship in the industry
  • Finish more games (honestly, when will this ever not be on the list)
  • Go through with #OneGameAMonth
  • Meet some devs at GDC this year
  • Finish school

Fun Fact: I finally got around to getting my driver’s license the day the world was supposed to end.

StatSystem: Inventory and Item Management

[This is a tutorial for my AS3 stat library which can be found here. You can find the full documentation here.]

As of version 2.1.0, StatSystem contains inventory and item management features! This tutorial was created to introduce these new features. As usual, when functions and properties are mentioned, they will be linked to their respective location in the documentation.

The new features summarized in one sentence: an Inventory is a collection of ItemStacks, each of which hold an amount of an Item.

The Item class contains three basic properties:

  • name – the name of the item as a string
  • type – the type of item (this can be anything e.g. weapon, consumable, potion, and etc)
  • stack – the maximum stackable amount for this item in an ItemStack
  • stats – the StatSystem for the item

To create a new Item simply pass the desired name, (optional) item type, and (optional) max stack of the item. Here I’ve created a new item called “Health Potion” that is a “potion” type item and stacks to the maximum of eight.

PRO TIP: If you set the max stack of an item to -1, there will be no limit. This happens to be the default value if you do not pass a value in the constructor.

To clarify the “type” property: In RPGs, there are often different types of items – weapons, shields, armor, consumables, food, and so on – each that have a different set of stats. If you are familiar with FlashPunk, you can think of it the same way the Entity’s “type” property.

Now back to our Health Potion! Let’s say all of our potions in our imaginary game have following stats – health, mana, and worth. Since this our Health Potion obviously affects health, we’ll give it a value of 20, mana a value of 0, and lets make it an expensive by setting the worth to 500:

The reason we still add the “mana” stat to the health potion is because we want all “potion” type items to have the same stats (but they don’t have to have the same value!) so when we need to do something with it, we don’t need have have any special cases and use a “catch all” code block. For instance, take this code snippet for example:

Other good examples are weapons in rouge-likes since they often have a multitude of different attributes:

Now that we’re overflowing with cool items, you’ll likely want to store them all somewhere. This is where ItemStacks and Inventories come in handy!

First off, let me make it clear that an Inventory is a collection of ItemStacks, not Items. ItemStacks are stacks of identical items. If an item contains a property that changes over time (such as, charge, durability, etc) or can be changed by the player, you’ll want to set the max stack of the item to 1. For example, say you find a Steel Sword that has 10 points of durability left and you have a Steel Sword in your inventory that has full durability points. If the max stack isn’t set to 1, that almost broken Steel Sword will have max durability once you add it to your inventory since it will be added to a stack. Now here’s to actually use ItemStacks and Inventories.

An ItemStack has two properties : the item it contains and the amount of said item. So say we wanted to create a stack of Health Potions for a trip down into the dungeons:

PRO TIP: It’s also worth mentioning that ItemStacks have three methods for altering the amount – add(), remove(), and setAmount() which should all be self explanatory.

Now we need to create an Inventory to hold the stack. Inventories have only one property – the maximum size. So let’s create a small inventory of size 5 and then add our stack of potions:

PRO TIP: the size of an inventory is the number of slots, not the number of items it can contain.

Since our inventory was empty when we used addItemStack(), our stack of potions will take up the first slot. You can also add items via the addItem() method which takes an Item instead of an ItemStack and the amount of the Item to add.

To get our stack of items back from the inventory, we can use getBySlot() which returns an ItemStack at a specified slot in an inventory but doesn’t remove the ItemStack. Since our potions are in slot one, we’d pass “0″ into the parameters as the inventory slots are zero-based. To remove an ItemStack from a specified slot, use removeBySlot() by simply passing the slot and amount to remove in the parameters.

There will be other occasions where we won’t know where an item is in an inventory. This is where the removeByName() method comes in. The function takes a name and the amount to be removed.

This concludes the introduction to the item and inventory management features!

StatSystem: Experience and Level Management

[This is a tutorial for my AS3 stat library which can be found here. You can find the full documentation here.]

Typically when stats are involved in a game, there are also levels and experience that alter them. This tutorial will teach you how to implement an experience system using the library. When functions and properties are mentioned, they will be linked to their respective location in the documentation.

So let’s say we have a hero who should gain levels by meeting the required experience per level. First we must set up our stat system for the hero:

The health, mana, speed, and strength stats should be nothing new if you’ve completed the previous tutorials. The level and experience stats are what we are interested in.

The level stat will hold the player’s current level while the experience stat will hold the player’s current experience towards the next level. As you can see in the above code, the player is currently at level one with a max level of 100. Experience is currently at 0 with the requirement of 50 point in order to reach the next level.

Now we need to add one additional detail to the experience stat in order for this to work – the onFull function:

This property takes a function that is executed once the stat’s value meets the max max value, which just so happens to be very useful in occasions like this.

PRO TIP: There is also an onEmpty property that is executed once a stat is equal to zero. This can be useful for when a player’s health runs out!

Here’s how our levelUp function should look:

The above code block introduces two new functions – setValue and setMaxValue. Each of which sets the respective variable to the value passed in the parameter as opposed to adding via the addValue/addMaxValue functions.

PRO TIP: The setValue function will not allow a new value less than zero or greater than the max value and will execute the onEmpty and onFull functions respectively. Similarly, the setMaxValue function will not allow a new value less than zero, but has no positive limit. It will also scale the base value if it exceeds the new max value.

We’ll use addValue to reset the current experience to 0 and then just add a level-based amount to the max value. Using this method, the required experience for level2 will be 60, level3 will be 84, level4 134, and so on. However, you can use any formula you wish to calculate experience values. You can even use a preset array or vector for this too:

This concludes the experience and level management tutorial!

 

StatSystem: Getting Started

[This is a tutorial for my AS3 stat library which can be found here. You can find the full documentation here.]

This tutorial is meant to be a quick overview of the library. When functions and properties are mentioned, they will be linked to their respective location in the documentation.

Okay, let’s get started! In order to begin, you need to create a new stat system:

From here, you can add as many stats as you want with addStat which takes a single parameter – a stat. Create a new Stat and set the first parameter as the desired name:

PRO TIP: You can also remove stats via removeStat function, however, you probably won’t use this too often as stats typically don’t disappear mid-game.

Congratulations, you have created your first stat system! However, you’ll probably want to know how to manipulate the values of the stats. Above we initialized our stats with only a name, which means all their values are currently 0. So let’s add some value to them. First, we need to retreive the stat from the stat system with getStat:

The function retrieves stats by name, so make sure you use the same spelling and capitalization, otherwise it will return null. To alter the value of the stat, we use the addValue function:

Our speed stat now has a value of 100! To remove value from a stat, simply pass a negative value:

PRO TIP: You can initialize a stat with as starting value by passing a second paramater into the Stat constructor. For example, to initialize a stat with a value of 9:  myStats.addStat(new Stat(“awesomeness”, 9)).

Stats not only have a basic value, but also a max value. When the max value is set, the basic value will never be allowed to exceed the max value. Right now, the max value is at zero, so there is no limit to how high the stat can reach. Use addMaxValue to set the max value:

As you may have noticed, the max value is now less than what we had set the basic value to previously. However, the addMaxValue function scales back the basic value if it exceeds the max value. So right now the max value and the basic value are set to 40.

To get the basic value and max value, you can use the read-only variable value and maxValue:

PRO TIP: You can initialize a stat with as max value by passing a third paramater into the Stat constructor. For example, to initialize a stat with a value of 9and max value of 10 : myStats.addStat(new Stat(“awesomeness”, 9, 10)).

There will also be situations where you may want to save a stat or an entire system to a string, such as, saving a characters current progression to a file.

To save a entire stat system to a string, call saveToString:

The above output is the result of our stat system up to this point. To load a this output into a new system, simply pass the string into the loadFromString function of the new system:

PRO TIP: You can also save/load individual stats by calling their own saveToString and loadFromString functions respectively.

This concludes the getting started tutorial!

StatSystem: Modifiers

[This is a tutorial for my AS3 stat library which can be found here. You can find the full documentation here.]

This tutorial will cover on how to use modifiers. When functions and properties are mentioned, they will be  linked to their respective location in the documentation.

Modifiers can be thought of as temporary stat effects that can be removed at a later time. Say, for example, you put on the “Boots of Blinding Speed” which has a +50 speed effect and -10 field of view effect. This effect isn’t permanent as it should only be active when the boots are being worn. Such cases are where modifiers come into play.

Adding a modifier is easy! First you must of course have an existing stat system:

Now the boots have two effects: a +50 speed boost and a -10 FOV penalty. So we’ll need to apply a modifier to each stat by using the addModifier function:

The modifier constructor takes several parameters – a name, the value, and the type. Let’s just look at the name and value for now, the type will be discussed later.

The name property is works the same way as a Stat - anything goes as long as you retain the same spelling and capitalization later when you want to retrieve or modify it. The value property is the amount that the modifier should add to the stat or the amount it should remove if the value is negative.

In order to get the value of the stat with modifiers, you must use the valueTotal property instead of the value property. The value property only returns the base value of that stat, that is, the amount without any modifiers (even if there modifiers present). The valueTotal property on the other hand, returns the value of that stat with all affecting modifiers. You can also get the total value of  just the modifiers by using the valueModifiers property. For example, if a stat has a modifier that adds +4 but also a modifier that removes -2, then the valueModifiers property will return 2.

Say you are tired of running around blind and would like to regain your vision, so you take off the boots which means you also need to remove the modifiers. To do so, use the removeModifier function:

PRO TIP: The removeModifier function also returns the removed modifier just in case you need it post-removal.

PRO TIP: The modifier class also contains saveToString and loadToString functions just in case you would like to save them.

As previously mentioned, modifiers also have a type parameter. Modifiers have two types as defined by the constants VALUE and MAX_VALUE in the Stat class. VALUE type modifiers affect the basic value of a stat while MAX_VALUE type modifiers will affect the max value of a stat. Why should there be two types?

Simply because there are situations where you may want to alter the max value of a stat rather than the basic value. For instance, say you put on a “Ring of Health” that grants +10 health points. Typically, you don’t want such an item to affect the current health but rather the total amount of health overall. This is when you use the MAX_VALUE type modifier:

This concludes the modifier tutorial!

 

SOPA, PIPA, and The Internet Black Out

Today was the date of the “internet black-out” which was a protest of two bills crawling their way through congress right now – SOPA and PIPA (click here for more info). Google, Wikipedia, and many other websites participated in this protest by completely blacking out their websites or along the same lines. I myself blacked out my page for today and I also created a game for sopajam, which is an anti-sopa game compo over at Ludum Dare. After roughly 16 hours, I came up with SOPAOIDS. I took inspiration from bother Asteroids and Sophie Houlden’s Swift*Stitch.

On another note, I’ve been quite MIA from game development lately because of the extra load of course work as well as some personal problems. However, I feel rejuvenated after the sopajam, so I hope to pick up on GRIDNET here soon once I get some more free time. I’ve also started a StatSystem for RPG games or any games that need stats. I created it with FlashPunk in mind, so I suggest you pick that up as well if you plan on using my library. I’ll be adding to it more in the future.

Speaking of which, I really should update my Minecraft plugins and list them on the website as well…