-
Notifications
You must be signed in to change notification settings - Fork 24
Creating an Action
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) {
System.out.println(context.getActor());
}
}
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.
Check out the Example projects and Code snippets!
Getting Started
- Getting the latest release
- Building from source
- Example projects
- Code snippets
- How to contribute
- Have bugs or questions?
How To Use
- JALSE
- Entities
- Attributes
- Actions
- Tags
Misc