• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Arrays for RPG stats for each level?

B

Brackleforth

Guest
Hello,

I am interested in making an array for each of my 4 RPG party characters to determine their stats.

The array should go from level 1 to level 99, and use a calculation to determine the MAX HP, ATTACK, and MAGIC statistics for each level. For example, maybe they all raise by a flat value, and then that new sum is multiplied by 1.05 and rounded to the nearest integer.

This way, when a character levels up, I want it to automatically grab their stats in the array...

Has anybody created arrays like this before? I imagine you use a for loop or something like that to initiate it.

Thanks!
 

Psycho_666

Member
Very simple, very useful, very versatile. Once you get the hang of arrays you unlock so much more features in your arsenal as game dev.
You want an array of sprites? No peoprobl. You want one with sounds as well? Have those in the same array as the sprites.
Using arrays is as simple as a single for loop.
for(i=0;i<10;i++)
{
array[i,0]=sprite;
array[i,1]=sound;
array[i,2]=name;
...
}

Now for the actual calculation you can just replace the old value with the new value.

PS: If you feel adventurous, try and use files for that. Be it ini or txt or whatever. it will help massively with piling up content later on. You would be able to just write everything in a simple text file in notepad, rather than having to program every value in GML...
 

Rob

Member
Can I also recommend using Enums. If you're gonna make an RPG and you might have more than a couple of stats then it will save you a lot of time and effort (although if you initialise them in the way I suggest, you can't use a for loop).
 
B

Brackleforth

Guest
I think this much is correct?

for(i=0;i<98;i++)
{
// MAX HP
global.partymember1_stats[i,0] = ???
// ATTACK
global.partymember1_stats[i,1] = ???
// MAGIC
global.partymember1_stats[i,2] = ???
}

What should I write in place of the question marks to make it cumulative and add up from the previous value in the for loop? I am rather new to this

The enums are interesting. What is the main benefit of enums?
 

Relic

Member
Player1stats=[stats.hp,6]=14 is more readable than player1stats=[0,6]=14. You also do not need to remember hp is in position 0 throughout your development.

You can refer to the previous level stat by calling on the i-1 position in the array in your loop:

Player1stats[i,0]=round(Player1stats [i-1,0]+5)*1.4)

You will need to choose the index 0 stats before the loop as there is no i-1 index in this case.
 
B

Brackleforth

Guest
How's this? For this project I do not mind remembering that 0 refers to max hp, 1 to attack, and 2 to magic. It's a relatively small project so I'm not incorporating defense or agility or dodging etc.

// initial stats
global.partymember1_stats[0,0] = 5
global.partymember1_stats[0,1] = 5
global.partymember1_stats[0,2] = 5
// subsequent stats after levelups
for(i=1;i<98;i++)
{
// MAX HP
global.partymember1_stats[i,0] = round(global.partymember1_stats[i-1,0]+(global.partymember1_stats[0,0])*1.4);
// ATTACK
global.partymember1_stats[i,1] = round(global.partymember1_stats[i-1,1]+(global.partymember1_stats[0,1])*1.4);
// MAGIC
global.partymember1_stats[i,2] = round(global.partymember1_stats[i-1,2]+(global.partymember1_stats[0,2])*1.4);
}
 

Relic

Member
The code works, not sure about your intention though. Are you happy that level 0 is 5, level 1 is 12, level 2 is 19? Your current maths has each level adding 7 points (because you always add 1.4 x level 0 which is 7.

You could have saved a lot of grief and just had your code read hp=level*7 + 5 and not worry about arrays or anything.
 

YanBG

Member
PS: If you feel adventurous, try and use files for that. Be it ini or txt or whatever. it will help massively with piling up content later on. You would be able to just write everything in a simple text file in notepad, rather than having to program every value in GML...
Do you read it directly or with parsing? Right now i'm using csv setup with semicolons.
 
D

dannyjenn

Guest
Enums make the code more readable which is especially important for an RPG. You don't want to be looking back through your code a month from now (or even just a few days from now) and wondering, "Which index number did I use for HP?" or "Was index 3 the attack stat or the defense stat?".

Consider,
Code:
enum player{
    alice,
    john,
    eve,
    bob
}

enum stat{
    level,
    max_hp,
    hp,
    level,
    exp,
    attack,
    defense,
    magic,
    speed
}

stats[player.bob, stat.hp] = 10; // clearly sets Bob's HP to 10
stats[player.alice, stat.defense] = 8; // clearly sets Alice's defense to 8
as opposed to
Code:
stats[3,2] = 10; // sets something to 10
stats[0,6] = 8; // sets something to 8
The former is nice and clear. The latter is obscure and mysterious.

Plus, enums make the code easier to edit. If, for example, you later decide you don't need the HP stat anymore, you can simply remove it from the enum and all the indices will adjust automatically. But if you hardcode it so that the hp index is 2, then if you ever remove it then your arrays are going to have empty cells in them.

(Though I personally use macros rather than enums. They're not as automatic nor as organized, but I like their brevity.)
 
Last edited by a moderator:
D

dannyjenn

Guest
I think he's asking about the formatting itself.

GMS does have built-in functionality for text files, but you're still going to need to parse the text somehow. Without parsing you just have a text file with a long list of values:
Code:
Alice
10
2
8
Bob
16
12
7
And this might be ok in certain situations. But it would be nicer if you could format your file like:
Code:
player Alice
    attack=10
    defense=2
    magic=8
player Bob
    attack=16
    defense=12
    magic=7
Or even something more like this:
Code:
Alice  10   2   8
Bob    16  12   7
or
Code:
Alice: 10, 2, 8;
Bob: 16, 12, 7;
all of which would require some sort of parsing.
 

Hyomoto

Member
Generally speaking people do stat gains in RPGs one of three ways, either as a function:
Code:
strength = level * 2 + 1;
A static table look-up:
Code:
strength = strength_table[ level ]
Or point distribution (where you use points from a pool to adjust your stats). I point this out because the main reason to use a table is so you, as the developer, can hand tweak each level as you see fit. Generally, and especially if you have a lot of levels, people tend to build a function so they only have to tweak a calculation, rather than hundreds of levels in a table. Now, if you want the first level to grant +5 HP and then never again until level 11 when it goes up by +7, a table is more useful because coding a function like that could be headache inducing. A table might also be useful if you want to use some kind of derived calculation but, again, a function doesn't give quite the results you want:
Code:
derived_strength = strength_bonus[ strength ] + ( level / 2 );
In this case we find our derived strength score by looking up the bonus we'd get for base strength and adding it to another calculation. This would also allow you to tailor the table per-character, but still, this approach is a bit rarer. This is a bit off-topic, but I wanted to emphasize why you might choose to use a table in the first place. You might be going down an unnecessary rabbit hole for an effect you can achieve much more easily.
 
Last edited:
T

Taddio

Guest
I'm with @Hyomoto on this one, a formula seems WAY simpler than having an array row per player, per level, each with god knows how many columns with stats...and tweaking that? I wouldn't want to tackle it.

But say you have 3 classes of characters
each with str, def, dex, hp
You could probably go with only 12 formulas (3x12).
And when leveling up, you could get:
Code:
//When level up
barbarian.str += 1.5;
wizard.str += 0.5;
rogue.str += 0.75;

barbarian.dex += bla bla bla;
Wizard.dex += and so on;
And you could just change the values from simple numbers to formulas if you want to make it fancier (say you have a ring that gives +10% more dex on lvl up, or something like that).

Anyway, just throwing my 2 cents,
good luck with it, bro!
 
Last edited by a moderator:
Top