-
Notifications
You must be signed in to change notification settings - Fork 433
Lua scripting
Mikulas Florek edited this page Dec 6, 2015
·
150 revisions
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.
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
-
Table API_getEnvironment(Scene scene, Entity entity)#620 void API_setEntityPosition(Universe univ, Entity entity, number x, number y, number z)void API_setEntityRotation(Universe univ, Entity entity, number x, number y, number z, number angle)void API_setEntityLocalRotation(UniverseContext univ, Entity entity, number x, number y, number z, number angle)void API_setRenderablePath(Scene scene, Component cmp, string path)number API_getInputActionValue(Engine engine, number action)void API_addInputAction(Engine engine, number action, number type, number key)Component API_createComponent(Scene scene, string type, Entity entity)void API_logError(string text)void API_logInfo(string text){x, y, z} API_multVecQuat(number x, number y, number z, number axis_x, number axis_y, number axis_z, number angle)
void API_moveController(Scene scene, Component cmp, number x, number y, number z, number time_delta)number API_getActorSpeed(Scene scene, Component cmp)Component getActorComponent(Scene scene, Entity entity)void putToSleep(Scene scene, Entity entity)void applyForceToActor(Scene scene, Component component, number x, number y, number z)
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 API_playSound(Scene scene, Entity entity, string clip_name, bool is_3d)void API_setSoundVolume(Scene scene, SoundHandle sound_id, number volume)