x


storing character stats

Im not sure how many of you have played final fantasy, but you have a team of up to 4 players, each of different stats.

I'm trying to achieve something similar.

Strength, Defense, Vitality etc so each player has its own individual stats.

Would it be best to store this all in one c# script, with a custom class holding these variables then have a list of these classes? Im not sure on what the best way to go about doing this would be.

Examples or a nudge in the right direction wouldn't go a miss, thanks in advance!

more ▼

asked Jul 13 '11 at 09:11 PM

CarlLawl gravatar image

CarlLawl
424 20 24 33

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

In my rpg, I have a Creature class which has INT, STR, etc. variables, each of type Stat. I also have an array of those same objects to simplify bulk processing, and an enum that corresponds to the array positions for nice presentation in inspector variables. The player and every monster is an instance of Creature.

Having a Stat class allows me to store buffs etc. while still having the base stat values available. I also use it to encapsulate stat change messages as well as generating floating visual +1s.

But there is no "right" way. You might just have:

var INT : int;
var STR : int;
...

In you Player class. Indeed, I think that's what I started with. It's better to write simple, maintainable, evolvable code and refactor as-needed rather than to start with something that may be unnecessarily complicated.

more ▼

answered Jul 13 '11 at 09:34 PM

Waz gravatar image

Waz
6.4k 22 33 71

ok a step in the most efficient direction*

example of what im trying to achieve

team:

player 1:
str - 1
def - 3
int - 2

player 2:
str - 2
def - 3
int - 2

player 3:
str - 2
def - 1
int - 1

player 4:
str - 3
def - 2
int - 3

would this best be stored in 1 script? and saved in playerprefs?

Jul 13 '11 at 09:41 PM CarlLawl

I would suggest that you at least have a "Character" script with the stats, and 4 instances of that script in your 4 characters.

Jul 13 '11 at 09:45 PM Waz

Storage or serialisation of your game is a whole other question, but yes, PlayerPrefs is fine - that's what I use.

Jul 13 '11 at 09:46 PM Waz

but the thing is, each player wont always have its own GameObject, only in a battle will the other players be intantiated!

Jul 13 '11 at 10:01 PM CarlLawl

Create an independent, persistent game manager and stick all your stat data in it.

Jul 13 '11 at 10:04 PM Chris D
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x804
x23
x9

asked: Jul 13 '11 at 09:11 PM

Seen: 1176 times

Last Updated: Jul 13 '11 at 10:04 PM