wiki.sine.space | sinespace

Difference between revisions of "Scripting/Server/SRegionScript"

From wiki.sine.space
Jump to: navigation, search
Line 2: Line 2:
 
=Public Member Functions=
 
=Public Member Functions=
  
{{ScriptFunction|void|Log|(string message);|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|void|Log|(string message);|Log a message to console. (only works on preview grid)|5=<pre>Space.Log("Log")</pre>|6=<pre></pre>}}
  
  
{{ScriptFunction|void|SubscribeToNetwork|(string key);|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|void|SubscribeToNetwork|(string key);|Subscribe to network messages on "key".|5=<pre>Space.SubscribeToNetwork("thekey")</pre>|6=<pre></pre>}}
  
  
{{ScriptFunction|void|UnsubscribeFromNetwork|(string key);|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|void|UnsubscribeFromNetwork|(string key);|Unsubscribe from network messages on "key".|5=<pre>Space.UnsubscribeFromNetwork("thekey")</pre>|6=<pre></pre>}}
  
  
{{ScriptFunction|void|SendMessageToAllClientScripts|(string messageName, Table message);|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|void|SendMessageToAllClientScripts|(string messageName, Table message);|Sends a network message to all client scripts.|5=<pre>Space.SendMessageToAllClientScripts("thekey",{"themessage"})</pre>|6=<pre></pre>}}
  
  
{{ScriptFunction|void|SendMessageToClientScripts|(int playerID, string messageName, Table message);|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|void|SendMessageToClientScripts|(int playerID, string messageName, Table message);|Sends a network message to a client script belonging to a specific player|5=<pre>Space.SendMessageToAllClientScripts(APlayerID,"thekey",{"themessage"})</pre>|6=<pre></pre>}}
  
 +
{{ScriptFunction|void|StartCoroutine|(<nowiki>string name, DynValue parameter=default(DynValue))</nowiki>;|Runs the given function as a coroutine. A parameter is optional.|5=<pre>Space.StartCoroutine("AFunctionName")</pre>|6=<pre></pre>}}
  
{{ScriptFunction|void|StartCoroutine|(<nowiki>DynValue coroutine, DynValue parameter=default(DynValue)</nowiki>);|description|5=<pre></pre>|6=<pre></pre>}}
 
  
 +
=Public Attributes=
  
{{ScriptFunction|void|StartCoroutine|(<nowiki>string name, DynValue parameter=default(DynValue))</nowiki>;|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|string|ScriptID|{ get; }|Returns a unique identifier of this script runtime.|5=<pre></pre>|6=<pre></pre>}}
  
 +
{{ScriptFunction|int|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. |5=<pre>instance = Space.InstanceID</pre>|6=<pre></pre>}}
  
=Public Attributes=
+
{{ScriptFunction|int|RegionID|{ get; }|Returns a unique identifier for the region. (Same ID seen in curator)|5=<pre>region = Space.RegionID</pre>|6=<pre></pre>}}
  
{{ScriptFunction|string|ScriptID|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|SScene|Scene|{ get; }|Access to the SScene class methods and properties.|5=<pre>Space.Scene</pre>|6=<pre></pre>}}
  
{{ScriptFunction|int|InstanceID|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|SDatabase|Database|{ get; }|Access to the SDatabase class methods and properties.|5=<pre>Space.Database</pre>|6=<pre></pre>}}
  
{{ScriptFunction|int|RegionID|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|SMath|Math|{ get; }|Access to the SMath class methods and properties.|5=<pre>Space.Math</pre>|6=<pre></pre>}}
  
{{ScriptFunction|SScene|Scene|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|SShared|Shared|{ get; }|Access to the SShared class methods and properties.|5=<pre>Space.Shared</pre>|6=<pre></pre>}}
  
{{ScriptFunction|SDatabase|Database|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|SWebservice|WebServices|{ get; }|Access to the SWebservice class methods and properties.|5=<pre>Space.WebServices</pre>|6=<pre></pre>}}
  
{{ScriptFunction|SMath|Math|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|string|RuntimeType|{ get;}|Returns "Server" if this script is a Server script|5=<pre>type = Space.RuntimeType</pre>|6=<pre></pre>}}
  
{{ScriptFunction|SShared|Shared|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|bool|InEditor|{ get; }|Returns true if in Editor. (this will return false on server scripts)|5=<pre>IsInEditor = Space.InEditor</pre>|6=<pre></pre>}}
  
{{ScriptFunction|SWebservice|WebServices|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|float|TimeSinceAwake|{ get;}|Time, in seconds, since this script runtime has been awake.|5=<pre>SecondsAwake = Space.TimeSinceAwake</pre>|6=<pre></pre>}}
  
{{ScriptFunction|string|RuntimeType|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|string|DateTimeUTC|{ get; }|Returns a string of the current Date/Time in UTC|5=<pre>DateAndTime = Space.DateTimeUTC</pre>|6=<pre></pre>}}
  
{{ScriptFunction|bool|InEditor|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|int|LocalTimeUnix|{ get; }|Returns the current Unix time (in seconds) (same as ServerTimeUnix)|5=<pre>unixtime = Space.LocalTimeUnix</pre>|6=<pre></pre>}}
  
{{ScriptFunction|float|TimeSinceAwake|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|int|ServerTimeUnix|{ get; }|Returns the current Unix time (in seconds) (same as LocalTimeUnix)|5=<pre>unixtime = Space.ServerTimeUnix</pre>|6=<pre></pre>}}
  
{{ScriptFunction|string|DateTimeUTC|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
 
  
{{ScriptFunction|int|LocalTimeUnix|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
=Events=
  
{{ScriptFunction|int|ServerTimeUnix|{ get;set; }|description|5=<pre></pre>|6=<pre></pre>}}
+
Server script events are "Magic methods" which, unlike client scripts, you don't have to bind or subscribe to. They will be called as long as you have their methods implemented in your server script.
  
 +
{{ScriptFunction|<nowiki>Action<int></nowiki>|OnAvatarJoin||An event function which will be called whenever an Avatar joins and will also contain the Avatar's ID as a parameter.|5=<pre>function OnAvatarJoin(playerID)
  
=Events=
+
player = playerID
 +
 
 +
 
 +
end</pre>|6=<pre></pre>}}
 +
 
 +
{{ScriptFunction|<nowiki>Action<int></nowiki>|OnAvatarLeave||An event function which will be called whenever an Avatar leaves and will also contain the Avatar's ID as a parameter.|5=<pre>function OnAvatarLeave(playerID)
 +
 
 +
player = playerID
 +
 
 +
 
 +
end</pre>|6=<pre></pre>}}
  
{{ScriptFunction|<nowiki>Action<int></nowiki>|OnAvatarJoin||description|5=<pre></pre>|6=<pre></pre>}}
+
{{ScriptFunction|<nowiki>Action<string, Table></nowiki>|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. |5=<pre>function OnScriptServerMessage(key, table)
  
{{ScriptFunction|<nowiki>Action<int></nowiki>|OnAvatarLeave||description|5=<pre></pre>|6=<pre></pre>}}
+
theKeyString = key
 +
theSNetworkMessageTable = table
  
{{ScriptFunction|<nowiki>Action<string, Table></nowiki>|OnScriptServerMessage||description|5=<pre></pre>|6=<pre></pre>}}
+
end</pre>|6=<pre></pre>}}
  
  
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 11:44, 22 February 2022

Public Member Functions

Log

void Log (string message);

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

Space.Log("Log")



SubscribeToNetwork

void SubscribeToNetwork (string key);

Subscribe to network messages on "key".

Space.SubscribeToNetwork("thekey")



UnsubscribeFromNetwork

void UnsubscribeFromNetwork (string key);

Unsubscribe from network messages on "key".

Space.UnsubscribeFromNetwork("thekey")



SendMessageToAllClientScripts

void SendMessageToAllClientScripts (string messageName, Table message);

Sends a network message to all client scripts.

Space.SendMessageToAllClientScripts("thekey",{"themessage"})



SendMessageToClientScripts

void SendMessageToClientScripts (int playerID, string messageName, Table message);

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

Space.SendMessageToAllClientScripts(APlayerID,"thekey",{"themessage"})


StartCoroutine

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

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

Space.StartCoroutine("AFunctionName")



Public Attributes

ScriptID

string ScriptID { get; }

Returns a unique identifier of this script runtime.


InstanceID

int 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.

instance = Space.InstanceID


RegionID

int RegionID { get; }

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

region = Space.RegionID


Scene

SScene Scene { get; }

Access to the SScene class methods and properties.

Space.Scene


Database

SDatabase Database { get; }

Access to the SDatabase class methods and properties.

Space.Database


Math

SMath Math { get; }

Access to the SMath class methods and properties.

Space.Math


Shared

SShared Shared { get; }

Access to the SShared class methods and properties.

Space.Shared


WebServices

SWebservice WebServices { get; }

Access to the SWebservice class methods and properties.

Space.WebServices


RuntimeType

string RuntimeType { get;}

Returns "Server" if this script is a Server script

type = Space.RuntimeType


InEditor

bool InEditor { get; }

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

IsInEditor = Space.InEditor


TimeSinceAwake

float TimeSinceAwake { get;}

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

SecondsAwake = Space.TimeSinceAwake


DateTimeUTC

string DateTimeUTC { get; }

Returns a string of the current Date/Time in UTC

DateAndTime = Space.DateTimeUTC


LocalTimeUnix

int LocalTimeUnix { get; }

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

unixtime = Space.LocalTimeUnix


ServerTimeUnix

int ServerTimeUnix { get; }

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

unixtime = Space.ServerTimeUnix



Events

Server script events are "Magic methods" which, unlike client scripts, you don't have to bind or subscribe to. They will be called as long as you have their methods implemented in your server script.

OnAvatarJoin

[[Scripting/Action<int>|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.

function OnAvatarJoin(playerID)

player = playerID


end


OnAvatarLeave

[[Scripting/Action<int>|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.

function OnAvatarLeave(playerID)

player = playerID


end


OnScriptServerMessage

[[Scripting/Action<string, Table>|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.

function OnScriptServerMessage(key, table) 

theKeyString = key
theSNetworkMessageTable = table

end