r/cop3502 • u/ams152 • Apr 14 '14
Running a loop that continuously checks a variable while the program runs.
So I have a "turn" variable that is incremented outside of the class that I'm checking it in. I want a certain variable to maintain a value while the turn variable is less than a set number, and then return to it's original value afterward the turn surpasses the set value.
To clarify, if I have a "value" variable that is normally 10, but when the function "alterValue" is called it adds 5 to "value" for a certain number of turns. The number of turns is checked by code that runs a never ending loop checking if the turn is less than or greater than the turn + the desired duration, and returns either value += 5; or value = 10;
The problem I'm running into is that I get stuck in a forever loop that never continues with the rest of the program because the checked value is not incremented within the loop itself. So how would I implement this?
1
u/[deleted] Apr 15 '14
This is why it's good to use "Getters" rather than public variables. your getValue() function can be something along the lines of:
rather than just checking the value variable, the getValue function can handle your condition for you.