Idle and sub-idle for an applet

I have an applet that cycle/idle every 1 second.
I would like now to add a new line code to be executed every 30 seconds.
For this, I could set up a variable (x) which increases its value every 1-sec idle by using x=x+1 and check in every 1-sec idle cycle:

if x > 29 then 
do something here -- execute the new line code
set x to = 0 -- reset the count for a fresh start
end

Is there any better/efficient way to achieve this?

Thanks Luciano

This works, tested.


global x

on run
	set x to 0
end run

on idle
	set x to x + 1
	if x > 29 then
		-- execute the new line code. For example:
		display notification "Another 30 seconds passed."
		set x to 0 -- reset the count for a fresh start
	end if
	return 1
end idle

You can check using (current date) instead of counter x, but I think the method above is more efficient.