QuestionWould love some help ...

Posts 1–2 of 2 · Page 1 of 1
Would love some help ...
Well where do i start, a couple of months ago i was making a little school project that i'd love to continue but i got a lilbit confused with my own code

this is supposed to be a leveling system that now im not being able to understand mainly cuz my variable names:



void Leveling(){

int PLvL;
int xpm;
int xp_mp;
double LvL_D;

xp_mp = P.xpmp;
PLvL = P.Level;
xpm = P.xp;

if(xp_mp == 0){
cout<<"FIRST TIME ADQUIRING XP!"<<endl;
xp_mp = PLvL * 1000;
getch();
}
LvL_D = xpm / xp_mp;
if(LvL_D >= 1){
PLvL++;
xpm = xpm - xp_mp;

P.Level = PLvL;
P.xp = xpm;
xp_mp += 1000;
P.xpmp = xp_mp;
P.health_max += 40;
cout<<"[|*|]>LEVEL UP!<[|*|]"<<endl;
cout<<"[|*|]>MAX HEALTH + 40P!<[|*|]"<<endl;
cout<<"[>>NEW LEVEL: "<<P.Level<<"<<]"<<endl;
save();
getch();

}

}

All i know is that PLvL stands for Player level, either xpm or xp_mp is XP multiplier and the other is the actual xp andi have no clue what LvL_D is.
There's also a class named player that contains the actual xp and level thats why there is P.Level p.xp and p.xpmp.

This is actually confusing, i should make it from scratch...
When you are naming variables keep couple notes in mind:
1. Only final variables should be in CAPS
2. You start with capital letters only if its a class name
3. You can either use cammelCase or underscore naming: myVar or this: my_var
4. Your variables should have names that are self explanatory example: player_level , xp_counter
5. Avoid using acronyms it recudes readability
6. Have consistency for example if you do this:

if (expression){
// code
}

Keep it do not change it to this:

if (expression)
{
// code
}

and visa versa ofc keep one coding style its easier to from someone to read it.


For more you could read here: https://hackernoon.com/few-simple-ru...e-96cb29d4acd9
https://en.wikipedia.org/wiki/Naming..._(programming)
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us