How to Implement an Action

Actions are generalized by the class TriggerInterface, under src/GamePlay of the engine. Each new action must implement this interface. These actions can be assigned to trigger volumes or GUI button.They can also be run on map load.

Action constructors will get a populated LimonAPI instance for the world they are to be run in. Using this instance, API calls can be made to interact or change the world to game design.

Actions never get persisted, but parameters to pass to actions are persisted with maps.

TriggerInterface Class

  TriggerInterface(LimonAPI *limonAPI)
std::vector<LimonAPI::ParameterRequest> getParameters()
bool run(std::vector<LimonAPI::ParameterRequest>parameters)
std::vector<LimonAPI::ParameterRequest> getResults()
std::string getName() const

TriggerInterface(LimonAPI *limonAPI)

The constructor of the interface.

Note

All actions must have the same signature, no other parameters should be required.

getParameters()

Returns a vector of ParameterRequest struct, These parameters are going to be set by map designer using the editor.

run(std::vector<LimonAPI::ParameterRequest>parameters)

The parameters with their set values will be provided. The logic of the action should be this method. Return true if run succesfully. Return false if the run failed for some reason.

getResults()

The actions result might be queried by other actions. This method should return the results. Engine itself doesn’t use this method, so it can return an empty vector. The usage of this method is game specific.

For example if the action adds a GUI element, and another action wants to remove this element, the other action might query for gui element id.

getName() const

Returns the name of the action.

Warning

The name must be unique, or the results will be undefined.

How to enable Dynamic Library discovery

Limon engine will try to load custom actions on engine startup, from libcustomTriggers file (extension based on platform). If the file is found, engine will check for a method with following signature:

void registerAsTrigger(std::map<std::string, TriggerInterface*(*)(LimonAPI*)>* triggerMap)

This method should fill the triggerMap passed, with all the custom actions, like this:

(*triggerMap)["$ACTION_NAME1$"] = &createT<$ActionClass1$>;
(*triggerMap)["$ACTION_NAME2$"] = &createT<$ActionClass2$>;