setTimerEvent

Syntax

int setTimerEvent(int nr, int t, int state)

Arguments

nr
Timer number. Values from 0 to 9 are allowed.
t
Time in milliseconds. Determines how often a timer is triggered. For a value of 1000, the timer is triggered every second.
state
Set to 1 for activated and to 0 for deactivated.

Return

If the function fails to create a timer, the return value is zero, otherwise it is nonzero.

Description

Lets you activate or deactivate one of 10 available timers. When activated, the timer will trigger an (FME_TIMER)? event every t milliseconds until the timer is deactivated again. The possibilities are unlimited with this function. You can use it to e.g. program a stopwatch (see Example below), display a flicker-free animation, perform asynchronous and multi-threaded-like tasks, stop a running calculation after a certain time period.

Example

%ffp

ctl(0):statictext,size=(140,10)
ctl(1):statictext,size=(140,10)
ctl(3): pushbutton,Text="Start",size=(50,15)
ctl(5): pushbutton,Text="Stop",size=(50,15)

OnCtl(n): 
{
	int r;
	static int count0,count1;
	
	if (n==0 && e == FME_TIMER)  {

		count0++;
		setCtlTextv (1,"%d ms",count0*10);
		

	} else if (n==1 && e == FME_TIMER)  {

		count1++;
		setCtlTextv (0,"%d seconds",count1);		
		
	} else if (n==3 && e == FME_CLICKED){

		setCtlText (0,"");
		setTimerEvent(0,10,1);
		setTimerEvent(1,1000,1);

	} else if (n==5 && e == FME_CLICKED){

		count0=count1=0;
		setTimerEvent(0,0,0);
		setTimerEvent(1,0,0);
	}
	
	return true;
}

Also see

(FME_TIMER)?

Comments

Everyone can add his comments about his experiences with this function here. Tips for using it are welcome, too.