m |
|||
Line 199: | Line 199: | ||
}} | }} | ||
− | {{ScriptFunction|bool|PreviewServer|[get;]|Return true if in preview server.|5=<pre>Space.Log(Space.PreviewServer)</pre>|6=<pre></pre>}} | + | {{ScriptFunction|bool|PreviewServer|[get;]|Return true if in preview server.|5=<pre>Space.Log(Space.PreviewServer)</pre>|6=<pre>--this script will update a UIText object with "preview" or "live" depending |
+ | --whether we are on preview server or live server | ||
+ | --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] | ||
+ | |||
+ | text = Space.Host.GetReference("Text").UIText | ||
+ | |||
+ | OnUpdate = function() | ||
+ | if Space.PreviewServer then | ||
+ | text.Text = "Preview" | ||
+ | else | ||
+ | text.Text = "Live" | ||
+ | end | ||
+ | end | ||
+ | |||
+ | Space.Host.ExecutingObject.OnUpdate(OnUpdate)</pre>}} | ||
{{Scripting Navbox}} | {{Scripting Navbox}} |
The 'Space' global accessible in every script (for C# scripts, this inherits from the SpaceScript base class)
Allows access to the users inventory
Space.Inventory.Authorize()
Stores information between user sessions, and for other users
Space.Persistence.RetrieveValue("value1")
Allows access to the current scene graph (objects and avatars in the scene, and other information)
Space.Scene.PlayerAvatar
Access information about the current scripting runtime host
Space.Host.StartCoroutine(CoFunc)
Call physics-related commands, and variables, such as raycasting
Space.Physics.RayCast(trans.WorldPosition,trans.Forward,50)
Math related functions (Sin, Cos, Tan, etc)
Space.Math.Ceil(4.0)
Miscellaneous additional string functions (e.g. MD5Sum)
Space.String.GetBytes("some data")
Input device related functions (mouse position, keyboard state)
Space.Input.Vibrate(1,1,false)
Take and control the users camera
obj = Space.Host.ExecutingObject Space.Camera.LockCamera (obj)
Call remote web services to designated hosts (will not work with arbitrary domains, see page for details)
Space.WebServices.GetImage("example.com/mrlee.jpg")
Send data to other clients through the region server
Space.Network.SubscribeToNetwork("helloworld", gotAMessageFunction)
Returns a resource with its name.
--Print "Texture" when it is exists.
Log a message to console.
Space.Log("Log",true)
Return the type name of the value.
Return current RuntimeType name.
Return current platform name.
Return current SessionID.
Always return false on the main grid.
Return true if in unity editor.
--the below script checks if we are in Unity editor or in SS --this way we can provide an alternative --(Example: if we're using a function that doesn't work in Unity editor) thisGameObject = Space.Host.ExecutingObject if Space.InEditor then avatarUsername = "Player Name" else avatarUsername = Space.Scene.GetAvatar(thisGameObject.Owner).Username --example: this doesn't work in Editor end Space.Log(avatarUsername)
Return all resources.
--the below script will search through the Scripting Runtime's resources --and return the first instance of an Animation Clip --[You need to add a few resources to the scripting runtime and make one of them an animation] resources = Space.Resources for i = 1, #resources do if resources[i].Type == "AnimationClip" then Space.Log("Resource #".. i .. " is an Animation Clip. The resource name is: " .. resources[i].Name) break end end
Returns time at the beginning of this frame.
Space.Log(Space.Time)
--this script will update a UIText object with the current local time without using a coroutine --(example: clock ) --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] rateUpdate = 1.0 nextUpdate = 0.0 text = Space.Host.GetReference("Text").UIText OnUpdate = function() if Space.Time > nextUpdate then nextUpdate = Space.Time + rateUpdate text.Text = Space.LocalTime end } Space.Host.ExecutingObject.OnUpdate(OnUpdate)
Returns current server time.
--this script will update a UIText object with the current server time (UTC) --(example: clock) --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] text = Space.Host.GetReference("Text").UIText co = function() while true do text.Text = Space.ServerTime coroutine.yield(1) end end Space.Host.StartCoroutine(co)
Returns current local time.
--this script will update a UIText object with the current local time --(example: clock) --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] text = Space.Host.GetReference("Text").UIText co = function() while true do text.Text = Space.LocalTime coroutine.yield(1) end end Space.Host.StartCoroutine(co)
Returns the server time unix timestamp.
Space.Log(Space.ServerTimeUnix)
--this script will update a UIText object with the current server time unix timestamp --(example: clock) --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] text = Space.Host.GetReference("Text").UIText co = function() while true do text.Text = Space.ServerTimeUnix coroutine.yield(1) end end Space.Host.StartCoroutine(co)
Returns the local time unix timestamp.
Space.Log(Space.LocalTimeUnix)
--this script will update a UIText object with the current local time unix timestamp --(example: clock) --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] text = Space.Host.GetReference("Text").UIText co = function() while true do text.Text = Space.LocalTimeUnix coroutine.yield(1) end end Space.Host.StartCoroutine(co)
Returns how long player has been logged in (in seconds).
Space.Log(Space.LoginTime)
--this script will update a UIText object with how long the user has been logged in (in seconds) --(example: clock) --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] text = Space.Host.GetReference("Text").UIText co = function() while true do text.Text = Space.LoginTime coroutine.yield(1) end end Space.Host.StartCoroutine(co)
The completion time in seconds since the last frame.
--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.OnUpdate(OnUpdate)
Return true if in preview server.
Space.Log(Space.PreviewServer)
--this script will update a UIText object with "preview" or "live" depending --whether we are on preview server or live server --[UIText object needs to be added to the references section in the scripting runtime with name "Text"] text = Space.Host.GetReference("Text").UIText OnUpdate = function() if Space.PreviewServer then text.Text = "Preview" else text.Text = "Live" end end Space.Host.ExecutingObject.OnUpdate(OnUpdate)
|