# I'm very beginner. i want to make game playing time

hi i want to know about make timer for timelapse.
first, what i want to know is using ofGetElasedTimeMillis
or any time controler to control mygame’s playing time to set 60seconds.
second,in this 60 seconds some events(like blink) occur 10 times in random seconds…
// 38sec blink … 10 times

//what should i do first… ?

For 10 blinks every 60 seconds => 1 blink every 6 seconds- you could just do a simple if else like this :

int time = (int) ofGetTimeElapsedf(); // The type casting is because the function returns a float value (seconds) and you can only use modulus operator on integer types.

This is pretty easy and might even be a bit obvious, but its a start I guess.

To add randomness and achieve something like “Blink x times every y seconds” is actually an interesting question. Would have to think about that a bit…

Best.

Update us if you find the solution and so will I if it strikes me

I’ve done something similar like this in this fashion. This is coming from some Arduino code reference (blink without delay).

In .h file setup the following:

``````long unsigned currentMillis;
long unsigned previousMillis;
long unsigned interval;
``````

In setup(), setup the following stuff.

``````currentMillis = 0;
previousMillis = 0;
interval = 1000; //this is 1000 milliseconds = 1 second
``````

In update() do this.

``````long unsigned currentMillis = ofGetElapsedTimeMillis();

if(currentMillis - previousMillis >= interval){
//do stuff here;
previousMillis = currentMillis; //reset the previousMillis value here to currentMillis so that in the loop next time it triggers again.
}
``````

setup multiple intervals and multiple previousMillis counters if you want to do stuff at different intervals.

1 Like

If you want to have the triggers at random times, throw in

`interval = ofRandom(maxValue);`

where you’re resetting the previousMillis counter.

You could also make an array for example:

and then fill this array with 10 random numbers from 1 - 60 every minute.

if((int)ofGetElapsedTimef()%60==0)
{
for(int i=0; i<9;i++)
{
x=ofRandom(60);
//You will have to insert some code here to make sure x values are not repeated.
}
}

then use the numbers in this array as the interval time that you want to see a blink.

currentSeconds = ofGetElapsedTimef();
for(int i=0; i<9;i++)
{
if (currentSeconds=time[i])
{