Here is a small lite-c test script that will send 0, 1, 2, 3, 4 in rapid succession on var a from client to server. The server event will print the received variable, and then waits untill the variable changes or 5 seconds have passed (without using wait() ofcourse).
I get the expected output:
0
5 second pause
timeout (means 5 seconds have passed)
1
5 second pause
timeout
2
5 second pause
timeout
..etc
Here is the code. Save as .c file and run with -sv, and another instance with -cl.
Code:
var a = 0;
STRING* s = "";
void serverEvent(void* addr, var id)
{
if(event_type == EVENT_VAR)
{
// store the received var and show it:
var b = *((var*)addr); // lite-c casting weirdness
str_for_num(s, b);
error(s);
// Wait untill var changes, or 5 seconds have passed:
timer();
double t = 0.0;
while(a == b && t < 5000000)
{
t += timer();
}
if(a != b){ error("oh no!");} // The loop terminated because a was update while the event was running
else { error("timeout");} // The loop terminated because 5 seconds have passed.
}
}
int main()
{
while(connection == 0) {wait(1);}
if(connection == 1) // server
{
on_server = serverEvent;
}
if(connection == 2) // client
{
// Send 0..4 on a:
var i = 0; for(i = 0; i < 5; i++)
{
a = i;
send_var(&a);
}
}
}