   Assigning a variable an equasion
  Don't know how.Heres an example:I'm trying to make the first part of my "Totally newbish" engine, and I would like to know how to assign an unsigned short int by lvl.Lets say that the begining HP of my character is 253, I want to make the engine add 10 HP per lvl up, and the point its that the engine will ask for the lvl, and generate the results right afterwards.But I don't know how to assign a variable an equasion. Whats the command I'd type in?sliceanddicethe 10 hp per lvl up sucks, its just to get the hang of it, you'd only get.....   
#include <iostream>#include <string>using namespace std;int main(){    int php, chp, xp, cdmg, pdmg;    php = 253;    xp = 0;   srand(time(0));    int randomNumber = rand();    cdmg = (randomNumber % 20) + 1;    pdmg = (randomNUmber % 20) + 1;   php = php - cdmg;    chp = chp - pdmg;   if(cdmg <= 0)    {  xp + 10;    }}Just test that, might not work... didn't try it =P   ;  yeah but I don't want a random value, I want the default begining health set. Using random numbers on something like this could eventually give the player an unfair amount of HP.for ex you start at 500 hp, the the random number of hp generated is 564. (Or 1.)Having 1064 HP at the begining of a game seems alittle "unethnical".Really, when the characters are so cute doing as much damage as a paper cut would do to us, it would take ALOT of papercuts to kill the main character.(Cloud Strife comes to mind....)Pwning a SOLDIER with 25 HP and having 1064.....   ;  Create a charater class:class Character{public:unsigned int levelUp();unsigned int getHP();//other public meathodsprivate:unsigned int HP;unsigned int level;//other private variables}unsigned int Character::levelUp(){++level;return HP+=10;}Then to level up simmply call myCharacter.levelUp(), where myCharacter is a Character type. Use the return value or getHP() to get the HP for calculations.EDIT:To set the starting health, create a constructor for character like this:class Character{public:Character(unsigned int startingHP=253);unsigned int levelUp();unsigned int getHP();//other public meathodsprivate:unsigned int HP;unsigned int level;//other private variables}Character::Character(unsigned int startingHP):HP(startingHP){}Notice how the if no value is passed to the constructor, the HP is initialized to 253. Otherwise it is initialized to whatever value is passed.Edit 2:Here is an example of the object in use:#include <iostream>using namespace std;main(){Character bob(300), jill;cout<<"Bob's HP is "<<bob.getHP()<<endl;cout<<"Jill's HP is "<<jill.getHP()<<endl;bob.levelUp;cout<<"Bob gained a level. Bob's new HP is "<<bob.getHP()<<endl;} [Edited by - King Mir on July 23, 2006 12:39:57 AM];Quote:Original post by sliceanddiceyeah but I don't want a random value, I want the default begining health set. Using random numbers on something like this could eventually give the player an unfair amount of HP.for ex you start at 500 hp, the the random number of hp generated is 564. (Or 1.)Having 1064 HP at the begining of a game seems alittle "unethnical".Really, when the characters are so cute doing as much damage as a paper cut would do to us, it would take ALOT of papercuts to kill the main character.(Cloud Strife comes to mind....)Pwning a SOLDIER with 25 HP and having 1064.....I created a random number generator for your damage dealt, just for a quick test for you :P look at the variables lol   ;You will need to learn to do this stuff yourself eventually.....Every level above the first one you will add 10HP (or some number depending on class....)You will have to determine when a new level is reached....assume level starts at 1 and first addition of HP happens at level 2when you hit a new level : HP_Max = Start_HP + (Level - 1) * HP_PerLevelNote- even if you level up you have to retain any existing damage   so you will have to add the additional HP to the  Current_HP;  Yeah, my class had only one HP variable per character, not a current HP and a max HP. But you can figure out how to differentiate.Don't do what nooblet did, because then you have to keep track of alot of individual variables. Instead use classes so that you can group variables related to a single character together and deal with the character as a single object. And it makes it really easy to add more characters.   ;  Well then I'd just make the HP fill up with the addition of the new added hp per lvl up. I guess that's traditional, not to mention relieving.I will obviously be using an experience bar.   