Creating an Action

Elliot Ford edited this page May 7, 2015 · 9 revisions

What is an Action?

An Action is like Runnable but for an ActionEngine. When the Action is executed it is handed an ActionContext which can be used to control the Actions life-cycle or gain additional information.

What is available from an ActionContext?

An ActionContext can be used to gain scheduling details as well as cancel an Action. ActionContext extends from ActionBindings so it can be used to gain addition information (key-value pairs) bound to that action (or the ActionEngine if the implementation supports this).

Creating the Action

Actions have a type argument T that represents the actors type (can be ? for unknown or no actor). This allows the ActionContext to provided a typed actor reference. The below example will output whatever text actor is bound:

public class PrintTextAction implements Action<String> {

    public void perform(ActionContext<String> context) {

Action is a functional interface so the above could be defined as:

Action<?> action = c -> System.out.println(c.getActor());

Executing the Action

For information about scheduling, cancelling or ActionContext see Scheduling, awaiting and cancelling actions.

Entity is an ActionScheduler most Actions scheduled are bound to an Entity (and thus have Entity as the context type argument). For scheduling Actions bound to specific actors see Using an ActionScheduler.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.