LuaEvents (Civ5 Type)
This page is a part of the Lua and UI Reference (Civ5).
This object provides a mechanism modders can use to define and subscribe their own events. Those events are then visible in all contexts and all mods.
To define a custom event, you just need to subscribe it or invoke it, the event will then be lazily created and no error will be thrown.
The following example defines a "VelociratproAttack" event and subscribes a "RunAway" handler to it.
function RunAway(name) print("Run "..name.."!") end LuaEvents.VelociraptorAttack.Add(RunAway) -- Now fires the event. Prints "Run Forest!" LuaEvents.VelociraptorAttack("Forest")
Events declared by the UI
Events can be subscribed by using
LuaEvents.SomeEvent.Add(SomeFunction). Regular events can also be fired through a dot by using
LuaEvents.SomeEvent(<args>). This will invoke all subscribers with the provided arguments.
Methods are functions that belong to an object. Static methods are invoked through a dot, as in
LuaEvents.SomeMethod(<args>). When a dot is used the caller object is not implicitly provided as the first argument.
The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.