I need some help. Here is my problem. I give a variable a number, and then a bunch of other variables that include the first variable.
Well what gets me frustrated is that when I change the first variable later on, using something like 'Variable1++;' or 'Variable1=50;' the rest of the numbers don't change along with it.
I know this because I printed it out on the screen before and after changing the variable to another number.
Also this is more of a skill level for something like a RPG game. I'd like to know how to do it, and if there is an easier way to do it.
Why did you expect that changing the variable enemylevel would cause playerhp and enemyhp to change?
Each variable is a location in memory. So
int playerlevel = 1;
stores the value 1 in the location where the int playerlevel is located.
int enemylevel = playerlevel;
reads the value out of the memory where int playerlevel is located and then stores it in the memory location for enemylevel.
The two variables now have the same value, but they are stored in totally different locations in memory. So changing one location will not change the other.
If I understand your problem correctly, that you want to be able to change (only) playerlevel and have the other variables track the changes according to some fixed rules, then the C++ way would be a class.
It's because you're not recomputing their values.
If you want their value to depend on playerlevel, you must recompute them each time playerlevel changes or each time you read them.
Thanks guys, especially you toum. That really helped me out. And most of my variables will be a global variable to make things simple. Unless I think differently later on.