wiki.sine.space | sinespace

Difference between revisions of "Scripting/SScene"

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/sscene")
 
(22 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The SScene class represents the region the user is currently in.
+
This page has moved to: https://docs.sine.space/v/scripting/client-scripting/scene/sscene
 
+
==Members==
+
{{ScriptFunction|SGameObject|Find|(string name);|Finds a single Game Object matching 'Name' and returns it. Can use '/' characters to designate a path (e.g. 'Parent/Child' returns Child with 'Parent')|5=
+
<pre> hand = Space.Scene.Find("Hand");
+
--This returns the GameObject named Hand.
+
 
+
hand = Space.Scene.Find("/Hand");
+
--This returns the GameObject named Hand.
+
--Hand must not have a parent in the Hierarchy view.
+
 
+
hand = Space.Scene.Find("/Monster/Arm/Hand");
+
--This returns the GameObject named Hand,
+
--which is a child of Arm > Monster.
+
--Monster must not have a parent in the Hierarchy view.
+
 
+
hand = Space.Scene.Find("Monster/Arm/Hand");
+
--This returns the GameObject named Hand,
+
--which is a child of Arm > Monster. </pre>}}
+
 
+
 
+
{{ScriptFunction|SGameObject|FindID|(string id);|Finds a single Game Object using ID and returns it |5=
+
''--add Scene Object Database to a Gameobject, set "123" to IDs and name the GameObject  "Cube".''<br>
+
local obj=Space.Scene.FindID("123")<br>
+
Space.Log(obj.Name);<br>
+
mat.SetColor("_Color",Color.New(0,0,1,1))<br>
+
''--print "Cube" if the object exists.''
+
}}
+
 
+
{{ScriptFunction|SAvatar|GetAvatar|(long id);|Get reference to avatar using ID |5=
+
local cur=Space.Scene.GetAvatar(43)<br>
+
Space.Log(cur.Username)
+
}}
+
 
+
{{ScriptFunction|SAvatar|GetAvatar|(string name);|Get  reference to avatar using Username|5=
+
local cur=Space.Scene.GetAvatar("TestUser")<br>
+
Space.Log(cur.ID)
+
}}
+
 
+
{{ScriptFunction|void|MarkObjectTemporary|(SGameObject obj);|Marks the Game Object as temporary. Temporary objects will be cleaned up automatically if the script is destroyed or reset. Can be used to handle cleanup from procedural objects created by a script.  |5=
+
local obj=Space.Scene.Find("Cube")<br>
+
Space.Scene.MarkObjectTemporary(obj)<br>
+
}}
+
 
+
 
+
{{ScriptFunction|void|OnEditModeEnd|(Closure e);|An event which is fired when play exists Room Edit mode|5=
+
Space.Scene.OnEditModeEnd(function ()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log("End Edit Mode")<br>
+
end)
+
}}
+
 
+
{{ScriptFunction|void|OnEditModeStart|(Closure e);|An event which is fired when player enters Room Edit mode|5=
+
Space.Scene.OnEditModeStart(function ()<br>
+
&nbsp;&nbsp;&nbsp;&nbsp;Space.Log("Enter Edit Mode")<br>
+
end)
+
}}
+
 
+
{{ScriptFunction|SAvatar|PlayerAvatar|{ get; }|Returns the current player avatar. If this script is calling this upon initialisation, the Player may not exist yet, and you will want to wait a few frames until the avatar is present before continuing.|5=
+
<pre> CurrentPlayer = Space.Scene.PlayerAvatar </pre>}}
+
{{ScriptFunction|SAvatar|Avatars[]|{ get; }|Returns a list of Avatars in the scene|5=
+
<pre>avatars = Space.Scene.Avatars  </pre>}}
+
{{ScriptFunction|SGameObject|Objects[]|{ get; }|Returns a list of Objects in the scene. '''IMPORTANT: This function is slow, you should cache the result and avoid calling this every frame.'''|5=
+
<pre> objects = Space.Scene.Objects </pre>}}
+
{{ScriptFunction|SGameObject|CreateGameObject|(string name);|Creates a new empty game object with the name 'Name' and returns a reference|5=
+
<pre>newObject = Space.Scene.CreateGameObject("potato")</pre>}}
+
{{ScriptFunction|SGameObject|CreateGameObject|([[Scripting/SResource|SResource]] resource);|Creates a game object from the specified resource|5=
+
<pre>res = Space.GetResource("Tomato")
+
--declare it as resource in your Scripting Runtime component
+
Space.Scene.CreateGameObject(res)
+
</pre>}}
+
{{ScriptFunction|string|Name|{ get; }|Returns the name of the current region|5=
+
<pre>RegionName = Space.Scene.Name </pre>}}
+
{{ScriptFunction|string|Url|{ get; }|Returns the URL of the current region|5=
+
<pre>RegionUrl = Space.Scene.Url </pre>}}
+
{{ScriptFunction|long|Owner|{ get; }|Returns the avatar ID of the regions owner|5=
+
<pre>RegionOwner = Space.Scene.Owner</pre>}}
+
{{ScriptFunction|bool|PlayerIsOwner|{ get; }|Returns whether the current player is the owner of the region|5=
+
<pre>isOwner = Space.Scene.PlayerIsOwner </pre>}}
+
{{ScriptFunction|void|OnPlayerJoin|(Closure e);|Event which fires whenever a player joins the region|5=}}
+
{{ScriptFunction|void|OnPlayerJoin|(Action<[[Scripting/SAvatar|SAvatar]]> callback)|Event which fires whenever a player joins the region|5=
+
<pre>--Place this script in a UIText object and it will
+
--update itself with the name of the last player joined
+
 
+
function updateText(Av) --we include "Av" here because the event gives us a reference to the Avatar that joined
+
Space.Host.ExecutingObject.UIText.Text= "Last player joined: " .. Av.Username
+
end
+
 
+
Space.Scene.OnPlayerJoin(updateText) -- updateText will now be called everytime a player joins
+
 
+
 
+
--Note that this is client side, you will not trigger this event,
+
--the player that joins next will trigger it.</pre>}}
+
{{ScriptFunction|void|OnPlayerLeave|(Action<long> callback)|Event which fires whenever a player leaves the region|5=
+
<pre> function playerLeft(id)
+
--
+
end
+
Space.Scene.OnPlayerLeave(playerLeft) </pre>}}
+
{{ScriptFunction|void|OnPlayerLeave|(Closure e);|Event which fires whenever a player leaves the region|5=}}
+
 
+
{{ScriptFunction|List<SAvatar>|AllAvatars|(string name);|Return all avatars in the scene.|5=
+
local avatars=Space.Scene.AllAvatars<br>
+
Space.Log(#avatars)<br>
+
''--Print the length of AllAvatars.''
+
}}
+
 
+
{{ScriptFunction|SAvatar|GetAvatar|(long id);|Return an avatar with id.|5=
+
local cur=Space.Scene.GetAvatar(43)<br>
+
Space.Log(cur.Username)
+
}}
+
 
+
{{ScriptFunction|SAvatar|GetAvatar|(string name);|Return an avatar with id.|5=
+
local cur=Space.Scene.GetAvatar("TestUser")<br>
+
Space.Log(cur.ID)
+
}}
+
 
+
{{ScriptFunction|long|RegionID|(get);|Returnsthe region ID of current region.|5=
+
Space.Log(Space.Scene.RegionID)
+
}}
+
 
+
{{ScriptFunction|long|InstanceID|(get);|Return the instance ID of current region.|5=
+
Space.Log(Space.Scene.InstanceID)
+
}}
+
 
+
{{ScriptFunction|long|InstanceID|(get);|Switch to a shard region.|5=
+
Space.Scene.SwitchToInstance(2)
+
}}
+
 
+
{{ScriptFunction|void|SwitchToInstance|(uint id);|Switch to a shard region.|5=
+
Space.Scene.SwitchToInstance(2)
+
}}
+
 
+
{{ScriptFunction|bool|PlayerIsAdmin|(get);|Return true if current player is the region admin.|5=
+
Space.Log(Space.Scene.InstanceID)
+
}}
+
 
+
{{Scripting Navbox}}
+

Latest revision as of 07:14, 19 September 2022

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