wiki.sine.space | sinespace

Difference between revisions of "Scripting/SScene"

From wiki.sine.space
Jump to: navigation, search
(Added simple example to SScene .CreateGameObject(resource) .OnPlayerLeave)
(Defined SScene .FindID .GetAvatar(ID) .GetAvatar(name) .MarkObjectTemporary .OnEditModeEnd .OnEditModeStart .OnPlayerLeave(closure) .OnPlayerJoin(closure))
Line 18: Line 18:
 
--This returns the GameObject named Hand,
 
--This returns the GameObject named Hand,
 
--which is a child of Arm > Monster. </pre>}}
 
--which is a child of Arm > Monster. </pre>}}
 +
{{ScriptFunction|SGameObject|FindID|(string id);|Finds a single Game Object using ID and returns it |5=}}
 +
{{ScriptFunction|SAvatar|GetAvatar|(long id);|Get reference to avatar using ID |5=}}
 +
{{ScriptFunction|SAvatar|GetAvatar|(string name);|Get  reference to avatar using Username|5=}}
 +
{{ScriptFunction|void|MarkObjectTemporary|(SGameObject obj);|Marks the Game Object as "Temporary" |5=}}
 +
{{ScriptFunction|void|OnEditModeEnd|(Closure e);|An event which is fired when Edit Mode has ended|5=}}
 +
{{ScriptFunction|void|OnEditModeStart|(Closure e);|An event which is fired when Edit Mode is started|5=}}
 
{{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=
 
{{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>}}
 
<pre> CurrentPlayer = Space.Scene.PlayerAvatar </pre>}}
Line 39: Line 45:
 
{{ScriptFunction|bool|PlayerIsOwner|{ get; }|Returns whether the current player is the owner of the region|5=
 
{{ScriptFunction|bool|PlayerIsOwner|{ get; }|Returns whether the current player is the owner of the region|5=
 
<pre>isOwner = Space.Scene.PlayerIsOwner </pre>}}
 
<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=
 
{{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
 
<pre>--Place this script in a UIText object and it will
Line 57: Line 64:
 
end
 
end
 
Space.Scene.OnPlayerLeave(playerLeft) </pre>}}
 
Space.Scene.OnPlayerLeave(playerLeft) </pre>}}
 +
{{ScriptFunction|void|OnPlayerLeave|(Closure e);|Event which fires whenever a player leaves the region|5=}}
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 15:59, 11 December 2020

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


GetAvatar

SAvatar GetAvatar (long id);

Get reference to avatar using ID


GetAvatar

SAvatar GetAvatar (string name);

Get reference to avatar using Username


MarkObjectTemporary

void MarkObjectTemporary (SGameObject obj);

Marks the Game Object as "Temporary"


OnEditModeEnd

void OnEditModeEnd (Closure e);

An event which is fired when Edit Mode has ended


OnEditModeStart

void OnEditModeStart (Closure e);

An event which is fired when Edit Mode is started


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 


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)
 


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 


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


--Note that this is client side, you will not trigger this event,
--the player that joins next will trigger it.


OnPlayerLeave

void OnPlayerLeave (Action<long> callback)

Event which fires whenever a player leaves the region

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


OnPlayerLeave

void OnPlayerLeave (Closure e);

Event which fires whenever a player leaves the region