Passing variables through functions

I feel stupid for asking this but how come the following code doesn’t increase LevelsConfig.Agility, it only increases the local variable Level.
I want to do it this way because I have stats such as Agility, Endurance etc and I don’t want a function for each one saying IncreaseAgility, IncreaseEndurance etc.
How would I do this?


AStats* CharacterStats;


CharacterStats->IncreaseLevel(CharacterStats->LevelsConfig.Agility);


int32 AStats::IncreaseLevel(int32 Level)
{
	Level += 1;
return Level;
}

Alright well, when Agility goes in, it increases by 1 and then gets returned but it’s never assigned to anything.

int32 playerLevel = CharacterStats->IncreaseLevel(CharacterStats->LevelsConfig.Agility);

Not sure how the rest of your code works but don’t use the same variable names in case you’re trying to assign to another variable named Level elsewhere.

Thanks! So obvious as well.

Alternatively, pass your variable by reference:


int32 AStats::IncreaseLevel(int32& Level)
{
	Level += 1;
	return Level;
}

Then:


CharacterStats->IncreaseLevel(CharacterStats->LevelsConfig.Agility);
// Agility is now increased.

Return value is mostly pointless in this case since you’re modifying the parameter directly.