There's on built in way to do this right now because it is very easy for such a function to tank 4coder performance. Right now it is event driven so if you leave it sit for an hour it's CPU usage stays at 0. With a tick function, even if you don't do anything in your tick, 4coder has no way of knowing that your tick won't do anything big and so it is forced to do a full update as if something is going to happen, which is why I originally decided against a time type system.
However, this request has come up frequently enough that I am considering adding it and letting you manage the performance consequences yourself. In the mean time, I and another person who requested this have found a work around that makes it possible for you to whip up your own time events anyway, but you'll have to do some platform specific work to set it up:
1. Write a thread that will send your tick events:
| void tick_function(void *){
for (;;){
Sleep(10*1000); // Spread out my ticks to every 10 seconds
/SEND_EVENT_TO_MY_MAIN_THREAD/
}
}
|
2. Decide what key you will allocate for tick events, F16 is a good candidate, especially if your keyboard doesn't have that key. On windows this means:
| void tick_function(void *){
for (;;){
Sleep(10*1000); // Spread out my ticks to every 10 seconds
INPUT in = {0};
in.type = INPUT_KEYBOARD;
in. DUMMYUNIONNAME.ki = VK_F16;
SendInput(1, &in, sizeof(in));
}
}
|
3. Put your tick event in a custom command:
| CUSTOM_COMMAND_SIG(tick){
// whatever it is we want to do regularly
}
|
4. Bind your tick to the F16 key at the global level in the bindings:
| bind(context, key_f16, MDFR_NONE, tick);
|
5. Launch your thread in the startup hook.
It's obviously more plumbing than you'd like to have to do, and if you ever want different flavors of times/ticks this would all fall apart, but hopefully it's a good enough stop gap measure for you until I do an upgrade to the event handling API and add some timer abilities there.