wiki.sine.space | sinespace

Difference between revisions of "Scripting/SScript"

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/sscript")
 
Line 1: Line 1:
The 'Space' global accessible in every script (for C# scripts, this inherits from the [[Scripting/SpaceScript|SpaceScript]] base class)
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/sscript
 
+
==Attributes==
+
 
+
{{ScriptFunction|SInventory|Inventory|{ get; }|Allows access to the users inventory|5=<pre>Space.Inventory.Authorize()</pre>}}
+
 
+
{{ScriptFunction|SPersistence|Persistence|{ get; }|Stores information between user sessions, and for other users|5=<pre>Space.Persistence.RetrieveValue("value1")</pre>}}
+
 
+
{{ScriptFunction|SScene|Scene|{ get; }|Allows access to the current scene graph (objects and avatars in the scene, and other information)|5=<pre>Space.Scene.PlayerAvatar</pre>}}
+
 
+
{{ScriptFunction|SHost|Host|{ get; }|Access information about the current scripting runtime host|5=<pre>Space.Host.StartCoroutine(CoFunc)</pre>}}
+
 
+
{{ScriptFunction|SPhysics|Physics|{ get; }|Call physics-related commands, and variables, such as raycasting|5=<pre>Space.Physics.RayCast(trans.WorldPosition,trans.Forward,50)</pre>}}
+
 
+
{{ScriptFunction|SMath|Math|{ get; }|Math related functions (Sin, Cos, Tan, etc)|5=<pre>Space.Math.Ceil(4.0)</pre>}}
+
 
+
{{ScriptFunction|SString|String|{ get; }|Miscellaneous additional string functions (e.g. MD5Sum)|5=<pre>Space.String.GetBytes("some data")</pre>}}
+
 
+
{{ScriptFunction|SInput|Input|{ get; }|Input device related functions (mouse position, keyboard state)|5=<pre>Space.Input.Vibrate(1,1,false)</pre>}}
+
 
+
{{ScriptFunction|SCameraManager|CameraManager|{ get; }|Take and control the users camera|5=<pre>obj = Space.Host.ExecutingObject
+
Space.Camera.LockCamera (obj)</pre>}}
+
 
+
{{ScriptFunction|SWebService|WebServices|{ get; }|Call remote web services to designated hosts (will not work with arbitrary domains, see page for details)|5=<pre>Space.WebServices.GetImage("example.com/mrlee.jpg")</pre>}}
+
 
+
{{ScriptFunction|SNetwork|Network|{ get; }|Send data to other clients through the region server|5=<pre>Space.Network.SubscribeToNetwork("helloworld", gotAMessageFunction)</pre>}}
+
 
+
 
+
=Members=
+
{{ScriptFunction|SResource|GetResource|{string name;}|Returns a resource with its name.|Space.Log(Space.GetResource("Texture").Name)<br>
+
''--Print "Texture" when it is exists.''
+
}}
+
 
+
{{ScriptFunction|void|Log|{DynValue text;}|Log a message to console.|Space.Log("Log")<br>
+
Space.Log("Log",true)
+
}}
+
 
+
{{ScriptFunction|string|TypeName|{DynValue dv }|Return the type name of the value.|Space.Log(Space.TypeName("123"))
+
}}
+
 
+
=Properties=
+
 
+
{{ScriptFunction|string|RuntimeType|{get; }|Return current RuntimeType name.|Space.Log(Space.RuntimeType)
+
}}
+
 
+
{{ScriptFunction|string|Platform|{get; }|Return current platform name.|Space.Log(Space.Platform)
+
}}
+
 
+
 
+
 
+
{{ScriptFunction|string|SessionID|{get; }|Return current SessionID.|Space.Log(Space.SessionID)
+
}}
+
 
+
{{ScriptFunction|bool|TrackingAllowed|{string key;}|Always return false on the main grid.|Space.Log(Space.TrackingAllowed("YourKey"))
+
}}
+
 
+
{{ScriptFunction|bool|InEditor|[get;]|Return true if in unity editor.|Space.Log(Space.InEditor)|6=<pre>--the below script checks if we are in Unity editor or in SS
+
--this way we can provide an alternative
+
--(Example: if we're using a function that doesn't work in Unity editor)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
 
+
if Space.InEditor then
+
avatarUsername = "Player Name"
+
else
+
avatarUsername = Space.Scene.GetAvatar(thisGameObject.Owner).Username --example: this doesn't work in Editor
+
end
+
 
+
Space.Log(avatarUsername)</pre>
+
}}
+
 
+
{{ScriptFunction|SResource|Resources|[get;]|Return all resources.|Space.Log(#Space.Resources)
+
|6=<pre>--the below script will search through the Scripting Runtime's resources
+
--and return the first instance of an Animation Clip
+
--[You need to add a few resources to the scripting runtime and make one of them an animation]
+
 
+
 
+
resources = Space.Resources
+
 
+
for i = 1, #resources do
+
if resources[i].Type == "AnimationClip" then
+
  Space.Log("Resource #".. i .. " is an Animation Clip. The resource name is: " .. resources[i].Name)
+
  break
+
end
+
  end</pre>}}
+
 
+
{{ScriptFunction|float|Time|[get;]|Returns time at the beginning of this frame.|5=<pre>Space.Log(Space.Time)</pre>|6=<pre>--this script will update a UIText object with the current local time without using a coroutine
+
--(example: clock )
+
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]
+
 
+
rateUpdate = 1.0
+
nextUpdate = 0.0
+
text = Space.Host.GetReference("Text").UIText
+
 
+
 
+
OnUpdate = function()
+
        if Space.Time > nextUpdate then
+
          nextUpdate = Space.Time + rateUpdate
+
          text.Text = Space.LocalTime
+
          end
+
    }
+
   
+
Space.Host.ExecutingObject.OnUpdate(OnUpdate)</pre>
+
}}
+
 
+
{{ScriptFunction|string|ServerTime|[get;]|Returns current server time.|Space.Log(Space.ServerTime)
+
|6=<pre>--this script will update a UIText object with the current server time (UTC)
+
--(example: clock)
+
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]
+
 
+
text = Space.Host.GetReference("Text").UIText
+
 
+
co = function()
+
  while true do
+
  text.Text = Space.ServerTime
+
    coroutine.yield(1)
+
  end
+
end
+
 
+
Space.Host.StartCoroutine(co)</pre>}}
+
 
+
{{ScriptFunction|string|LocalTime|[get;]|Returns current local time.|Space.Log(Space.LocalTime)|6=<pre>--this script will update a UIText object with the current local time
+
--(example: clock)
+
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]
+
 
+
text = Space.Host.GetReference("Text").UIText
+
 
+
co = function()
+
  while true do
+
  text.Text = Space.LocalTime
+
    coroutine.yield(1)
+
  end
+
end
+
 
+
Space.Host.StartCoroutine(co)</pre>}}
+
 
+
{{ScriptFunction|int|ServerTimeUnix|[get;]|Returns the server time unix timestamp.|<pre>Space.Log(Space.ServerTimeUnix)</pre>|6=<pre>--this script will update a UIText object with the current server time unix timestamp
+
--(example: clock)
+
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]
+
 
+
text = Space.Host.GetReference("Text").UIText
+
 
+
co = function()
+
  while true do
+
  text.Text = Space.ServerTimeUnix
+
    coroutine.yield(1)
+
  end
+
end
+
 
+
Space.Host.StartCoroutine(co)</pre>}}
+
 
+
{{ScriptFunction|int|LocalTimeUnix|[get;]|Returns the local time unix timestamp.|5=<pre>Space.Log(Space.LocalTimeUnix)</pre>|6=<pre>--this script will update a UIText object with the current local time unix timestamp
+
--(example: clock)
+
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]
+
 
+
text = Space.Host.GetReference("Text").UIText
+
 
+
co = function()
+
  while true do
+
  text.Text = Space.LocalTimeUnix
+
    coroutine.yield(1)
+
  end
+
end
+
 
+
Space.Host.StartCoroutine(co)</pre>}}
+
 
+
{{ScriptFunction|int|LoginTime|[get;]|Returns how long player has been logged in (in seconds).|5= <pre>Space.Log(Space.LoginTime)</pre>|6=<pre>--this script will update a UIText object with how long the user has been logged in (in seconds)
+
--(example: clock)
+
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]
+
 
+
text = Space.Host.GetReference("Text").UIText
+
 
+
co = function()
+
  while true do
+
  text.Text = Space.LoginTime
+
    coroutine.yield(1)
+
  end
+
end
+
 
+
Space.Host.StartCoroutine(co)</pre>}}
+
 
+
{{ScriptFunction|float|DeltaTime|[get;]|The completion time in seconds since the last frame.|Space.Log(Space.DeltaTime)|6= <pre>--the below script rotates an object around Y axis but uses DeltaTime
+
--to make sure it's not dependant on client's Framerate (FPS)
+
--this way the object rotates per second not per frame
+
--(Example: Important movement in OnUpdate)
+
 
+
thisGameObject = Space.Host.ExecutingObject
+
 
+
 
+
 
+
OnUpdate = function()
+
currentY = thisGameObject.WorldRotation.EulerAngles.Y
+
newRotation = Quaternion.Euler(0, currentY + 1 * Space.DeltaTime, 0) --We multiplied 1 by Space.DeltaTime
+
thisGameObject.WorldRotation = newRotation
+
end
+
 
+
thisGameObject.OnUpdate(OnUpdate)</pre>
+
}}
+
 
+
{{ScriptFunction|bool|PreviewServer|[get;]|Return true if in preview server.|5=<pre>Space.Log(Space.PreviewServer)</pre>|6=<pre>--this script will update a UIText object with "preview" or "live" depending
+
--whether we are on preview server or live server
+
--[UIText object needs to be added to the references section in the scripting runtime with name "Text"]
+
 
+
text = Space.Host.GetReference("Text").UIText
+
 
+
OnUpdate = function()
+
  if Space.PreviewServer then
+
    text.Text = "Preview"
+
  else
+
    text.Text = "Live"
+
  end
+
end
+
 
+
Space.Host.ExecutingObject.OnUpdate(OnUpdate)</pre>}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 07:13, 19 September 2022

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