(→Example Lua Script) |
|||
Line 17: | Line 17: | ||
==Example Lua Script== | ==Example Lua Script== | ||
− | + | Here's the view in the inspector pane of the GameObject to which the example script is attached, along with a particle system: | |
+ | |||
+ | [[File:Exampleluascript.png]] | ||
+ | |||
+ | That's the entire script in the source code box, it's really quite simple. | ||
+ | |||
+ | - The first line writes a text message on the console. | ||
+ | |||
+ | - The second line creates a script-local reference to the host object (the GameObject to which the script is attached). | ||
+ | |||
+ | - The next five lines set up a local variable referencing the host object's position, set the positional properties via the local variable, and finally store that position back to the host object, effectively setting it's position in world. | ||
+ | |||
+ | - after that, the attached particle system is invoked with 50 particles. | ||
+ | |||
+ | Note that in each of these operations, the reference to the host object has been used as a property selector. The last line uses a reference to the scene as a property selector, but does so directly, without creating any persistent references in advance of of doing so. | ||
+ | |||
+ | - That last line sets the text value to be rendered on the canvas in the hierarchy, producing the 'Hello World" message as 3D text rendered in the scene. | ||
+ | |||
+ | |||
+ | Hopefully this will be a sufficient 'jumping off point' for those of us eager to get busy with scripting interactive objects for Space. | ||
+ | |||
{{Scripting Navbox}} | {{Scripting Navbox}} |
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.
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
Here's the view in the inspector pane of the GameObject to which the example script is attached, along with a particle system:
That's the entire script in the source code box, it's really quite simple.
- The first line writes a text message on the console.
- The second line creates a script-local reference to the host object (the GameObject to which the script is attached).
- The next five lines set up a local variable referencing the host object's position, set the positional properties via the local variable, and finally store that position back to the host object, effectively setting it's position in world.
- after that, the attached particle system is invoked with 50 particles.
Note that in each of these operations, the reference to the host object has been used as a property selector. The last line uses a reference to the scene as a property selector, but does so directly, without creating any persistent references in advance of of doing so.
- That last line sets the text value to be rendered on the canvas in the hierarchy, producing the 'Hello World" message as 3D text rendered in the scene.
Hopefully this will be a sufficient 'jumping off point' for those of us eager to get busy with scripting interactive objects for Space.
|