wiki.sine.space | sinespace

Difference between revisions of "Scripting/LUA"

From wiki.sine.space
Jump to: navigation, search
(Notes on the Lua implementation)
Line 7: Line 7:
 
* Using coroutines or binding to a regularly firing event (e.g. OnUpdate()) is a way of continuing a long running script.
 
* Using coroutines or binding to a regularly firing event (e.g. OnUpdate()) is a way of continuing a long running script.
 
* Scripts run in the client (for server scripts see [[Scripting/Server Scripts]])
 
* Scripts run in the client (for server scripts see [[Scripting/Server Scripts]])
 +
 +
==Creating a Lua Script in Space==
 +
'''Note: This documentation refers to the first fruits of Lua scripting in Space, and as such, it and everything it describes is subject to change at just about any time'''
 +
 +
* Lua scripts can be attached to any Game Object. This is done by selecting the game object, and in the inspector, "Add Component->Scripts->Scripting Runtime" (don't let it fool you that it has a little C# icon).
 +
* Lua requires no preamble or compiler directives (at this time, at least), so no 'using' or 'includes' lines -- everything inherits from the parent Space object.
 +
* Having attached the scripting runtime to your object, when you examine it via the inspector you will see an empty source code box, among other things (we'll get into those later). Thats where you type or paste your script source code. It will be saved with the scene, just like any other object property.
 +
* In the Project tree, if you search 'Scripting Example' you will find a scene. In that scene is an empty game object with a sample 'Hello World' script attached. A quick exposition of the script's operational elements is provided following.
 +
 +
==Example Lua Script==
 +
Blah, blah blah. More blah.
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 05:44, 26 January 2017

Space supports two separate scripting runtimes - Lua and C#; for most uses, we strongly recommending using the Lua variant, as it is cross-platform compatible. (C#/.NET only work for Standalone clients). Our Lua runtime runs optimally in all platforms including WebGL; and utilises the same API as the C# variant.

Note: We had originally announced JavaScript as our cross-platform runtime, however after implementation we've found our Lua runtime performs considerably better and with greater stability.

Notes on the Lua implementation

  • We do not place many limits on scripts, however scripts must return execution context every 5000 (configurable) instruction cycles (scripts are run in a deterministic single-threaded manner for compatibility with HTML5/WebGL where threading does not yet exist). Exceeding this will have your script forcibly interrupted.
  • Using coroutines or binding to a regularly firing event (e.g. OnUpdate()) is a way of continuing a long running script.
  • Scripts run in the client (for server scripts see Scripting/Server Scripts)

Creating a Lua Script in Space

Note: This documentation refers to the first fruits of Lua scripting in Space, and as such, it and everything it describes is subject to change at just about any time

  • Lua scripts can be attached to any Game Object. This is done by selecting the game object, and in the inspector, "Add Component->Scripts->Scripting Runtime" (don't let it fool you that it has a little C# icon).
  • Lua requires no preamble or compiler directives (at this time, at least), so no 'using' or 'includes' lines -- everything inherits from the parent Space object.
  • Having attached the scripting runtime to your object, when you examine it via the inspector you will see an empty source code box, among other things (we'll get into those later). Thats where you type or paste your script source code. It will be saved with the scene, just like any other object property.
  • In the Project tree, if you search 'Scripting Example' you will find a scene. In that scene is an empty game object with a sample 'Hello World' script attached. A quick exposition of the script's operational elements is provided following.

Example Lua Script

Blah, blah blah. More blah.