wiki.sine.space | sinespace

Difference between revisions of "Scripting/SScript"

From wiki.sine.space
Jump to: navigation, search
(Added simple examples to 15 members in SScript)
Line 81: Line 81:
 
}}
 
}}
  
{{ScriptFunction|float|DeltaTime|[get;]|The completion time in seconds since the last frame.|Space.Log(Space.DeltaTime)
+
{{ScriptFunction|float|DeltaTime|[get;]|The completion time in seconds since the last frame.|Space.Log(Space.DeltaTime)|6= <pre>--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.SubscribeToEvents()
 +
thisGameObject.OnUpdate(OnUpdate)</pre>
 
}}
 
}}
  

Revision as of 15:17, 12 July 2021

The 'Space' global accessible in every script (for C# scripts, this inherits from the SpaceScript base class)

Attributes

Inventory

SInventory Inventory { get; }

Allows access to the users inventory

Space.Inventory.Authorize()


Persistence

SPersistence Persistence { get; }

Stores information between user sessions, and for other users

Space.Persistence.RetrieveValue("value1")


Scene

SScene Scene { get; }

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

Space.Scene.PlayerAvatar


Host

SHost Host { get; }

Access information about the current scripting runtime host

Space.Host.StartCoroutine(CoFunc)


Physics

SPhysics Physics { get; }

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

Space.Physics.RayCast(trans.WorldPosition,trans.Forward,50)


Math

SMath Math { get; }

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

Space.Math.Ceil(4.0)


String

SString String { get; }

Miscellaneous additional string functions (e.g. MD5Sum)

Space.String.GetBytes("some data")


Input

SInput Input { get; }

Input device related functions (mouse position, keyboard state)

Space.Input.Vibrate(1,1,false)


CameraManager

SCameraManager CameraManager { get; }

Take and control the users camera

obj = Space.Host.ExecutingObject
Space.Camera.LockCamera (obj)


WebServices

SWebService WebServices { get; }

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

Space.WebServices.GetImage("example.com/mrlee.jpg")


Network

SNetwork Network { get; }

Send data to other clients through the region server

Space.Network.SubscribeToNetwork("helloworld", gotAMessageFunction)


Time

float Time { get; }

The current viewer time - this will usually correlate with the number of seconds the player has been in the current scene, increments each frame, typically used for animation/tweening

currentTime = Space.Time


ServerTime

DateTime ServerTime { get; }

The current server time - usually UTC, as according to the login server.

serverTime = Space.ServerTime


DeltaTime

float DeltaTime { get; }

The current time between this frame, and the previous frame, as used in Update, LateUpdate events, if moving a object, you can multiply it by DeltaTime to get a consistent speed

deltaTime = Space.DeltaTime


Log

void Log (string text);

Logs the message to the script debug console

Space.Log("Hello World!")


Members

GetResource

SResource GetResource {string name;}

Returns a resource with its name.

Space.Log(Space.GetResource("Texture").Name)

--Print "Texture" when it is exists.


Log

void Log {DynValue text;}

Log a message to console.

Space.Log("Log")

Space.Log("Log",true)


Properties

RuntimeType

string RuntimeType {get; }

Return current RuntimeType name.

Space.Log(Space.RuntimeType)


Platform

string Platform {get; }

Return current platform name.

Space.Log(Space.Platform)


TypeName

string TypeName {get; }

Return the type name of the value.

Space.Log(Space.TypeName("123"))


SessionID

string SessionID {get; }

Return current SessionID.

Space.Log(Space.SessionID)


TrackingAllowed

bool TrackingAllowed {string key;}

Always return false on the main grid.

Space.Log(Space.TrackingAllowed("YourKey"))


InEditor

bool InEditor [get;]

Return true if in unity editor.

Space.Log(Space.InEditor)


Resources

SResource Resources [get;]

Return all resources.

Space.Log(#Space.Resources)


Time

float Time [get;]

Returns time at the beginning of this frame.

Space.Log(Space.Time)


ServerTime

string ServerTime [get;]

Returns current server time.

Space.Log(Space.ServerTime)


LocalTime

string LocalTime [get;]

Returns current local time.

Space.Log(Space.LocalTime)


ServerTimeUnix

int ServerTimeUnix [get;]

Returns server unix timestamp.

Space.Log(Space.ServerTimeUnix)


LocalTimeUnix

int LocalTimeUnix [get;]

Returns local unix timestamp.

Space.Log(Space.LocalTimeUnix)


DeltaTime

float DeltaTime [get;]

The completion time in seconds since the last frame.

Space.Log(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.SubscribeToEvents()
thisGameObject.OnUpdate(OnUpdate)

PreviewServer

bool PreviewServer [get;]

Return true if in preview server.

Space.Log(Space.PreviewServer)