Basic leveling problem (I think)
Anyway, its been a while since I've done any game programming and, returning to a basic C++ game I started about 6 months ago, I decided to make a more sophisticated leveling system besides level*150. So... here is my code for a fishing level up (notice I commented many lines out):
int fishinglvlup(){
double fishexpneeded = 100;
/* if (fishingexp >= 100 && fishinglvl <= 2){
// remeber it was 0 | fishingexp = fishingexp;
fishinglvl++;
fishexpneeded = 210;
cout<<"You're fishing level is now "<< fishinglvl <<"\nYou have "<< fishingexp <<" fishing experience!";
cin.get();
}*/
/*else if */if(/*fishinglvl >= 2 && */fishingexp >= fishexpneeded){
fishinglvl++;
fishexpneeded = fishexpneeded*2.1;
cout<<"You're fishing level is now "<< fishinglvl <<"\nYou have "<< fishingexp <<" fishing experience!\n You need "<< fishexpneeded <<" to advance!\n";
cin.get();
}
return 0;
}
So when i run this, I go and fish (fish are set at 50 experience each for testing purposes) until i go up a level. Obviously my idea here is to change the experience to 2.1 times the experience needed to get to the last level. So I get to level 2.
You catch a fish!
You're fishing level is now 2!
You have 100 experience!
You need 210 experience to advance!
Maybe too many exclamations, but that is beside the point. So I fish another fish and lo and behold, I'm magically level 3 with 150 exp and 210 experience to advance!
Any ideas as to what I am doing wrong here? I left the commented stuff in case it's helpful in some odd way....
Sincerely,
Annoyer
int fishinglvlup(){ static double fishexpneeded = 100; /* if (fishingexp >= 100 && fishinglvl <= 2){ // remeber it was 0 | fishingexp = fishingexp; fishinglvl++; fishexpneeded = 210; cout<<"You're fishing level is now "<< fishinglvl <<"\nYou have "<< fishingexp <<" fishing experience!"; cin.get(); }*/ /*else if */ if ( /*fishinglvl >= 2 && */fishingexp >= fishexpneeded ) { fishinglvl++; fishexpneeded = fishexpneeded*2.1; cout<<"You're fishing level is now "<< fishinglvl <<"\nYou have "<< fishingexp <<" fishing experience!\n You need "<< fishexpneeded <<" to advance!\n"; cin.get(); } return 0;}
Change
double fishexpneeded = 100;
to
static double fishexpneeded = 100;
With your current version, fishexpneeded gets reset to 100 every time you enter the function. However, quipping a static keyword on fishexpneeded, only initializes it to 100 once.
EDIT:
Fixed link.
[Edited by - _fastcall on September 15, 2008 10:07:10 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement