Action< int > OnAvatarJoin \ Action< int > OnAvatarLeave \ Action< string, Table > OnScriptServerMessage
An event function which will be called whenever an Avatar joins and will also contain the Avatar's ID as a parameter.
Functions
Log
void Log (string message)
Log a message to console. (only works on preview grid)
Parameter
Type
Description
Space.Log("Log")
--Clicking the object will make the server script log "Test Message" on all clients--server scriptfunctionOnScriptServerMessage(key,table) if key =="testKey" then Space.Log("Message:" .. table[1])endend--client scriptthisObject = Space.Host.ExecutingObjectOnClickFunction=function() Space.Network.SendNetworkMessage("testKey",{"Test Message"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
--Clicking the object by a single client will send a message to the server which triggers a message response to all clients--server script--functionOnScriptServerMessage(key,table) if key =="testKey" then Space.SendMessageToAllClientScripts("ServerResponse",{"message response to all client scripts in region that are subscribed to this key"})endend--client script--thisObject = Space.Host.ExecutingObjectOnClickFunction=function() Space.Network.SendNetworkMessage("testKey",{"Test Message"}) endOnRecieveFunction=function(SNetworkMessage) Space.Log(SNetworkMessage.Key) Space.Log(SNetworkMessage.Message[1])endSpace.Network.SubscribeToNetwork("ServerResponse", OnRecieveFunction)thisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
--Clicking the object by a single client will send a message to the server which triggers...--a message response only to that specific client--server script--functionOnScriptServerMessage(key,table) if key =="testKey" thenlocal sender = table[2] Space.SendMessageToClientScripts(sender,"ServerResponse",{"a message response to the clicker's client script in region that is subscribed to this key"})endend--client script--thisObject = Space.Host.ExecutingObjectOnClickFunction=function() id = Space.Scene.PlayerAvatar.ID Space.Network.SendNetworkMessage("testKey",{"Test Message", id}) endOnRecieveFunction=function(SNetworkMessage) Space.Log(SNetworkMessage.Key) Space.Log(SNetworkMessage.Message[1])endSpace.Network.SubscribeToNetwork("ServerResponse", OnRecieveFunction)thisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
Runs the given function as a coroutine. A parameter is optional.
Parameter
Type
Description
Space.StartCoroutine(AFunctionName)
--Clicking the object on client will trigger a 3 second countdown on server script using coroutine--server script--functionOnScriptServerMessage(key,table) if key =="testKey" and table[1] =="Timer" then Space.StartCoroutine(TimerCoroutine)endendfunctionTimerCoroutine()local time =0while time <3do Space.Log(3-time) time = time +1coroutine.yield(1)endend--client script--thisObject = Space.Host.ExecutingObjectfunctionOnClickFunction() Space.Network.SendNetworkMessage("testKey",{"Timer"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
Properties
ScriptID
string ScriptIDget
Returns a unique identifier of this script runtime. (can be found in "/list_scripts" window on preview.)
scriptID = Space.ScriptID
--Clicking the object on client will make the server script log it's ScriptID--server script--functionOnScriptServerMessage(key,table) if key =="testKey" and table[1] =="ScriptID" then Space.Log(Space.ScriptID)endend--client script--thisObject = Space.Host.ExecutingObjectfunctionOnClickFunction() Space.Network.SendNetworkMessage("testKey",{"ScriptID"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
InstanceID
int InstanceIDget
Returns a unique identifier for the instance of the region. Useful in the case of multiple shards/instances being used. InstanceID does not necessarily equal to the RegionID, even if there's only one instance running.
instance = Space.InstanceID
--Clicking the object on client will make the server script log only...--if it's instanceID matches with client's instanceID--server script--functionOnScriptServerMessage(key,table) local instanceID = Space.InstanceIDif key =="testKey" and table[1] =="ScriptID" and table[2] == instanceID then Space.Log(instanceID)endend--client script--thisObject = Space.Host.ExecutingObjectfunctionOnClickFunction()local instanceID = Space.Scene.InstanceID Space.Network.SendNetworkMessage("testKey",{"ScriptID", instanceID}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
RegionID
int RegionIDget
Returns a unique identifier for the region. (Same ID seen in curator)
region = Space.RegionID
--Clicking the object on client will make the server script log only...--if it's RegionID matches with client's RegionID--server script--functionOnScriptServerMessage(key,table) local RegionID = Space.RegionIDif key =="testKey" and table[1] =="ScriptID" and table[2] == RegionID then Space.Log(RegionID)endend--client script--thisObject = Space.Host.ExecutingObjectfunctionOnClickFunction()local RegionID = Space.Scene.RegionID Space.Network.SendNetworkMessage("testKey",{"ScriptID", RegionID}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
Access to the SWebservice class methods and properties.
Space.WebServices
RuntimeType
string RuntimeTypeget
Returns "Server" if this script is a Server script
type = Space.RuntimeType
InEditor
bool InEditorget
Returns true if in Editor. (this will return false on server scripts)
IsInEditor = Space.InEditor
TimeSinceAwake
float TimeSinceAwakeget
Time, in seconds, since this script runtime has been awake.
SecondsAwake = Space.TimeSinceAwake
--Clicking the object will make the server script log it's TimeSinceAwake on all clients--server scriptfunctionOnScriptServerMessage(key,table) if key =="testKey" and table[1] =="TimeSinceAwake" then Space.Log(Space.TimeSinceAwake)endend--client scriptthisObject = Space.Host.ExecutingObjectOnClickFunction=function() Space.Network.SendNetworkMessage("testKey",{"TimeSinceAwake"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
DateTimeUTC
string DateTimeUTCget
Returns a string of the current Date/Time in UTC
DateAndTime = Space.DateTimeUTC
--Clicking the object will make the server script log it's DateTimeUTC on all clients--server scriptfunctionOnScriptServerMessage(key,table) if key =="testKey" and table[1] =="DateTimeUTC" then Space.Log(Space.DateTimeUTC)endend--client scriptthisObject = Space.Host.ExecutingObjectOnClickFunction=function() Space.Network.SendNetworkMessage("testKey",{"DateTimeUTC"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
LocalTimeUnix
int LocalTimeUnixget
Returns the current Unix time (in seconds) (same as ServerTimeUnix)
unixtime = Space.LocalTimeUnix
--Clicking the object will make the server script log it's LocalTimeUnix on all clients--server scriptfunctionOnScriptServerMessage(key,table) if key =="testKey" and table[1] =="LocalTimeUnix" then Space.Log(Space.LocalTimeUnix)endend--client scriptthisObject = Space.Host.ExecutingObjectOnClickFunction=function() Space.Network.SendNetworkMessage("testKey",{"LocalTimeUnix"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
ServerTimeUnix
int ServerTimeUnixget
Returns the current Unix time (in seconds) (same as LocalTimeUnix)
unixtime = Space.ServerTimeUnix
--Clicking the object will make the server script log it's ServerTimeUnix on all clients--server scriptfunctionOnScriptServerMessage(key,table) if key =="testKey" and table[1] =="ServerTimeUnix" then Space.Log(Space.ServerTimeUnix)endend--client scriptthisObject = Space.Host.ExecutingObjectOnClickFunction=function() Space.Network.SendNetworkMessage("testKey",{"ServerTimeUnix"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)
Events
OnAvatarJoin
Action< int > OnAvatarJoin
An event function which will be called whenever an Avatar joins and will also contain the Avatar's ID as a parameter.
functionOnAvatarJoin(playerID)end
functionOnAvatarJoin(id)local numOfAvatars = Space.Scene.ConnectedAvatars Space.Log("Avatar with ID " .. id .."has joined") Space.Log("Number of avatars connected: " .. numOfAvatars)end
OnAvatarLeave
Action< int > OnAvatarLeave
An event function which will be called whenever an Avatar leaves and will also contain the Avatar's ID as a parameter.
functionOnAvatarLeave(playerID)end
functionOnAvatarLeave(id)local numOfAvatars = Space.Scene.ConnectedAvatars Space.Log("Avatar with ID " .. id .."has left") Space.Log("Number of avatars connected: " .. numOfAvatars)end
OnScriptServerMessage
Action< string, Table > OnScriptServerMessage
An event function which will be called whenever the server script receives a Network Message, and will contain the network message key String and message Table as a parameter.
--Clicking the object will make the server script log "Test Message" on all clients--server scriptfunctionOnScriptServerMessage(key,table) if key =="testKey" then Space.Log("Message:" .. table[1])endend--client scriptthisObject = Space.Host.ExecutingObjectOnClickFunction=function() Space.Network.SendNetworkMessage("testKey",{"Test Message"}) endthisObject.AddClickable()thisObject.Clickable.OnClick(OnClickFunction)