Simple timer function

I just need a simple timer function,

for example I need something to repeat every 5-10 minutes
or maybe after half an hour or 25 hours etc.

so now that glutTimerFunc is out of the picture

how can we do this without re-inventing the wheel?

or using something cheap like ofGetMinutes%5==0 or ofGetElapsedTimef()

Here is an example of what I need:

if(ofGetTimerAlarmIsTrue(“1:33:29”,39)){//FIRST VARIABLE IS CURRENT TIME THE ALARM WAS SET NOT TIME OF ALARM

cout<<“start something awesome”<<endl;

}

bool ofGetTimerAlarmIsTrue(string & begin time, int minutesInFuture){
return …
}

I tried a quick search in the addons but couldn’t find anything, I might be wrong though.

you can just store the current time and check in update if the time you are waiting for has passed already.

1 Like

Hi arturo, thank’s for the feedback
and
Sorry in advance for the whining… :slight_smile: :

here is the story:

I needed to setup a quick sketch I had in mind,

and I needed a way so that I was able to open the project, and set in-situ a timer-list of future events that would occur reliably on certain time maybe days in future and I was hoping to get when that time would be in human time (so I know the duration of time in minutes but not the time itself)

For example now it’s 11:45

I want to get what time would be 159 minutes in the future etc…
or 100324 minutes :smile:

or if you knew the day time get a timer to that

So What I really needed for that was smthng like a callendar class.

That you say getDayInFuture("24/1/16),135) and you get if is friday tuesday etc…

I only had a few hours so I didn’t want to risk a bug
so I wrote the simpliest thing I could came up with to be sure it will work assuming you only went minutes in the future for the timer not days or months or even hours :confused:

class shittyalarmTimer{
public:
textbox nextAlarmInput;//for inputing minutes until next timer
int nextAlarmTime=30;
int minutesleftforAlarm=30;

int resetTimer(int time){
nextAlarmTime = (ofGetMinutes()+time)%60;
getMinutesUntilAlarm(true);
return nextAlarmTime;
}
int getMinutesUntilAlarm(bool force=false){
if(ofGetFrameNum()%60==0||force){
int curminutes = ofGetMinutes();
if ((curminutes+minutesleftforAlarm%60) != nextAlarmTime) {
minutesleftforAlarm=0;
while ((curminutes+minutesleftforAlarm)%60!=nextAlarmTime) {
minutesleftforAlarm++;
}
nextAlarmInput.text = ofToString(minutesleftforAlarm);
}
}

    return minutesleftforalarm;
}
bool getIsAlarmTime(){
    return minutesleftforalarm==0;
}

string getTimeOfNextAlarm(int){
… if int - getCur minutes <0 then ++ one hour
then return bla bla bla so many bugs.
}

};

Yes I could write a class with a lot of If statements that would be able to do so , but I was short in time so I was
hoping if anybody had something ready already I am sure it has to be somewhere :slightly_smiling: I also didn’t have the luxury of debugging or affording the class i came up with to not work for whatever reason.
:slight_smile: anyway

again thank’s for the info, I am all set for now
fingers crossed the shittytimer class wont start counting forward instead of backwards in a month :slightly_smiling:

:beer: :beers: