SRegionScript
Dans cette classeLog
- Fonctions
- Log
- Subscribe
To Network - Unsubscribe
From Network - Send
Message To All Client Scripts - Send
Message To Client Scripts - Start
Coroutine - Propriétés
- ScriptID
- InstanceID
- RegionID
- Scene
- Database
- Math
- Shared
- Web
Services - Runtime
Type - In
Editor - Time
Since Awake - Date
TimeUTC - Local
Time Unix - Server
Time Unix - Événements
- On
Avatar Join - On
Avatar Leave - On
Script Server Message
| Fonction | Log | Log a message to console. (only works on preview grid) |
| Fonction | SubscribeToNetwork | Subscribe to network messages on "key". |
| Fonction | UnsubscribeFromNetwork | Unsubscribe from network messages on "key". |
| Fonction | SendMessageToAllClientScripts | Sends a network message to all client scripts. |
| Fonction | SendMessageToClientScripts | Sends a network message to a client script belonging to a specific player |
| Fonction | StartCoroutine | Runs the given function as a coroutine. |
| Propriété | ScriptID | Returns a unique identifier of this script runtime. (can be found in "/list_scripts" window on preview.) |
| Propriété | InstanceID | Returns a unique identifier for the instance of the region. |
| Propriété | RegionID | Returns a unique identifier for the region. (Same ID seen in curator) |
| Propriété | Scene | Access to the SScene class methods and properties. |
| Propriété | Database | Access to the SDatabase class methods and properties. |
| Propriété | Math | Access to the SMath class methods and properties. |
| Propriété | Shared | Access to the SShared class methods and properties. |
| Propriété | WebServices | Access to the SWebservice class methods and properties. |
| Propriété | RuntimeType | Returns "Server" if this script is a Server script |
| Propriété | InEditor | Returns true if in Editor. (this will return false on server scripts) |
| Propriété | TimeSinceAwake | Time, in seconds, since this script runtime has been awake. |
| Propriété | DateTimeUTC | Returns a string of the current Date/Time in UTC |
| Propriété | LocalTimeUnix | Returns the current Unix time (in seconds) (same as ServerTimeUnix) |
| Propriété | ServerTimeUnix | Returns the current Unix time (in seconds) (same as LocalTimeUnix) |
| Événement | OnAvatarJoin | An event function which will be called whenever an Avatar joins and will also contain the Avatar's ID as a parameter. |
| Événement | OnAvatarLeave | An event function which will be called whenever an Avatar leaves and will also contain the Avatar's ID as a parameter. |
| Événement | 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. |
Fonctions
Log
Log a message to console. (only works on preview grid)
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| message | string | – |
Valeurs de retour
void
Exemple
Space.Log("Log")
--Clicking the object will make the server script log "Test Message" on all clients
--server script
function OnScriptServerMessage(key, table)
if key == "testKey" then
Space.Log("Message:" .. table[1])
end
end
--client script
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
Space.Network.SendNetworkMessage("testKey",{"Test Message"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
SubscribeToNetwork
Subscribe to network messages on "key".
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
Valeurs de retour
void
Exemple
Space.SubscribeToNetwork("thekey")
UnsubscribeFromNetwork
Unsubscribe from network messages on "key".
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| key | string | – |
Valeurs de retour
void
Exemple
Space.UnsubscribeFromNetwork("thekey")
SendMessageToAllClientScripts
Sends a network message to all client scripts.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| messageName | string | – |
| message | Table | – |
Valeurs de retour
void
Exemple
Space.SendMessageToAllClientScripts("thekey",{"themessage"})
--Clicking the object by a single client will send a message to the server which triggers a message response to all clients
--server script--
function OnScriptServerMessage(key, table)
if key == "testKey" then
Space.SendMessageToAllClientScripts("ServerResponse",{"message response to all client scripts in region that are subscribed to this key"})
end
end
--client script--
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
Space.Network.SendNetworkMessage("testKey",{"Test Message"})
end
OnReceiveFunction = function(SNetworkMessage)
Space.Log(SNetworkMessage.Key)
Space.Log(SNetworkMessage.Message[1])
end
Space.Network.SubscribeToNetwork("ServerResponse", OnReceiveFunction)
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
SendMessageToClientScripts
Sends a network message to a client script belonging to a specific player
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| playerID | ulong | – |
| messageName | string | – |
| message | Table | – |
Valeurs de retour
void
Exemple
Space.SendMessageToClientScripts(playerID,"thekey",{"themessage"})
--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--
function OnScriptServerMessage(key, table)
if key == "testKey" then
local sender = table[2]
Space.SendMessageToClientScripts(sender,"ServerResponse",{"a message response to the clicker's client script in region that is subscribed to this key"})
end
end
--client script--
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
id = Space.Scene.PlayerAvatar.ID
Space.Network.SendNetworkMessage("testKey",{"Test Message", id})
end
OnReceiveFunction = function(SNetworkMessage)
Space.Log(SNetworkMessage.Key)
Space.Log(SNetworkMessage.Message[1])
end
Space.Network.SubscribeToNetwork("ServerResponse", OnReceiveFunction)
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
StartCoroutine
Runs the given function as a coroutine. A parameter is optional.
Paramètres
| Nom | Type | Valeur par défaut |
|---|---|---|
| coroutine | DynValue | – |
| parameter | DynValue | default(DynValue) |
| name | string | – |
Valeurs de retour
void
Exemple
Space.StartCoroutine(AFunctionName)
--Clicking the object on client will trigger a 3 second countdown on server script using coroutine
--server script--
function OnScriptServerMessage(key, table)
if key == "testKey" and table[1] == "Timer" then
Space.StartCoroutine(TimerCoroutine)
end
end
function TimerCoroutine()
local time = 0
while time < 3 do
Space.Log(3-time)
time = time + 1
coroutine.yield(1)
end
end
--client script--
thisObject = Space.Host.ExecutingObject
function OnClickFunction()
Space.Network.SendNetworkMessage("testKey",{"Timer"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
Propriétés
ScriptIDLecture seule
Returns a unique identifier of this script runtime. (can be found in "/list_scripts" window on preview.)
Exemple
scriptID = Space.ScriptID
--Clicking the object on client will make the server script log it's ScriptID
--server script--
function OnScriptServerMessage(key, table)
if key == "testKey" and table[1] == "ScriptID" then
Space.Log(Space.ScriptID)
end
end
--client script--
thisObject = Space.Host.ExecutingObject
function OnClickFunction()
Space.Network.SendNetworkMessage("testKey",{"ScriptID"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
InstanceIDLecture seule
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.
Exemple
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--
function OnScriptServerMessage(key, table)
local instanceID = Space.InstanceID
if key == "testKey" and table[1] == "ScriptID" and table[2] == instanceID then
Space.Log(instanceID)
end
end
--client script--
thisObject = Space.Host.ExecutingObject
function OnClickFunction()
local instanceID = Space.Scene.InstanceID
Space.Network.SendNetworkMessage("testKey",{"ScriptID", instanceID})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
RegionIDLecture seule
Returns a unique identifier for the region. (Same ID seen in curator)
Exemple
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--
function OnScriptServerMessage(key, table)
local RegionID = Space.RegionID
if key == "testKey" and table[1] == "ScriptID" and table[2] == RegionID then
Space.Log(RegionID)
end
end
--client script--
thisObject = Space.Host.ExecutingObject
function OnClickFunction()
local RegionID = Space.Scene.RegionID
Space.Network.SendNetworkMessage("testKey",{"ScriptID", RegionID})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
SceneLecture seule
Access to the SScene class methods and properties.
Exemple
Space.Scene
DatabaseLecture seule
Access to the SDatabase class methods and properties.
Exemple
Space.Database
MathLecture seule
Access to the SMath class methods and properties.
Exemple
Space.Math
SharedLecture seule
Access to the SShared class methods and properties.
Exemple
Space.Shared
WebServicesLecture seule
Access to the SWebservice class methods and properties.
Exemple
Space.WebServices
RuntimeTypeLecture seule
Returns "Server" if this script is a Server script
Exemple
type = Space.RuntimeType
InEditorLecture seule
Returns true if in Editor. (this will return false on server scripts)
Exemple
IsInEditor = Space.InEditor
TimeSinceAwakeLecture seule
Time, in seconds, since this script runtime has been awake.
Exemple
SecondsAwake = Space.TimeSinceAwake
--Clicking the object will make the server script log it's TimeSinceAwake on all clients
--server script
function OnScriptServerMessage(key, table)
if key == "testKey" and table[1] == "TimeSinceAwake" then
Space.Log(Space.TimeSinceAwake)
end
end
--client script
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
Space.Network.SendNetworkMessage("testKey",{"TimeSinceAwake"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
DateTimeUTCLecture seule
Returns a string of the current Date/Time in UTC
Exemple
DateAndTime = Space.DateTimeUTC
--Clicking the object will make the server script log it's DateTimeUTC on all clients
--server script
function OnScriptServerMessage(key, table)
if key == "testKey" and table[1] == "DateTimeUTC" then
Space.Log(Space.DateTimeUTC)
end
end
--client script
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
Space.Network.SendNetworkMessage("testKey",{"DateTimeUTC"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
LocalTimeUnixLecture seule
Returns the current Unix time (in seconds) (same as ServerTimeUnix)
Exemple
unixtime = Space.LocalTimeUnix
--Clicking the object will make the server script log it's LocalTimeUnix on all clients
--server script
function OnScriptServerMessage(key, table)
if key == "testKey" and table[1] == "LocalTimeUnix" then
Space.Log(Space.LocalTimeUnix)
end
end
--client script
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
Space.Network.SendNetworkMessage("testKey",{"LocalTimeUnix"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
ServerTimeUnixLecture seule
Returns the current Unix time (in seconds) (same as LocalTimeUnix)
Exemple
unixtime = Space.ServerTimeUnix
--Clicking the object will make the server script log it's ServerTimeUnix on all clients
--server script
function OnScriptServerMessage(key, table)
if key == "testKey" and table[1] == "ServerTimeUnix" then
Space.Log(Space.ServerTimeUnix)
end
end
--client script
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
Space.Network.SendNetworkMessage("testKey",{"ServerTimeUnix"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)
Événements
OnAvatarJoin
An event function which will be called whenever an Avatar joins and will also contain the Avatar's ID as a parameter.
Exemple
function OnAvatarJoin(playerID)
end
function OnAvatarJoin(id)
local numOfAvatars = Space.Scene.ConnectedAvatars
Space.Log("Avatar with ID " .. id .. "has joined")
Space.Log("Number of avatars connected: " .. numOfAvatars)
end
OnAvatarLeave
An event function which will be called whenever an Avatar leaves and will also contain the Avatar's ID as a parameter.
Exemple
function OnAvatarLeave(playerID)
end
function OnAvatarLeave(id)
local numOfAvatars = Space.Scene.ConnectedAvatars
Space.Log("Avatar with ID " .. id .. "has left")
Space.Log("Number of avatars connected: " .. numOfAvatars)
end
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.
Exemple
function OnScriptServerMessage(key, table)
theKeyString = key
theSNetworkMessageTable = table
end
--Clicking the object will make the server script log "Test Message" on all clients
--server script
function OnScriptServerMessage(key, table)
if key == "testKey" then
Space.Log("Message:" .. table[1])
end
end
--client script
thisObject = Space.Host.ExecutingObject
OnClickFunction = function()
Space.Network.SendNetworkMessage("testKey",{"Test Message"})
end
thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClickFunction)



