Hi, I'm working on creating my first game to sharpen my programing skills and as a great learning experience for programming in general.
I'm using private ints for the stats and was working on get and set methods for retrieving them and changing them and I was wondering if anyone could tell me how to go about this without having to create a if statement for each variable in the class (since there are many)

Condensed version of code for example:
class Character
private int str;
private int HP;
private int spd;

public int getStat(String stat)
//here is where I want to return the value of the
//variable above with the matching name to stat

public int setStat(String stat, int x)
//here is where I want to change the variable above
//with the matching name of stat to x

How would I go about it?

9 Years
Discussion Span
Last Post by JamesCherrill

yeah, that was a small example, I actually have around 70 stats right now, with plans for more.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.