Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,561 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Variable scope within events [Re: fastlane69] #183786
02/18/08 10:38
02/18/08 10:38
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
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);
}
}
}



Re: Variable scope within events [Re: Excessus] #183787
02/18/08 22:58
02/18/08 22:58
Joined: Mar 2003
Posts: 5,377
USofA
fastlane69 Offline
Senior Expert
fastlane69  Offline
Senior Expert

Joined: Mar 2003
Posts: 5,377
USofA
Cool; question resolved!

I'm glad it's like that; makes a lot more sense for it to work the way you describe it(and actually is).

Page 2 of 2 1 2

Moderated by  HeelX, Spirit 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1