# SScript

## Functions

### TypeName

string **TypeName** (DynValue dv)

*Return the type name of the value.*

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| dv        | DynValue |             |

{% tabs %}
{% tab title="Lua" %}

```lua
typeName = Space.TypeName("123")
```

{% endtab %}
{% endtabs %}

### TrackingAllowed

bool **TrackingAllowed** (string key)

*Returns true on white-label grids when the user has opted into tracking for the given key. Always returns false on the main grid.*

| Parameter | Type   | Description                                                                |
| --------- | ------ | -------------------------------------------------------------------------- |
| key       | string | A unique identifier used to store and look up the user's tracking consent. |

{% tabs %}
{% tab title="Lua" %}

```lua
isTrackingAllowed = Space.TrackingAllowed('3423423423423')
```

{% endtab %}
{% endtabs %}

### TrackingRequest

void **TrackingRequest** (string key, string privacynotice, Closure callback, bool force=false)

*Displays a consent prompt (EULA-style) asking the user to allow tracking for a given key. On white-label grids, stores the user's choice and invokes the callback with a boolean indicating consent. On the main grid, this does nothing.*

| Parameter     | Type    | Description                                                                          |
| ------------- | ------- | ------------------------------------------------------------------------------------ |
| key           | string  | A unique identifier used to store and look up the user's tracking consent.           |
| privacynotice | string  | The privacy notice text to display in the consent dialog.                            |
| callback      | Closure | A function invoked with one boolean parameter: `true` if allowed, `false` otherwise. |
| force         | bool    | If `true`, show the prompt even if a stored decision exists. Defaults to `false`.    |

{% tabs %}
{% tab title="Lua" %}

```lua
-- Request consent (white-label only). The callback receives a boolean 'allowed'.
Space.TrackingRequest('24234234234234', 'A notice message', function(allowed)
    if allowed then
        Space.Log("Tracking allowed")
    else
        Space.Log("Tracking denied")
    end
end)
-- or force re-prompt even if a decision was saved previously:
Space.TrackingRequest('24234234234234', 'A notice message', function(allowed) end, true)
```

{% endtab %}
{% endtabs %}

### GetResource

[SResource](https://docs.sine.space/scripting/client-scripting-api-reference/types/sresource) **GetResource** (string name)

*Returns a reference to a SResource using it's Resource name.*

| Parameter | Type   | Description                                                                        |
| --------- | ------ | ---------------------------------------------------------------------------------- |
| name      | string | Name of the Resource as set in the Scripting Runtime Component (Resources section) |

{% tabs %}
{% tab title="Lua" %}

```lua
aResource = Space.GetResource("ResourceName")
```

{% endtab %}
{% endtabs %}

### LogEvent

void **LogEvent** (string eventName, float value, [SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) position)

*Logs an analytics event to the server on white-label grids.*

| Parameter | Type    | Description                                   |
| --------- | ------- | --------------------------------------------- |
| eventName | string  | The name of the analytics event.              |
| value     | float   | A numeric value associated with the event.    |
| position  | SVector | A world position to associate with the event. |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.LogEvent('event name', 2.0, Vector.New(0,0,0) )
```

{% endtab %}
{% endtabs %}

### Log

void **Log** (DynValue text, bool logToFile=false)\
void **Log** (string text, bool logToFile=false)

*Log a message to console.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Log(Color.Blue)
--or
Space.Log("Log")
--or
Space.Log("Log",true)
```

{% endtab %}
{% endtabs %}

## Properties

### Inventory

[SInventory](https://docs.sine.space/scripting/client-scripting-api-reference/player/sinventory) **Inventory** `get`

*Allows access to the users inventory*

{% tabs %}
{% tab title="Lua" %}

```lua
inventory  = Space.Inventory
```

{% endtab %}
{% endtabs %}

### Persistence

[SPersistence](https://docs.sine.space/scripting/client-scripting-api-reference/region/spersistence) **Persistence** `get`

*Stores information between user sessions, and for other users*

{% tabs %}
{% tab title="Lua" %}

<pre class="language-lua"><code class="lang-lua"><strong>persistence = Space.Persistence
</strong></code></pre>

{% endtab %}
{% endtabs %}

### Scene

[SScene](https://docs.sine.space/scripting/client-scripting-api-reference/region/sscene) **Scene** `get`

*Allows access to the current scene graph (objects and avatars in the scene, and other information)*

{% tabs %}
{% tab title="Lua" %}

```lua
scene = Space.Scene
```

{% endtab %}
{% endtabs %}

### Grid

[SGrid](https://docs.sine.space/scripting/client-scripting-api-reference/region/sgrid) **Grid** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
grid = Space.Grid
```

{% endtab %}
{% endtabs %}

### Host

[SHost](https://docs.sine.space/scripting/client-scripting-api-reference/region/shost) **Host** `get`

*Access information about the current scripting runtime host*

{% tabs %}
{% tab title="Lua" %}

```lua
host = Space.Host
```

{% endtab %}
{% endtabs %}

### Physics

[SPhysics](https://docs.sine.space/scripting/client-scripting-api-reference/region/sphysics) **Physics** `get`

*Call physics-related commands, and variables, such as raycasting*

{% tabs %}
{% tab title="Lua" %}

```lua
physics = Space.Physics
```

{% endtab %}
{% endtabs %}

### Math

[SMath](https://docs.sine.space/scripting/client-scripting-api-reference/types/smath) **Math** `get`

*Math related functions (Sin, Cos, Tan, etc)*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Math.Ceil(4.0)
```

{% endtab %}
{% endtabs %}

### String

[SString](https://docs.sine.space/scripting/client-scripting-api-reference/types/sstring) **String** `get`

*Miscellaneous additional string functions (e.g. MD5Sum)*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.String.GetBytes("some data")
```

{% endtab %}
{% endtabs %}

### Input

[SInput](https://docs.sine.space/scripting/client-scripting-api-reference/client/sinput) **Input** `get`

*Input device related functions (mouse position, keyboard state)*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Input.Vibrate(1,1,false)
```

{% endtab %}
{% endtabs %}

### Camera

[SCameraManager](https://docs.sine.space/scripting/client-scripting-api-reference/region/scameramanager) **Camera** `get`

*Take and control the users camera*

{% tabs %}
{% tab title="Lua" %}

```lua
obj = Space.Host.ExecutingObject
Space.Camera.LockCamera (obj)
```

{% endtab %}
{% endtabs %}

### WebServices

[SWebService](https://docs.sine.space/scripting/client-scripting-api-reference/network/swebservice) **WebServices** `get`

*Call remote web services to designated hosts (will not work with arbitrary domains, see page for details)*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.WebServices.GetImage("example.com/mrlee.jpg")
```

{% endtab %}
{% endtabs %}

### Network

[SNetwork](https://docs.sine.space/scripting/client-scripting-api-reference/network/snetwork) **Network** `get`

*Send data to other clients through the region server*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Network.SubscribeToNetwork("helloworld", gotAMessageFunction)
```

{% endtab %}
{% endtabs %}

### PostFX

[SPostFX](https://docs.sine.space/scripting/client-scripting-api-reference/region/spostfx) **PostFX** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.PostFX
```

{% endtab %}
{% endtabs %}

### AudioAnalyser

SAudioAnalyser **AudioAnalyser** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.AudioAnalyser
```

{% endtab %}
{% endtabs %}

### Tween

STween **Tween** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Tween
```

{% endtab %}
{% endtabs %}

### UI

[SUI](https://docs.sine.space/scripting/client-scripting-api-reference/client/sui) **UI** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
ui = Space.UI
```

{% endtab %}
{% endtabs %}

### Dialogues

[SDialogues](https://docs.sine.space/scripting/client-scripting-api-reference/client/sdialogues) **Dialogues** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
dialogues = Space.Dialogues
```

{% endtab %}
{% endtabs %}

### Shared

[SShared](https://docs.sine.space/scripting/client-scripting-api-reference/client/sshared) **Shared** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
shared = Space.Shared
```

{% endtab %}
{% endtabs %}

### Quests

[SQuests](https://docs.sine.space/scripting/client-scripting-api-reference/player/squests) **Quests** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
quests = Space.Quests
```

{% endtab %}
{% endtabs %}

### Economy

[SEconomy](https://docs.sine.space/scripting/client-scripting-api-reference/player/seconomy) **Economy** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
economy = Space.Economy
```

{% endtab %}
{% endtabs %}

### Groups

[SGroup](https://docs.sine.space/scripting/client-scripting-api-reference/player/sgroup) **Groups** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
groups = Space.Groups
```

{% endtab %}
{% endtabs %}

### Activity

SActivity **Activity** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

<pre class="language-lua"><code class="lang-lua"><strong>activity = Space.Activity
</strong></code></pre>

{% endtab %}
{% endtabs %}

### RenderSettings

[SRenderSettings](https://docs.sine.space/scripting/client-scripting-api-reference/region/srendersettings) **RenderSettings** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
renderSettings = Space.RenderSettings
```

{% endtab %}
{% endtabs %}

### Profile

[SProfile](https://docs.sine.space/scripting/client-scripting-api-reference/player/sprofile) **Profile** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
profile = Space.Profile
```

{% endtab %}
{% endtabs %}

### Photos

[SPhotos](https://docs.sine.space/scripting/client-scripting-api-reference/network/sphotos) **Photos** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
photos = Space.Photos
```

{% endtab %}
{% endtabs %}

### Videos

[SVideos](https://docs.sine.space/scripting/client-scripting-api-reference/network/svideos) **Videos** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
videos = Space.Videos
```

{% endtab %}
{% endtabs %}

### MusicDirectory

SMusicDirectory **MusicDirectory** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
musicDirectory = Space.MusicDirectory
```

{% endtab %}
{% endtabs %}

### Journey

SJourney **Journey** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
journey = Space.Journey
```

{% endtab %}
{% endtabs %}

### GameTester

SGameTester **GameTester** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
gameTester = Space.GameTester
```

{% endtab %}
{% endtabs %}

### RuntimeType

string **RuntimeType** `get`

*Return current RuntimeType name.*

{% tabs %}
{% tab title="Lua" %}

```lua
runtimeType = Space.RuntimeType
```

{% endtab %}
{% endtabs %}

### Platform

string **Platform** `get`

*Return current platform name.*

{% tabs %}
{% tab title="Lua" %}

```lua
platform = Space.Platform
```

{% endtab %}
{% endtabs %}

### SessionID

string **SessionID** `get`

*Return current SessionID.*

{% tabs %}
{% tab title="Lua" %}

```lua
sessionID = Space.SessionID
```

{% endtab %}
{% endtabs %}

### InEditor

bool **InEditor** `get`

*Return true if in unity editor.*

{% tabs %}
{% tab title="Lua" %}

```lua
isInEditor = Space.InEditor
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### Version

int **Version** `get`

*Returns the numeric build version of the viewer (for programmatic comparisons). In the Unity Editor this returns `int.MaxValue`; if unknown at runtime it returns `-1`.*

{% tabs %}
{% tab title="Lua" %}

```lua
viewerVersion = Space.Version
```

{% endtab %}
{% endtabs %}

### FullVersionString

string **FullVersionString** `get`

*Returns the full build version display string tied to release notes (e.g., "2025.6f210"). Best for user-facing display and logging.*

{% tabs %}
{% tab title="Lua" %}

```lua
viewerVersionString = Space.FullVersionString
```

{% endtab %}
{% endtabs %}

### Resources

[SResource](https://docs.sine.space/scripting/client-scripting-api-reference/types/sresource)\[] **Resources** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
tableOfResources = Space.Resources
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### Time

float **Time** `get`

*Returns time at the beginning of this frame.*

{% tabs %}
{% tab title="Lua" %}

```lua
floatTime = Space.Time
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### ServerTime

string **ServerTime** `get`

*Returns current server time.*

{% tabs %}
{% tab title="Lua" %}

```lua
serverTime = Space.ServerTime
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### LocalTime

string **LocalTime** `get`

*Returns current local time.*

{% tabs %}
{% tab title="Lua" %}

```lua
localTime = Space.LocalTime
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### LoginTime

float **LoginTime** `get`

*Returns how long player has been logged in (in seconds).*

{% tabs %}
{% tab title="Lua" %}

```lua
loginTime = Space.LoginTime
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### ServerTimeUnix

int **ServerTimeUnix** `get`

*Returns the server time unix timestamp.*

{% tabs %}
{% tab title="Lua" %}

```lua
serverTimeUnix = Space.ServerTimeUnix
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### LocalTimeUnix

int **LocalTimeUnix** `get`

*Returns the local time unix timestamp.*

{% tabs %}
{% tab title="Lua" %}

```lua
localTimeUnix = Space.LocalTimeUnix
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### DeltaTime

float **DeltaTime** `get`

*The completion time in seconds since the last frame.*

{% tabs %}
{% tab title="Lua" %}

```lua
deltaTime = Space.DeltaTime
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### PreviewServer

bool **PreviewServer** `get`

*Return true if in preview server.*

{% tabs %}
{% tab title="Lua" %}

```lua
isInPreview = Space.PreviewServer
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### ComponentName

string **ComponentName** `get`

*The name of this component.*

{% tabs %}
{% tab title="Lua" %}

```lua
componentName = Space.ComponentName
```

{% endtab %}
{% endtabs %}
