exp is a local variable which is destroyed when function finishes. What it actually does:
1) assigns passed value (in your case experience) to exp
2) Does some manipulations with exp
3) Discards exp.
So your manipulations are not visible outside.
Also return exp,lvl; line is equal to return lvl;. Do not use comma operator unless you know how it works.
It works well because you do not expect outside values to change after your function finishes.
FOr example your hp, enemy_hp and battle_win_lose members are never changed, it is just you never used them in context where it would be noticeable
bool Menu::battleCommand(char battle_command,int hp_battle ,int battle_enemy_hp,bool win_lose_func)
how about the bool win_lose_func which is a local variable too and it does changing and still works well...
It is always true. You never see lose message, do you?
i have tried to lose it but still same behavior
To fix your function, just drop input parameters and manipulate members directly:
i see thats how it is. its because in my code when i call the function and when the function is exiting the variables from that function will be destroyed even it is passed.
void Menu::battle()
{
/*...*/
battle_win_lose = battleCommand(choose, hp, enemy_hp);
if(battle_win_lose == true)
//...
}
bool Menu::battleCommand(char battle_command, int hp_battle , int battle_enemy_hp)
//Parameters are not actually used, but I left them for now
{
/*...*/
//if(hp_battle <= 0) { win_lose_func=false; }
//...return (hp_battle > 0)
}