Ashasekayi (Talk | contribs) |
Ashasekayi (Talk | contribs) |
||
Line 27: | Line 27: | ||
− | {{ScriptFunction|int|CallBroadcastFunction|((string ns, string func, IEnumerable< DynValue > args);|Calls every registered broadcast function with the specified arguments, | + | {{ScriptFunction|int|CallBroadcastFunction|((string ns, string func, IEnumerable< DynValue > args);|Calls every registered broadcast function with the specified arguments, and returns the number of calls queued.|5= |
− | + | ||
− | and returns the number of calls queued.|5= | + | |
''-- Script A: Receiver''<br> | ''-- Script A: Receiver''<br> | ||
function someFunction(status)<br> | function someFunction(status)<br> |
The SShared class provides IPC methods that allow scripts to communicate with each other and objects to be passed between scripts. Variables are shared between scripts, so a namespace is required. This class does not replace Scripting/SNetwork.
Sets a global key to a value. The value can be any object type.
Retrieves a previously set global variable, or returns nil.
Makes func into a global function that can be accessed anywhere.
Space.Log("Hello " .. name);
end
Calls the registered function with the specified arguments.
Makes func into a global function that can be accessed anywhere.
Space.Log("Hello " .. name);
end
Calls every registered broadcast function with the specified arguments, and returns the number of calls queued.
function someFunction(status)
if status == "start"
then Space.Log("Do receiver 1 procedures.")
end
end
Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);
-- Script B: Another Receiver
function someFunction(status)
if status == "start"
then Space.Log("Do receiver 2 procedures.")
end
end
Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);
--Script C: Sender
local ball = Space.Host.ExecutingObject;
ball.SubscribeToEvents();
function onDown()
local queue = Space.Shared.CallBroadcastFunction("com.someNameHere.world", "func", {"start"});
Space.Log("number in queue: " .. queue);
end
|