-
Notifications
You must be signed in to change notification settings - Fork 433
Lua scripting
Lua script plugin provides an option to script using Lua. It provides a new type of component, which points to a lua script file. This file is executed when a game starts. Each component has lua sandboxed - it means that all variables and function are not accessible from other components unless they are put in the global table _G or accessed using Engine.getEnvironment.
Each script can contain function update(dt) and this function is called each frame.
UniverseContext g_universe_contextUniverse g_universeEngine g_engine
All scenes are visible to script as global variables, each with prefix "g_scene_" and ends with the name of a plugin, e.g.:
g_scene_rendererg_scene_animationg_scene_audiog_scene_physicsg_scene_lua_script
Other than standard lua types there is one more - Vec3. It is just table with three numbers.
-
Table Engine.getEnvironment(Scene scene, Entity entity)#620 void Engine.setEntityPosition(Universe univ, Entity entity, Vec3 position)void Engine.setEntityRotation(Universe univ, Entity entity, Vec3 axis, number angle)void Engine.setEntityLocalRotation(UniverseContext univ, Entity entity, Vec3 axis, number angle)void Engine.setRenderablePath(Scene scene, Component cmp, string path)number Engine.getInputActionValue(Engine engine, number action)void Engine.addInputAction(Engine engine, number action, number type, number key)Component Engine.createComponent(Scene scene, string type, Entity entity)void Engine.logError(string text)void Engine.logInfo(string text)Vec3 Engine.multVecQuat(Vec3 vec, Vec3 axis, number angle)Component Engine.getRenderable(Scene scene, Entity entity)void Engine.destroyComponent(Scene scene, string type, Component component)
void Physics.moveController(Scene scene, Component cmp, Vec3 velocity, number time_delta)number Physics.getActorSpeed(Scene scene, Component cmp)Component Physics.getActorComponent(Scene scene, Entity entity)void Physics.putToSleep(Scene scene, Entity entity)void Physics.applyForceToActor(Scene scene, Component component, Vec3 force)
If two entities with a physical component collide, onContact function is called in script on both of them:
function onContact(entity)
API_logError("not implemented - onContact(" .. entity .. ")")
end
SoundHandle Audio.playSound(Scene scene, Entity entity, string clip_name, bool is_3d)void Audio.setSoundVolume(Scene scene, SoundHandle sound_id, number volume)void Audio.setEcho(IScene* scene, SoundHandle sound, number wet_dry_mix, number feedback, number left_delay, number right_delay)