How to run a piece of code once in a while

I was looking for a way to run a piece of code once in a while, and accidentally found the answer in a seemingly unrelated guide here: AFL Function Reference - SAY

To quote from that guide:

function SayNotTooOften( text, Minperiod )
   Lastelapsed = Nz( StaticVarGet("lastsaytime") );

  if( elapsed - Lastelapsed > Minperiod )
     StaticVarSet("lastsaytime", elapsed );
     Say( text );

Instead of Say(), another piece of code can be run once in a while using this method, which is what I need.
I started this topic so other users looking for the same solution could find it faster.
Thank you Tomasz for the great work!

1 Like

you are great
thank you