# SScene

**Membres** 30

|           |                                             |                                                                 |
| --------- | ------------------------------------------- | --------------------------------------------------------------- |
| Fonction  | [Find](#find)                               | Finds a single Game Object matching 'Name' and returns it.      |
| Fonction  | [FindID](#findid)                           | Finds a single Game Object using ID and returns it              |
| Fonction  | [MarkObjectTemporary](#markobjecttemporary) | Marks the Game Object as temporary.                             |
| Fonction  | [GetAvatar](#getavatar)                     | Get reference to an avatar                                      |
| Fonction  | [CreateGameObject](#creategameobject)       | Creates a game object from the specified resource               |
| Fonction  | [SwitchToInstance](#switchtoinstance)       | Switch to a shard region.                                       |
| Fonction  | [OnPlayerJoin](#onplayerjoin)               | Event which fires whenever a player joins the region            |
| Fonction  | [OnPlayerLeave](#onplayerleave)             | Event which fires whenever a player leaves the region           |
| Fonction  | [OnEditModeStart](#oneditmodestart)         | An event which is fired when player enters Room Edit mode       |
| Fonction  | [OnEditModeEnd](#oneditmodeend)             | An event which is fired when player exits Room Edit mode        |
| Fonction  | [OnEditModeAdd](#oneditmodeadd)             | An event which is fired when object is added during Edit Mode   |
| Fonction  | [OnEditModeRemove](#oneditmoderemove)       | An event which is fired when object is deleted during Edit Mode |
| Propriété | [PlayerAvatar](#playeravatar)               | Returns the current player avatar.                              |
| Propriété | [Avatars](#avatars)                         | Returns a list of Avatars in the scene                          |
| Propriété | [AllAvatars](#allavatars)                   | Returns a list of all avatars in the scene.                     |
| Propriété | [Population](#population)                   | –                                                               |
| Propriété | [Objects](#objects)                         | Returns a list of Objects in the scene.                         |
| Propriété | [Name](#name)                               | Returns the name of the current region                          |
| Propriété | [Url](#url)                                 | Returns the URL of the current region                           |
| Propriété | [RegionID](#regionid)                       | Returns the region ID of current region.                        |
| Propriété | [InstanceID](#instanceid)                   | Return the instance ID of current region.                       |
| Propriété | [Owner](#owner)                             | Returns the avatar ID of the regions owner                      |
| Propriété | [PlayerIsOwner](#playerisowner)             | Returns whether the current player is the owner of the region   |
| Propriété | [PlayerIsAdmin](#playerisadmin)             | Does this Player have the Admin role?                           |
| Propriété | [PlayerIsModerator](#playerismoderator)     | Does this Player have the Moderator role?                       |
| Propriété | [PlayerIsDeveloper](#playerisdeveloper)     | Does this Player have the Developer role?                       |
| Propriété | [PlayerIsTrusted](#playeristrusted)         | Does this Player have the Trusted role?                         |
| Propriété | [IsInEditMode](#isineditmode)               | Returns true if current player is in edit mode.                 |
| Propriété | [Floors](#floors)                           | Return an array of all floors in the region.                    |
| Propriété | [Landmarks](#landmarks)                     | Return all Landmarks in the region                              |

## Fonctions

### Find

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) 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')

Paramètres

| Nom  | Type   | Valeur par défaut |
| ---- | ------ | ----------------- |
| name | string | –                 |

Valeurs de retour

`SGameObject`

Exemple

**Lua**

```lua
 Space.Scene.Find('Door2')

```

**Lua**

```lua
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](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) FindID(string id)

Finds a single Game Object using ID and returns it

Paramètres

| Nom | Type   | Valeur par défaut |
| --- | ------ | ----------------- |
| id  | string | –                 |

Valeurs de retour

`SGameObject`

Exemple

**Lua**

```lua
--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);
--print "Cube" if the object exists.

```

### MarkObjectTemporary

void MarkObjectTemporary([SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) 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.

Paramètres

| Nom | Type                                                                                  | Valeur par défaut |
| --- | ------------------------------------------------------------------------------------- | ----------------- |
| obj | [SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Scene.MarkObjectTemporary(AnObjectReference)

```

### GetAvatar

[SAvatar](/docs/fr/scripting/client-scripting-api-reference/types/savatar.md) GetAvatar(long id)

[SAvatar](/docs/fr/scripting/client-scripting-api-reference/types/savatar.md) GetAvatar(string name)

Get reference to an avatar

Paramètres

| Nom  | Type   | Valeur par défaut |
| ---- | ------ | ----------------- |
| id   | long   | –                 |
| name | string | –                 |

Valeurs de retour

`SAvatar`

Exemple

**Lua**

```lua
theAvatar =Space.Scene.GetAvatar(43)
--or
theAvatar =Space.Scene.GetAvatar("TestUser")

```

### CreateGameObject

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) CreateGameObject(string name)

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) CreateGameObject([SResource](/docs/fr/scripting/client-scripting-api-reference/types/sresource.md) resource)

Creates a game object from the specified resource

Paramètres

| Nom      | Type                                                                              | Valeur par défaut |
| -------- | --------------------------------------------------------------------------------- | ----------------- |
| name     | string                                                                            | –                 |
| resource | [SResource](/docs/fr/scripting/client-scripting-api-reference/types/sresource.md) | –                 |

Valeurs de retour

`SGameObject`

Exemple

**Lua**

```lua
Space.Scene.CreateGameObject('NewBall')
--or
Space.Scene.CreateGameObject(Space.Resources[1])

```

**Lua**

```lua
--clicking this object will create a GameObject from a resource and place it above our avatar

thisObject = Space.Host.ExecutingObject
thisPlayer = Space.Scene.PlayerAvatar

resource = Space.GetResource("Tomato")  --add it as resource in your Scripting Runtime component

OnClick = function()
createdObject = Space.Scene.CreateGameObject(resource)    
createdObject.WorldPosition = thisPlayer.GameObject.WorldPosition + thisPlayer.GameObject.Up
end

thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### SwitchToInstance

void SwitchToInstance(uint id)

Switch to a shard region.

Paramètres

| Nom | Type | Valeur par défaut |
| --- | ---- | ----------------- |
| id  | uint | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Scene.SwitchToInstance(2)

```

### OnPlayerJoin

void OnPlayerJoin(Closure e)

Event which fires whenever a player joins the region

Paramètres

| Paramètre | Type               | Description |
| --------- | ------------------ | ----------- |
| e         | Closure (Callback) | e(SAvatar)  |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
--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(Closure e)

Event which fires whenever a player leaves the region

Paramètres

| Paramètre | Type               | Description |
| --------- | ------------------ | ----------- |
| e         | Closure (Callback) | e(long)     |

Valeurs de retour

`void`

Exemple

**Lua**

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

```

**Lua**

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

```

### OnEditModeStart

void OnEditModeStart(Closure e)

An event which is fired when player enters Room Edit mode

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Scene.OnEditModeStart(AFunctionName)

```

**Lua**

```lua
--makes an object become active upon entering edit mode
thisObject = Space.Host.ExecutingObject
targetObject = Space.Host.GetReference("target") --add to references in Scripting Runtime component

function OnEditModeFunction()
  targetObject.Active = true
end


Space.Scene.OnEditModeStart(OnEditModeFunction)

```

### OnEditModeEnd

void OnEditModeEnd(Closure e)

An event which is fired when player exits Room Edit mode

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Scene.OnEditModeEnd(AfunctionName)

```

**Lua**

```lua
--makes an object become active upon exiting edit mode
thisObject = Space.Host.ExecutingObject
targetObject = Space.Host.GetReference("target") --add to references in Scripting Runtime component

function OnEditModeFunction()
  targetObject.Active = false
end


Space.Scene.OnEditModeEnd(OnEditModeFunction)

```

### OnEditModeAdd

void OnEditModeAdd(Closure e)

An event which is fired when object is added during Edit Mode

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Scene.OnEditModeAdd(AFunctionName)

```

**Lua**

```lua
--prints the total number of objects in the scene whenever a new object is added in edit mode

  function OnEditModeFunction()
   Space.Log(#Space.Scene.Objects)
  end


  Space.Scene.OnEditModeAdd(OnEditModeFunction)

```

### OnEditModeRemove

void OnEditModeRemove(Closure e)

An event which is fired when object is deleted during Edit Mode

Paramètres

| Nom | Type    | Valeur par défaut |
| --- | ------- | ----------------- |
| e   | Closure | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

```lua
Space.Scene.OnEditModeRemove(AFunctionName)

```

**Lua**

```lua
--prints the total number of objects in the scene whenever a new object is removed in edit mode

  function OnEditModeFunction()
   Space.Log(#Space.Scene.Objects)
  end


  Space.Scene.OnEditModeRemove(OnEditModeFunction)

```

## Propriétés

### PlayerAvatar

[SAvatar](/docs/fr/scripting/client-scripting-api-reference/types/savatar.md) 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.

Exemple

**Lua**

```lua
 CurrentPlayer = Space.Scene.PlayerAvatar 

```

### Avatars

[SAvatar](/docs/fr/scripting/client-scripting-api-reference/types/savatar.md)\[] Avatars {get; }

Returns a list of Avatars in the scene

Exemple

**Lua**

```lua
avatars = Space.Scene.Avatars  

```

**Lua**

```lua
--this script, once clicked, will get all avatars in the scene
--and print their ID, Username and Title (excluding self)
--(Example: scoreboards/radars/scanners/game machines)

thisGameObject = Space.Host.ExecutingObject

OnClick = function()
Avatars = Space.Scene.Avatars

      if #Avatars > 0 then
            for var=1, #Avatars do
        local ID = Avatars[var].ID
        local Username = Avatars[var].Username
        local Title = Avatars[var].Title
        if Title == "" then Title = "None" end

         Space.Log("ID: " .. ID .. ", Username: " .. Username .. ", Title: " .. Title)
            end

      else
      Space.Log("No Avatars")
      end
end
 
thisGameObject.AddClickable() 
thisGameObject.Clickable.Tooltip = "Click to print all avatars' information"
thisGameObject.Clickable.OnClick(OnClick) 

```

### AllAvatars

List< [SAvatar](/docs/fr/scripting/client-scripting-api-reference/types/savatar.md) > AllAvatars {get; }

Returns a list of all avatars in the scene. The player avatar that is calling this will be added to the end of the list.

Exemple

**Lua**

```lua
local avatars=Space.Scene.AllAvatars
Space.Log(#avatars)
--Print the length of AllAvatars.

```

**Lua**

```lua
 --this script, once clicked, will get all avatars in the scene
--and print their ID, Username and Title (including self)
--(Example: scoreboards/radars/scanners/game machines)

thisGameObject = Space.Host.ExecutingObject

OnClick = function()
allAvatars = Space.Scene.AllAvatars

    for var=1, #allAvatars do
local ID = allAvatars[var].ID
local Username = allAvatars[var].Username
local Title = allAvatars[var].Title
if Title == "" then Title = "None" end

 Space.Log("ID: " .. ID .. ", Username: " .. Username .. ", Title: " .. Title)
    end

end

 
thisGameObject.AddClickable() 
thisGameObject.Clickable.Tooltip = "Click to print all avatars' information"
thisGameObject.Clickable.OnClick(OnClick) 

```

### Population

int Population {get; }

Exemple

**Lua**

```lua
currentPopulation = Space.Scene.Population

```

### Objects

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md)\[] 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.

Exemple

**Lua**

```lua
 objects = Space.Scene.Objects 

```

**Lua**

```lua
--clicking this object will print a name of every object in the scene
--[better use a coroutine incase the foor loop exceeds allowed frame time]
  thisObject = Space.Host.ExecutingObject

  OnClickFunction = function()
    local objects = Space.Scene.Objects
    for i=1, #objects, 1 do
      Space.Log(objects[i].Name)
    end
  end

  thisObject.AddClickable()

```

### Name

string Name {get; }

Returns the name of the current region

Exemple

**Lua**

```lua
RegionName = Space.Scene.Name 

```

**Lua**

```lua
--this object will be clickable only if it is in a region called "X Region"
--((for example: limiting object functionality to a specific region))

thisObject = Space.Host.ExecutingObject


OnClick = function()
Space.Log("We are in X Region")
end


if Space.Scene.Name == "X Region" then
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)
end

```

### Url

string Url {get; }

Returns the URL of the current region

Exemple

**Lua**

```lua
RegionUrl = Space.Scene.Url 

```

**Lua**

```lua
--the URL of this region will be placed in a UIText upon loading 
--and also printed if this object is clicked
thisObject = Space.Host.ExecutingObject
textObject = Space.Host.GetReference("textObject") -- add to scripting runtime references


function OnClick()
  Space.Log(Space.Scene.Url)
end

textObject.UIText.Text = Space.Scene.Url
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### RegionID

long RegionID {get; }

Returns the region ID of current region.

Exemple

**Lua**

```lua
Space.Log(Space.Scene.RegionID)

```

**Lua**

```lua
--the RegionID of this region will be placed in a UIText upon loading 
--and also printed if this object is clicked
thisObject = Space.Host.ExecutingObject
textObject = Space.Host.GetReference("textObject") -- add to scripting runtime references


function OnClick()
  Space.Log(Space.Scene.RegionID)
end

textObject.UIText.Text = Space.Scene.RegionID
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### InstanceID

long InstanceID {get; }

Return the instance ID of current region.

Exemple

**Lua**

```lua
instanceID = Space.Scene.InstanceID

```

**Lua**

```lua
--the RegionID of this region will be placed in a UIText upon loading 
--and also printed if this object is clicked
thisObject = Space.Host.ExecutingObject
textObject = Space.Host.GetReference("textObject") -- add to scripting runtime references


function OnClick()
  Space.Log(Space.Scene.InstanceID)
end

textObject.UIText.Text = Space.Scene.InstanceID
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### Owner

long Owner {get; }

Returns the avatar ID of the regions owner

Exemple

**Lua**

```lua
RegionOwner = Space.Scene.Owner

```

**Lua**

```lua
--this script will make this object only clickable for the region owner

thisObject = Space.Host.ExecutingObject
thisPlayer = Space.Scene.PlayerAvatar

OnClick = function()
Space.Log("Do Something")
end

if thisPlayer.ID == Space.Scene.Owner then 
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)
end

```

### PlayerIsOwner

bool PlayerIsOwner {get; }

Returns whether the current player is the owner of the region

Exemple

**Lua**

```lua
isOwner = Space.Scene.PlayerIsOwner 

```

**Lua**

```lua
--this script will make the object a clickable, but only if player is region owner
--(Example: Access control)

thisGameObject = Space.Host.ExecutingObject

OnClick = function()
Space.Log("this click was only possible because you are a region Owner")
end

if Space.Scene.PlayerIsOwner then
thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click me"
thisGameObject.Clickable.OnClick(OnClick) 
end

```

### PlayerIsAdmin

bool PlayerIsAdmin {get; }

Does this Player have the **Admin** role?

Exemple

**Lua**

```lua
Space.Scene.PlayerIsAdmin

```

**Lua**

```lua
--this script will make the object a clickable, but only if player is region Admin
--(Example: Access control)

thisGameObject = Space.Host.ExecutingObject

OnClick = function()
Space.Log("this click was only possible because you are a region Admin")
end

if Space.Scene.PlayerIsAdmin then
thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click me Admin"
thisGameObject.Clickable.OnClick(OnClick) 
end

```

### PlayerIsModerator

bool PlayerIsModerator {get; }

Does this Player have the **Moderator** role?

Exemple

**Lua**

```lua
playerIsModerator = Space.Scene.PlayerIsModerator

```

**Lua**

```lua
--this script will make the object a clickable, but only if player is Moderator in this region
--(Example: Access control)

thisGameObject = Space.Host.ExecutingObject

OnClick = function()
Space.Log('this click was only possible because you are Moderator in this region')
end

if Space.Scene.PlayerIsModerator then
thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click me Moderator"
thisGameObject.Clickable.OnClick(OnClick) 
end

```

### PlayerIsDeveloper

bool PlayerIsDeveloper {get; }

Does this Player have the **Developer** role?

Exemple

**Lua**

```lua
playerIsDeveloper = Space.Scene.PlayerIsDeveloper

```

### PlayerIsTrusted

bool PlayerIsTrusted {get; }

Does this Player have the **Trusted** role?

Exemple

**Lua**

```lua
playerIsTrusted = Space.Scene.PlayerIsTrusted

```

**Lua**

```lua
--this script will make the object a clickable, but only if player is Trusted in this region
--(Example: Access control)

thisGameObject = Space.Host.ExecutingObject

OnClick = function()
Space.Log("this click was only possible because you are Trusted in this region")
end

if Space.Scene.PlayerIsTrusted then
thisGameObject.AddClickable()
thisGameObject.Clickable.Tooltip = "Click me Trusted"
thisGameObject.Clickable.OnClick(OnClick) 
end

```

### IsInEditMode

bool IsInEditMode {get; }

Returns true if current player is in edit mode.

Exemple

**Lua**

```lua
Space.Log(Space.Scene.IsInEditMode)

```

**Lua**

```lua
--makes an object only active when this player is in Edit Mode
thisObject = Space.Host.ExecutingObject
targetObject = Space.Host.GetReference("target") --add to references in Scripting Runtime component

function OnUpdateFunction()
  targetObject.Active = Space.Scene.IsInEditMode 
end


thisObject.OnUpdate(OnUpdateFunction)

```

### Floors

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md)\[] Floors {get; }

Return an array of all floors in the region.

Exemple

**Lua**

```lua
for i=1,#Space.Scene.Floors do
    Space.Log(Space.Scene.Floors[i].Name)
end
--print all floor names.

```

**Lua**

```lua
example 2

```

### Landmarks

[SLandmark](/docs/fr/scripting/client-scripting-api-reference/types/slandmark.md)\[] Landmarks {get; }

Return all Landmarks in the region

Exemple

**Lua**

```lua
        local landmark = Space.Scene.Landmarks
        for i = 1,#landmark do
    if landmark[i].Type == LandmarkType.LandingZone then
        Space.Log("LandingZone")
        end
                Space.Log(landmark[i].Name .. " ".. landmark[i].Position.ToString())
        end

```
