Gamestudio Links
Zorro Links
Newest Posts
Max Number of Strategies in /Strategy folder
by Martin_HH. 08/17/26 07:54
ZorroGPT
by OptimusPrime. 08/15/26 23:39
Pause button for evaluation shell?
by AndrewAMD. 08/13/26 17:16
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 08/10/26 12:46
phantom() not defined in indicators.c
by jcl. 08/07/26 11:45
Accepting new programming clients
by AndrewAMD. 08/06/26 21:25
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (Lapsa, kiamonster), 9,792 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Student_64151, Koti
19230 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