I have a code which has a start() function that executes every cycle. In it I call a pause() function here and there.
I now have to become more smart of the way I call the pause() depending on some conditions. And in some places it is executed on conditions that are not needed in other places.
I understand that I now have to create a separate function which will call the pause() function. But that is as far as i have gotten. It feels like a maze and I’m getting lost.
What is the best way to code this? How do the pros do it?
Update:
I’ve added my code. Basically I want my pauseActivator to do more than one action.
-
Act as condition tester and return true or false.
-
To actually call the pause function.
Maybe I shouldn’t make my function do this?
void doPause() {
//call system default pause function()
}
bool pauseOn = true;
string myPauseTime = "02:30";
bool pauseTimeReached = false;
bool pauseActivator() {
if(pauseOn && systemTime() == myPauseTime){
pauseTimeReached = true;
doPause();
}
return (pauseTimeReached);
}
int start() {
if(maxMovement > 500 && pauseActivator()) {
if(maxA() && secondMovement==600) {
pauseActivator();
}
}
return(0);
}
I would suggest you use DoPause for pausing and have a function to return the pause state. Having a test function with a “hidden” side-effect of actually pausing could cause problems down the line.