Ashasekayi (Talk | contribs) |
|||
Line 59: | Line 59: | ||
ball.OnMouseDown(onDown);}} | ball.OnMouseDown(onDown);}} | ||
+ | |||
+ | {{ScriptFunction|int|UnregisterBroadcastFunction|(string ns, string func, Closure reference);|Unregister Broadcast Function.|5= | ||
+ | ''-- Script A: Receiver''<br> | ||
+ | function someFunction(status)<br> | ||
+ | if status == "start"<br> | ||
+ | then Space.Log("Do receiver 1 procedures.")<br> | ||
+ | end<br> | ||
+ | end<br><br> | ||
+ | |||
+ | Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);<br><br> | ||
+ | |||
+ | |||
+ | ''-- Script B: Another Receiver''<br> | ||
+ | function someFunction(status)<br> | ||
+ | if status == "start"<br> | ||
+ | then Space.Log("Do receiver 2 procedures.")<br> | ||
+ | end<br> | ||
+ | end<br><br> | ||
+ | |||
+ | Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);<br><br> | ||
+ | |||
+ | |||
+ | ''--Script C: Sender''<br> | ||
+ | local ball = Space.Host.ExecutingObject;<br> | ||
+ | ball.SubscribeToEvents();<br><br> | ||
+ | |||
+ | function onDown()<br> | ||
+ | local queue = '''Space.Shared.CallBroadcastFunction'''("com.someNameHere.world", "func", {"start"});<br> | ||
+ | Space.Log("number in queue: " .. queue);<br> | ||
+ | Space.Shared.UnregisterBroadcastFunction("com.someNameHere.world", "func", someFunction);<br> | ||
+ | Space.Log("UnregisterBroadcastFunction");<br> | ||
+ | end<br><br> | ||
+ | |||
+ | |||
+ | ball.OnMouseDown(onDown);}} | ||
+ | |||
+ | {{ScriptFunction|int|UnregisterBroadcastFunction|(string ns, string func);|Unregister Broadcast Function.|5= | ||
+ | ''-- Script A: Receiver''<br> | ||
+ | function someFunction(status)<br> | ||
+ | if status == "start"<br> | ||
+ | then Space.Log("Do receiver 1 procedures.")<br> | ||
+ | end<br> | ||
+ | end<br><br> | ||
+ | |||
+ | Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);<br><br> | ||
+ | |||
+ | |||
+ | ''-- Script B: Another Receiver''<br> | ||
+ | function someFunction(status)<br> | ||
+ | if status == "start"<br> | ||
+ | then Space.Log("Do receiver 2 procedures.")<br> | ||
+ | end<br> | ||
+ | end<br><br> | ||
+ | |||
+ | Space.Shared.RegisterBroadcastFunction("com.someNameHere.world", "func", someFunction);<br><br> | ||
+ | |||
+ | |||
+ | ''--Script C: Sender''<br> | ||
+ | local ball = Space.Host.ExecutingObject;<br> | ||
+ | ball.SubscribeToEvents();<br><br> | ||
+ | |||
+ | function onDown()<br> | ||
+ | local queue = '''Space.Shared.CallBroadcastFunction'''("com.someNameHere.world", "func", {"start"});<br> | ||
+ | Space.Log("number in queue: " .. queue);<br> | ||
+ | Space.Shared.UnregisterBroadcastFunction("com.someNameHere.world", "func");<br> | ||
+ | Space.Log("UnregisterBroadcastFunction");<br> | ||
+ | end<br><br> | ||
+ | |||
+ | |||
+ | ball.OnMouseDown(onDown);}} | ||
+ | |||
+ | {{ScriptFunction|void|SetSuperGlobal|(string ns, string key, DynValue value);|Sets a Super global key to a value. The value can be any object type.|5= | ||
+ | Space.Shared.SetSuperGlobal("com.someNameHere.world", "version", "1.02");}} | ||
+ | |||
+ | {{ScriptFunction|DynValue|GetSuperGlobal|(string ns, string key);|Retrieves a previously set super global variable, or returns nil.|5= | ||
+ | local versionValue = Space.Shared.GetSuperGlobal("com.someNameHere.world", "version"); | ||
+ | }} | ||
{{Scripting Navbox}} | {{Scripting Navbox}} |
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
Unregister Broadcast Function.
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);
Space.Shared.UnregisterBroadcastFunction("com.someNameHere.world", "func", someFunction);
Space.Log("UnregisterBroadcastFunction");
end
Unregister Broadcast Function.
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);
Space.Shared.UnregisterBroadcastFunction("com.someNameHere.world", "func");
Space.Log("UnregisterBroadcastFunction");
end
Sets a Super global key to a value. The value can be any object type.
Retrieves a previously set super global variable, or returns nil.
|