• Advertisement
Sign in to follow this  

Basic leveling problem (I think)

This topic is 3442 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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;
}



Posting code

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]

Share this post


Link to post
Share on other sites
Thank you so much! It shows that I'm still a beginner I guess...Oh well. At least I'm a happy beginner!

Sincerely,
Annoyer

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement