The action system formalizes how players interact with the game, making things like networking possible.
The player interacts with the controller whose inputs will result in different actions depending on the context for the user interface.

Actions are things that happen in the game because of a player's input. For example, a player shooting a gun would be an action, but also, the bullet hitting a target would be an action as it only exisited in the first place due to a player.
Most actions will be found in the Step or Collision events. Let's take for example a player throwing an ice ball that freezes whatever it touches. In the character's Step Event is:
// Throw ice ball towards mouse if not reloading
if keyboard_check(vk_space) and alarm[0] < 0 {
var ice_ball = instance_create_layer(x, y, "lay_instances", obj_ball)
ice_ball.direction = point_direction(x, y, mouse_x, mouse_y)
ice_ball.speed = throw_speed
alarm[0] = reload_wait_time
}
As the ball's creation is dependent on a player's input, it is an action. The intent of the action module is to abstract and standardize how actions are requested and performed, therefore allowing integration with more complex modules such as networking.
Each action is given a unique identifier, specified in scr_action_interface, and then where the action initally appears in the code, is replaced by a request. For this example we will use ACT_THROW as the identifier.
When migrating an exisiting code block to the action system, there are four parts to identify and move:
if keyboard_check(vk_space) {
if alarm[0] < 0 {
var throw_direction = point_direction(x, y, mouse_x, mouse_y)
var ice_ball = instance_create_layer(x, y, "lay_instances", obj_ball)
ice_ball.direction = throw_direction
ice_ball.speed = throw_speed
alarm[0] = reload_wait_time
While throw_speed is a variable, it is not specific to the context and therefore is not a parameter to the action.
Conditionals determining which action is occuring, and context-specific parameters stay in the orignal code block, while conditionals determining whether the action is valid and action-specific code is migrated into the object's request_action() and perform_action() functions.
A source of authority is required for conditionals determining whether the action is valid. In non-networked games, it is fine for this to be the object itself, and therefore the check can occur in request_action(). In networked games, the check may need to occur on the server before sending out to all clients to perform.
In this case, the code would be migrated as follows:
Step Event (Conditionals determining which action is occuring and context-specific parameters):
// Throw ice ball towards mouse if not reloading
if keyboard_check(vk_space) {
var dir = point_direction(x, y, mouse_x, mouse_y)
request_action(ACT_THROW, dir)
}
Create Event | request_action (Conditionals determining whether action is valid):
/// @function request_action(action, [arguments])
/// @description Intermediate function that validates actions
/// @param {real} action Constant associated with action, other arguments depend on action
request_action = function(action) {
switch action {
case ACT_THROW:
var dir = argument[1]
if alarm[0] < 0 {
perform_action(action, dir)
}
break
}
}
Create Event | perform_action (Action-specific code):
/// @function perform_action(action, [arguments])
/// @description Impacts the games
/// @param {real} action Constant associated with action, other arguments depend on action
perform_action = function(action) {
switch action {
case ACT_THROW:
var dir = argument[1]
var ice_ball = instance_create_layer(x, y, "lay_instances", obj_ball)
ice_ball.direction = dir
ice_ball.speed = throw_speed
alarm[0] = reload_wait_time
break
}
}
For more guidance on each step briefed here, see the following tabs:
Assign an Action Identifier
Action Function Template
Under Phame | Phame-Actions | Integrations | scr_action_interface, designate a macro to represent the action moving forward, using ACT_ as a prefix.
Assign to the macro the next available sequential number (0-9 is reserved for Phame Modules).
#macro ACT_THROW 10
For debugging purposes, also add the new macro as case to scr_action_to_string():
/// @function scr_action_to_string(action)
/// @description Takes the action and returns the corresponding string
/// @param action
function scr_action_to_string(action) {
switch (action) {
case ACT_THROW:
return "ACT_THROW"
...
Each object capable of performing actions is required to have two functions defined in its Create event: request_action() and perform_action():
#region Actions
/// @function perform_action(action, [arguments])
/// @description Impacts the games
/// @param {real} action Constant associated with action, other arguments depend on action
perform_action = function(action) {
switch action {
case ACT_THROW:
// TODO
break
}
}
/// @function request_action(action, [arguments])
/// @description Intermediate function that validates actions
/// @param {real} action Constant associated with action, other arguments depend on action
request_action = function(action) {
switch action {
case ACT_THROW:
// TODO
break
}
}
#endregion
The Phame Actions module is leveraged across several Phame modules and is the common language of "getting things done". By implementing actions into your game, you can easily leverage the Phame Networking module for any interactions in the future.
Module integration happens in two parts. First in the integration group of the module itself.
All action constants should start with ACT_ for consistency.
scr_action_interfacescr_action_interface defines a constant for each unique action in the game. Usually, the first ten numbers are reserved for the game's lobby menu. It is best practice to also fill out the scr_action_to_string() function for debug purposes.
Whenever an object requests or performs actions, it must be integrated with the action system.
In the object's Create event, two functions must be defined with switch statements for each applicable action constant:
perform_action(action)request_action(action)Since common functions are required for interoperability, the function definition cannot define any action-specifc parameters. Instead, these are accessed with argument[n] where n is 1 and above. argument[0] is reserved for action.
Documentation of these parameters occur naturally in the perform_action() function. Give parameters human readables names by first saving to a local variable: var damage = argument[1]. Then when a developer is trying to implement that action in another event, they can simply look at hte Create event. request_action() must identify the action-specific parameters to pass to perform_action().
Anywhere in the code that an action is normally performed, is replaced with a call to request_action() with the appropriate action constant and any necessary parameters.
request_action() in the create event can then determine whether it is an interaction and needs to be sent over the server, or an action that can be peformed locally. By centralizing this decision to the create event, it is easier to quickly implement networking without deep-diving the entire code.
Network interactions with Online Networking.
Network controllers with Hybrid Controllers.
Is damaging a character an action or interaction?
Where is the determination of if its an interaction made?
request_action(), not in the object event requesting the action.