wiki.sine.space | sinespace

Difference between revisions of "Scripting/SNetwork"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/network/snetwork")
 
(30 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The SNetwork class allows you to send messages to other users in the region, and persist/retrieve variables which have been stored within the region.
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/network/snetwork
 
+
==Members==
+
{{ScriptFunction|void|SendNetworkMessage|(string key, IDictionary<object,object>);|Sends a networked message to every client with a subscriber listening on 'key'. The message itself can be a dictionary/table containing two columns and any network serializable type (string, float, int, byte, bool and arrays of those types)<br><br>
+
This is a modified version of the example for *.Renderer.Material.SetTexture that demonstrates networking.<br><br>note that this example applies also to SubscribeToNetwork.|5 = image = "mrlee.jpg"
+
server = "https://middleware.systems/"<br>
+
obj = Space.Host.GetReference("Gino")
+
 
+
Space.Network.SubscribeToNetwork("smack", onSmack)
+
 
+
function hithere()
+
  resrc = Space.WebServices.GetImage(server .. image)
+
  obj.Renderer.Material.SetTexture("_MainTex", resrc)
+
  Space.Network.SendNetworkMessage("smack",{'smack'})
+
end
+
 
+
function update()
+
  resrc = Space.WebServices.GetImage(server .. "mrlee.jpg")
+
  obj.Renderer.Material.SetTexture("_MainTex", resrc)
+
end
+
 
+
function onSmack()
+
  update()
+
end}}
+
{{ScriptFunction|void|SetShardProperty|(string key, string value);|Sets a property named 'key' of the region to 'value'. Will persist until the region is shut down or restarted. (Use SPersistence for longer term storage)|5=local scriptedObject = Space.Host.ExecutingObject;<br>scriptedObject.SubscribeToEvents();<br><br>local testMsg = "Hello";<br>local updateTextUI = function()<br>&nbsp;Space.Network.SetShardProperty("testKey", testMsg);<br>end<br><br>scriptedObject.OnMouseDown(updateTextUI);<br><br>-- Once this object is clicked, it will create a shard property with the key "testKey" and give it the value of "Hello".}}
+
 
+
{{ScriptFunction|string|GetShardProperty|(string key);|Gets a previously set key.|5=local scriptedObject = Space.Host.ExecutingObject;<br>scriptedObject.SubscribeToEvents();<br><br>local textValue = Space.Host.GetReference("Text");<br>local retrieved;<br><br>local updateTextUI = function()<br>&nbsp;retrieved = Space.Network.GetShardProperty("testKey");<br>end<br><br>-- this method is called every frame, once "retrieved" gets a value, it displays in text<br>local onUpdateMethod = function()<br>&nbsp;updateTextUI();<br>&nbsp;if retrieved ~= nil then <br>&nbsp;&nbsp;textValue.UIText.Text = "Retrieved msg: " .. retrieved ;<br>&nbsp;end<br>end<br><br>scriptedObject.OnUpdate(onUpdateMethod);<br><br>-- "Text" used with GetReference is a UItext canvas object used to display the test text inworld. After you add UI > Text to your scene, drag the text object to the Object References section in your script.}}
+
{{ScriptFunction|void|SubscribeToNetwork|(string key, Action<SNetworkMessage> callback);|Subscribes to network messages on 'key', will fire a [[Scripting/SNetworkMessage]] whenever a matching message is received}}
+
 
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 07:01, 19 September 2022

This page has moved to: https://docs.sine.space/v/scripting/client-scripting/network/snetwork