This example takes 1 script (A) and it starts another script (B) then sends events to it. Script B reports if it got an event or if it did not.
You can send anything in an event - a mobile reference, item reference, error, struct, dictionary, integer, etc. and it will be received that way.
A.src
Code: Select all
use uo;
use os;
use util;
program SomeScript()
var script := Start_Script(":packagename:B");
if ( script.errortext )
print("Error starting B ->"+script.errortext);
return 0;
endif
Print("MyPId="+GetPid());
Print("Sending events to script with PId: "+script.pid);
while ( 1 )
var time := StrFormatTime("%H:%M:%S", POLCore().systime);
SysLog(time+" - Sending Tick.");
script.SendEvent("Tick!");
Sleep(RandomInt(20)+1);
endwhile
return 1;
endprogram
Code: Select all
use uo;
use os;
use util;
program EventCatcher()
while ( 1 )
// Wait up to 5 seconds for an event
var event := Wait_For_Event(5);
var time := StrFormatTime("%H:%M:%S", POLCore().systime);
if ( event )
SysLog(time+" - Received Event. Value = "+event);
else
SysLog(time+" - No event received.");
endif
endwhile
return 1;
endprogram
Code: Select all
MyPId=20430
Sending events to script with PId: 20431
syslog [pkg/commands/test/A.ecl]: 18:37:49 - Sending Tick.
syslog [pkg/commands/B.ecl]: 18:37:49 - Received Event. Value = Tick!
syslog [pkg/commands/B.ecl]: 18:37:54 - No event received.
syslog [pkg/commands/B.ecl]: 18:37:59 - No event received.
syslog [pkg/commands/test/A.ecl]: 18:38:04 - Sending Tick.
syslog [pkg/commands/B.ecl]: 18:38:04 - Received Event. Value = Tick!
syslog [pkg/commands/test/A.ecl]: 18:38:08 - Sending Tick.
syslog [pkg/commands/B.ecl]: 18:38:08 - Received Event. Value = Tick!
syslog [pkg/commands/B.ecl]: 18:38:13 - No event received.
syslog [pkg/commands/B.ecl]: 18:38:18 - No event received.
syslog [pkg/commands/B.ecl]: 18:38:23 - No event received.