have received a obstacle when I have worked with my game. When i have over 10 reps I can buy a item and it will cost me 10 reps. The problem is when if i get over 20 reps and buy the item it will take away 20 reps but actually it should only cost 10?!.
this is the code Underneath
1 2 3 4 5 6 7 8 9 10
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (this->score->reps >= 10)
{
this->stats->Strength += 1;
this->score->reps -= 10;
}
}
If you run this code each time the game is updated you need to release the button very fast otherwise it will run multiple times and repeatedly buy the same item until you run out of money.
The isButtonPressed function is good if you want to know if a button is currently being held down, but if you want to carry out some action, once, when the button is pressed you better use events.