Breakroom is now Sinewave Campus. Book a meeting

SRegionScript

الخادمالمشهد
في هذا الصنفLog
  1. الدوال
  2. Log
  3. SubscribeToNetwork
  4. UnsubscribeFromNetwork
  5. SendMessageToAllClientScripts
  6. SendMessageToClientScripts
  7. StartCoroutine
  8. الخصائص
  9. ScriptID
  10. InstanceID
  11. RegionID
  12. Scene
  13. Database
  14. Math
  15. Shared
  16. WebServices
  17. RuntimeType
  18. InEditor
  19. TimeSinceAwake
  20. DateTimeUTC
  21. LocalTimeUnix
  22. ServerTimeUnix
  23. الأحداث
  24. OnAvatarJoin
  25. OnAvatarLeave
  26. OnScriptServerMessage
الأعضاء 23
دالةLogLog a message to console. (only works on preview grid)
دالةSubscribeToNetworkSubscribe to network messages on "key".
دالةUnsubscribeFromNetworkUnsubscribe from network messages on "key".
دالةSendMessageToAllClientScriptsSends a network message to all client scripts.
دالةSendMessageToClientScriptsSends a network message to a client script belonging to a specific player
دالةStartCoroutineRuns the given function as a coroutine.
خاصيةScriptIDReturns a unique identifier of this script runtime. (can be found in "/list_scripts" window on preview.)
خاصيةInstanceIDReturns a unique identifier for the instance of the region.
خاصيةRegionIDReturns a unique identifier for the region. (Same ID seen in curator)
خاصيةSceneAccess to the SScene class methods and properties.
خاصيةDatabaseAccess to the SDatabase class methods and properties.
خاصيةMathAccess to the SMath class methods and properties.
خاصيةSharedAccess to the SShared class methods and properties.
خاصيةWebServicesAccess to the SWebservice class methods and properties.
خاصيةRuntimeTypeReturns "Server" if this script is a Server script
خاصيةInEditorReturns true if in Editor. (this will return false on server scripts)
خاصيةTimeSinceAwakeTime, in seconds, since this script runtime has been awake.
خاصيةDateTimeUTCReturns a string of the current Date/Time in UTC
خاصيةLocalTimeUnixReturns the current Unix time (in seconds) (same as ServerTimeUnix)
خاصيةServerTimeUnixReturns the current Unix time (in seconds) (same as LocalTimeUnix)
حدثOnAvatarJoinAn event function which will be called whenever an Avatar joins and will also contain the Avatar's ID as a parameter.
حدثOnAvatarLeaveAn event function which will be called whenever an Avatar leaves and will also contain the Avatar's ID as a parameter.
حدثOnScriptServerMessageAn 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.

الدوال​

Log​

void Log(string message)

Log a message to console. (only works on preview grid)

المعاملات

الاسمالنوعالقيمة الافتراضية
messagestring–

القيم المرجعة

void

مثال

Lua
Space.Log("Log")
Lua
--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​

void SubscribeToNetwork(string key)

Subscribe to network messages on "key".

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–

القيم المرجعة

void

مثال

Lua
Space.SubscribeToNetwork("thekey")

UnsubscribeFromNetwork​

void UnsubscribeFromNetwork(string key)

Unsubscribe from network messages on "key".

المعاملات

الاسمالنوعالقيمة الافتراضية
keystring–

القيم المرجعة

void

مثال

Lua
Space.UnsubscribeFromNetwork("thekey")

SendMessageToAllClientScripts​

void SendMessageToAllClientScripts(string messageName, Table message)

Sends a network message to all client scripts.

المعاملات

الاسمالنوعالقيمة الافتراضية
messageNamestring–
messageTable–

القيم المرجعة

void

مثال

Lua
Space.SendMessageToAllClientScripts("thekey",{"themessage"})
Lua
--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​

void SendMessageToClientScripts(ulong playerID, string messageName, Table message)

Sends a network message to a client script belonging to a specific player

المعاملات

الاسمالنوعالقيمة الافتراضية
playerIDulong–
messageNamestring–
messageTable–

القيم المرجعة

void

مثال

Lua
Space.SendMessageToClientScripts(playerID,"thekey",{"themessage"})
Lua
--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​

void StartCoroutine(DynValue coroutine, DynValue parameter = default(DynValue))
void StartCoroutine(string name, DynValue parameter = default(DynValue))

Runs the given function as a coroutine. A parameter is optional.

المعاملات

الاسمالنوعالقيمة الافتراضية
coroutineDynValue–
parameterDynValuedefault(DynValue)
namestring–

القيم المرجعة

void

مثال

Lua
Space.StartCoroutine(AFunctionName)
Lua
--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)

الخصائص​

ScriptIDللقراءة فقط​

string ScriptID {get; }

Returns a unique identifier of this script runtime. (can be found in "/list_scripts" window on preview.)

مثال

Lua
scriptID = Space.ScriptID
Lua
--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)

InstanceIDللقراءة فقط​

uint InstanceID {get; }

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.

مثال

Lua
instance = Space.InstanceID
Lua
--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)

RegionIDللقراءة فقط​

ulong RegionID {get; }

Returns a unique identifier for the region. (Same ID seen in curator)

مثال

Lua
region = Space.RegionID
Lua
--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)

Sceneللقراءة فقط​

SScene Scene {get; }

Access to the SScene class methods and properties.

مثال

Lua
Space.Scene

Databaseللقراءة فقط​

SDatabase Database {get; }

Access to the SDatabase class methods and properties.

مثال

Lua
Space.Database

Mathللقراءة فقط​

SMath Math {get; }

Access to the SMath class methods and properties.

مثال

Lua
Space.Math

Sharedللقراءة فقط​

SShared Shared {get; }

Access to the SShared class methods and properties.

مثال

Lua
Space.Shared

WebServicesللقراءة فقط​

SWebservice WebServices {get; }

Access to the SWebservice class methods and properties.

مثال

Lua
Space.WebServices

RuntimeTypeللقراءة فقط​

string RuntimeType {get; }

Returns "Server" if this script is a Server script

مثال

Lua
type = Space.RuntimeType

InEditorللقراءة فقط​

bool InEditor {get; }

Returns true if in Editor. (this will return false on server scripts)

مثال

Lua
IsInEditor = Space.InEditor

TimeSinceAwakeللقراءة فقط​

float TimeSinceAwake {get; }

Time, in seconds, since this script runtime has been awake.

مثال

Lua
SecondsAwake = Space.TimeSinceAwake
Lua
--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)

DateTimeUTCللقراءة فقط​

string DateTimeUTC {get; }

Returns a string of the current Date/Time in UTC

مثال

Lua
DateAndTime = Space.DateTimeUTC
Lua
--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)

LocalTimeUnixللقراءة فقط​

int LocalTimeUnix {get; }

Returns the current Unix time (in seconds) (same as ServerTimeUnix)

مثال

Lua
unixtime = Space.LocalTimeUnix
Lua
--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)

ServerTimeUnixللقراءة فقط​

int ServerTimeUnix {get; }

Returns the current Unix time (in seconds) (same as LocalTimeUnix)

مثال

Lua
unixtime = Space.ServerTimeUnix
Lua
--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)

الأحداث​

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.

مثال

Lua
function OnAvatarJoin(playerID)
end
Lua
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​

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.

مثال

Lua
function OnAvatarLeave(playerID)
end
Lua
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​

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.

مثال

Lua
function OnScriptServerMessage(key, table)

theKeyString = key
theSNetworkMessageTable = table

end
Lua
--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)