wiki.sine.space | sinespace

Difference between revisions of "Scripting/SHost"

From wiki.sine.space
Jump to: navigation, search
(Replaced content with "This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/shost")
 
Line 1: Line 1:
The SHost class represents the scripting runtime.
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/shost
 
+
==Members==
+
{{ScriptFunction|void|InvokeEvent|(string name);|Invokes a UnityEvent attached to the Scripting Runtime component this script is executing in.|
+
function InvokeExample()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log("Invoke Event");<br>
+
end<br>
+
''--Attach the upon function to Scripting Runtime/Unity Interfaces/Events,Named "InvokeExample.''<br><br>
+
Space.Host.InvokeEvent("InvokeExample");<br>
+
''--Print "Invoke Event" to the console.''
+
}}
+
 
+
{{ScriptFunction|void|Stop|();|Pauses the current script until it is manually restarted, at the end of the current function/method; consider using return as well.|5=
+
local trans=Space.Host.ExecutingObject;<br>
+
trans.SubscribeToEvents();<br><br>
+
function Running()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log("Running")<br>
+
end<br><br>
+
trans.OnUpdate(Running)<br><br>
+
Space.Host.InvokeDelayed(function()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log("Stop")<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Host.Stop()<br>
+
end,5)<br><br>
+
''--After print the "Stop","Running" won't display anymore.''
+
}}
+
 
+
{{ScriptFunction|SGameObject|ExecutingObject|{ get; }|Returns the SGameObject this script is attached to.|5=
+
local obj=Space.Host.ExecutingObject;<br>
+
Space.Log(obj.Name);<br>
+
''--Print object name to the console.''
+
}}
+
 
+
{{ScriptFunction|string|Language|{ get; }|Returns the English name for the users language, e.g. 'English', 'French', 'Chinese'|
+
Space.Log(Space.Host.Language);<br>
+
''--Print current system language in English.''|6=<pre>--Makes a UIText show a different message according to the client's language
+
TextObject = Space.Host.GetReference("TextObject") --add to references section of Scripting Runtime component
+
 
+
language = Space.Host.Language
+
 
+
 
+
if language == "English" then
+
  TextObject.UIText.Text = "Welcome!"
+
elseif language == "Dutch" then
+
  TextObject.UIText.Text = "welkom!"
+
elseif language == "French" then
+
  TextObject.UIText.Text = "bienvenue!"
+
else
+
  TextObject.UIText.Text = "Welcome!"
+
end</pre>
+
}}
+
 
+
{{ScriptFunction|void|StartCoroutine|(DynValue func);|Executes the specified function as a coroutine.|
+
local function myCoroutine()
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;-- The yield statement is a special kind of return, that ensures that the function will continue from the line once the coroutine resumes.
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;-- Placing a float value inside of the yield will result in a delayed execution.
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;-- Example: coroutine.yield(0.5) will wait 0.5 seconds before continuing the execution of the coroutine.
+
<br>
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;-- This will print the current players active time.
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(Space.Time);
+
<br>
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;-- Execution of this coroutine will be halted for 10 seconds.
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;coroutine.yield(10);
+
<br>
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;-- This will print the current players active time, which will be 10 seconds greater then the previous as a result of the yield
+
<br>&nbsp;&nbsp;&nbsp;&nbsp;Space.Log(Space.Time);
+
<br>end
+
<br>
+
<br>Space.Host.StartCoroutine(myCoroutine);
+
<br>
+
}}
+
 
+
{{ScriptFunction|void|InvokeDelayed|(Closure c, float delay)|Invoke the closure after the delayed time.|5=<pre>Space.Host.InvokeDelayed(AFunction, 10)</pre>|6=<pre>--Clicking this object makes it destroy itself after 5 seconds
+
thisObject = Space.Host.ExecutingObject
+
 
+
 
+
function DeleteFunction()
+
  thisObject.Destroy()
+
end
+
 
+
 
+
function OnClickFunction()
+
  Space.Host.InvokeDelayed(DeleteFunction,10)
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClickFunction)</pre>
+
}}
+
 
+
{{ScriptFunction|bool|ReferenceExists|(string name)|Return true when the reference object exists and is not empty.|
+
Space.Log(Space.Host.ReferenceExists("obj"));<br>
+
''--Print "false" to console if didn't set the object named "obj" to the Object Reference.''
+
}}
+
 
+
{{ScriptFunction|bool|ReferenceExistsAndNotEmpty|(string name)|Return true when the reference object exists and is not empty.|
+
Space.Log(Space.Host.ReferenceExistsAndNotEmpty("obj"));<br>
+
''--Print "false" to console if didn't set the object named "obj" to the Object References or attach the reference to "obj".''
+
}}
+
 
+
{{ScriptFunction|SGameObject|GetReference|(string name)|Pulls a reference from the scripting runtime component's "References" section by it's name.|5=<pre>theObject = Space.Host.GetReference("referenceName")</pre>|6=<pre>--Clicking this object makes it destroy the object we linked in the references section
+
thisObject = Space.Host.ExecutingObject
+
dObject = Space.Host.GetReference("theObjectToBeDestroyed")
+
 
+
 
+
function OnClickFunction()
+
dObject.Destroy()
+
end
+
 
+
 
+
thisObject.AddClickable()
+
thisObject.Clickable.OnClick(OnClickFunction)</pre>
+
}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 07:21, 19 September 2022

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