All pages
Powered by GitBook
1 of 1

Loading...

SScript

Functions

TypeName

string TypeName (DynValue dv)

Return the type name of the value.

Parameter
Type
Description

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

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

GetResource

GetResource (string name)

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

Parameter
Type
Description

LogEvent

void LogEvent (string eventName, float value, position)

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

Parameter
Type
Description

Log

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

Log a message to console.

Parameter
Type
Description

Properties

Inventory

Inventory get

Allows access to the users inventory

Persistence

Persistence get

Stores information between user sessions, and for other users

Scene

Scene get

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

Grid

Grid get

Property Description

Host

Host get

Access information about the current scripting runtime host

Physics

Physics get

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

Math

Math get

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

String

String get

Miscellaneous additional string functions (e.g. MD5Sum)

Input

Input get

Input device related functions (mouse position, keyboard state)

Camera

Camera get

Take and control the users camera

WebServices

WebServices get

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

Network

Network get

Send data to other clients through the region server

PostFX

PostFX get

Property Description

AudioAnalyser

SAudioAnalyser AudioAnalyser get

Property Description

Tween

STween Tween get

Property Description

UI

UI get

Property Description

Dialogues

Dialogues get

Property Description

Shared

Shared get

Property Description

Quests

Quests get

Property Description

Economy

Economy get

Property Description

Groups

Groups get

Property Description

Activity

SActivity Activity get

Property Description

RenderSettings

RenderSettings get

Property Description

Profile

Profile get

Property Description

Photos

Photos get

Property Description

Videos

Videos get

Property Description

MusicDirectory

SMusicDirectory MusicDirectory get

Property Description

Journey

SJourney Journey get

Property Description

GameTester

SGameTester GameTester get

Property Description

RuntimeType

string RuntimeType get

Return current RuntimeType name.

Platform

string Platform get

Return current platform name.

SessionID

string SessionID get

Return current SessionID.

InEditor

bool InEditor get

Return true if in unity editor.

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.

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.

Resources

[] Resources get

Property Description

Time

float Time get

Returns time at the beginning of this frame.

ServerTime

string ServerTime get

Returns current server time.

LocalTime

string LocalTime get

Returns current local time.

LoginTime

float LoginTime get

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

ServerTimeUnix

int ServerTimeUnix get

Returns the server time unix timestamp.

LocalTimeUnix

int LocalTimeUnix get

Returns the local time unix timestamp.

DeltaTime

float DeltaTime get

The completion time in seconds since the last frame.

PreviewServer

bool PreviewServer get

Return true if in preview server.

ComponentName

string ComponentName get

The name of this component.

dv

DynValue

key

string

A unique identifier used to store and look up the user's tracking consent.

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

name

string

Name of the Resource as set in the Scripting Runtime Component (Resources section)

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.

SResource
SVector
SInventory
SPersistence
SScene
SGrid
SHost
SPhysics
SMath
SString
SInput
SCameraManager
SWebService
SNetwork
SPostFX
SUI
SDialogues
SShared
SQuests
SEconomy
SGroup
SRenderSettings
SProfile
SPhotos
SVideos
SResource
typeName = Space.TypeName("123")
isTrackingAllowed = Space.TrackingAllowed('3423423423423')

If true, show the prompt even if a stored decision exists. Defaults to false.

-- 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)
aResource = Space.GetResource("ResourceName")
Space.LogEvent('event name', 2.0, Vector.New(0,0,0) )
Space.Log(Color.Blue)
--or
Space.Log("Log")
--or
Space.Log("Log",true)
inventory  = Space.Inventory
persistence = Space.Persistence
scene = Space.Scene
grid = Space.Grid
host = Space.Host
physics = Space.Physics
Space.Math.Ceil(4.0)
Space.String.GetBytes("some data")
Space.Input.Vibrate(1,1,false)
obj = Space.Host.ExecutingObject
Space.Camera.LockCamera (obj)
Space.WebServices.GetImage("example.com/mrlee.jpg")
Space.Network.SubscribeToNetwork("helloworld", gotAMessageFunction)
Space.PostFX
Space.AudioAnalyser
Space.Tween
ui = Space.UI
dialogues = Space.Dialogues
shared = Space.Shared
quests = Space.Quests
economy = Space.Economy
groups = Space.Groups
activity = Space.Activity
renderSettings = Space.RenderSettings
profile = Space.Profile
photos = Space.Photos
videos = Space.Videos
musicDirectory = Space.MusicDirectory
journey = Space.Journey
gameTester = Space.GameTester
runtimeType = Space.RuntimeType
platform = Space.Platform
sessionID = Space.SessionID
isInEditor = Space.InEditor
--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)
viewerVersion = Space.Version
viewerVersionString = Space.FullVersionString
tableOfResources = Space.Resources
--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
floatTime = Space.Time
--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)
serverTime = Space.ServerTime
--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)
localTime = Space.LocalTime
--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)
loginTime = Space.LoginTime
--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)
serverTimeUnix = Space.ServerTimeUnix
--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)
localTimeUnix = Space.LocalTimeUnix
--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)
deltaTime = Space.DeltaTime
--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)
isInPreview = Space.PreviewServer
--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)
componentName = Space.ComponentName