wiki.sine.space | sinespace

Scripting/SScene

From wiki.sine.space
Revision as of 02:54, 10 August 2021 by Voidtech (Talk | contribs)

Jump to: navigation, search

The SScene class represents the region the user is currently in.

Members

Find

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')

 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. 



FindID

SGameObject FindID (string id);

Finds a single Game Object using ID and returns it

--add Scene Object Database to a Gameobject, set "123" to IDs and name the GameObject "Cube".

local obj=Space.Scene.FindID("123")
Space.Log(obj.Name);
mat.SetColor("_Color",Color.New(0,0,1,1))

--print "Cube" if the object exists.


GetAvatar

SAvatar GetAvatar (long id);

Get reference to avatar using ID

local cur=Space.Scene.GetAvatar(43)
Space.Log(cur.Username)


GetAvatar

SAvatar GetAvatar (string name);

Get reference to avatar using Username

local cur=Space.Scene.GetAvatar("TestUser")
Space.Log(cur.ID)


MarkObjectTemporary

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.

local obj=Space.Scene.Find("Cube")
Space.Scene.MarkObjectTemporary(obj)



OnEditModeEnd

void OnEditModeEnd (Closure e);

An event which is fired when play exists Room Edit mode

Space.Scene.OnEditModeEnd(function ()

    Space.Log("End Edit Mode")

end)


OnEditModeStart

void OnEditModeStart (Closure e);

An event which is fired when player enters Room Edit mode

Space.Scene.OnEditModeStart(function ()

    Space.Log("Enter Edit Mode")

end)


CreateGameObject

SGameObject CreateGameObject (string name);

Creates a new empty game object with the name 'Name' and returns a reference

newObject = Space.Scene.CreateGameObject("potato")


CreateGameObject

SGameObject CreateGameObject (SResource resource);

Creates a game object from the specified resource

res = Space.GetResource("Tomato") 
--declare it as resource in your Scripting Runtime component
Space.Scene.CreateGameObject(res)
 


OnPlayerJoin

void OnPlayerJoin (Closure e);

Event which fires whenever a player joins the region


OnPlayerJoin

void OnPlayerJoin (Action<SAvatar> callback)

Event which fires whenever a player joins the region

--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


OnPlayerLeave

void OnPlayerLeave (Action<long> callback)

Event which fires whenever a player leaves the region

 function playerLeft(id) 
--
end
Space.Scene.OnPlayerLeave(playerLeft) 


--Place this script in a UIText object and it will
--update itself with the name of the last player left

function updateText(Av) --we include "Av" here because the event gives us a reference to the Avatar that has left
Space.Host.ExecutingObject.UIText.Text= "Last player left: " .. Av.Username
end

Space.Scene.OnPlayerLeave(updateText) -- updateText will now be called every time a player leaves

OnPlayerLeave

void OnPlayerLeave (Closure e);

Event which fires whenever a player leaves the region



GetAvatar

SAvatar GetAvatar (long id);

Return an avatar with id.

local cur=Space.Scene.GetAvatar(43)
Space.Log(cur.Username)


GetAvatar

SAvatar GetAvatar (string name);

Return an avatar with id.

local cur=Space.Scene.GetAvatar("TestUser")
Space.Log(cur.ID)



Properties

PlayerAvatar

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.

 CurrentPlayer = Space.Scene.PlayerAvatar 


Avatars[]

SAvatar Avatars[] { get; }

Returns a list of Avatars in the scene

avatars = Space.Scene.Avatars  


Objects[]

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.

 objects = Space.Scene.Objects 


Name

string Name { get; }

Returns the name of the current region

RegionName = Space.Scene.Name 


Url

string Url { get; }

Returns the URL of the current region

RegionUrl = Space.Scene.Url 


Owner

long Owner { get; }

Returns the avatar ID of the regions owner

RegionOwner = Space.Scene.Owner


PlayerIsOwner

bool PlayerIsOwner { get; }

Returns whether the current player is the owner of the region

isOwner = Space.Scene.PlayerIsOwner 


AllAvatars

SAvatar AllAvatars (string name);

Return all avatars in the scene.

local avatars=Space.Scene.AllAvatars

Space.Log(#avatars)

--Print the length of AllAvatars.


RegionID

long RegionID (get);

Returns the region ID of current region.

Space.Log(Space.Scene.RegionID)


InstanceID

long InstanceID (get);

Return the instance ID of current region.

Space.Log(Space.Scene.InstanceID)


InstanceID

long InstanceID (get);

Switch to a shard region.

Space.Scene.SwitchToInstance(2)


SwitchToInstance

void SwitchToInstance (uint id);

Switch to a shard region.

Space.Scene.SwitchToInstance(2)


PlayerIsAdmin

bool PlayerIsAdmin (get);

Return true if current player is the region admin.

Space.Log(Space.Scene. PlayerIsAdmin)


IsInEditMode

bool IsInEditMode (get);

Returns true if current player is in edit mode.

Space.Log(Space.Scene. IsInEditMode)


Floors

SGameObject Floors (get);

Return an array of all floors in the region.

for i=1,#Space.Scene.Floors do

    Space.Log(Space.Scene.Floors[i].Name)
end

--print all floor names.