Skip to contents

Updates RAM$actions according to any inputs occurring on the current frame.

Inputs and actions are stored in RAM like so:

RAM$inputs Stores every input that ever occurred, just like inputs.csv.
RAM$actionsStores the game actions corresponding to inputs as dictated in ROM$keybinds (see below).

Usage

inputs.process(RAM)

Arguments

RAM

RAM object to update.

Details

The following is an outline of the process from a player entering an input to it being registered by the game.

  1. Player types out "wa" in the inputs.listen() listener.

  2. Player presses Enter; an input is created consisting of the string "wa" and a timestamp (see inputs.listen).
    This input is written to inputs.csv.

  3. When the gameloop runs inputs.get(), this input is added to RAM$inputs and its timestamp is converted to the tick it should be processed on.

  4. When RAM$ticks == the tick timestamp of this input in RAM$inputs, the input is processed:

  5. The input is split into individual characters: "w" and "a".

  6. The actions corresponding to these keys, RAM$ROM$keybinds["w"] and RAM$ROM$keybinds["a"], are set to 1 in RAM$actions (see below).

  7. Game code in RAM$ROM$custom() reads RAM$actions and move the player character accordingly.

  8. On the next frame, all RAM$actions are set to 0 before inputs are checked again.

Keybinds

Keybinds are set by the dev with, e.g.

ROM$keybinds = c(k = 'attack', w = 'up', a = 'left', s = 'down', d = 'right')

This stores the actions ('attack', 'up', etc.) and the keys (k, w, etc.) that, when input, activate the actions. These keybinds populate RAM$actions when RAM is initialized:

RAM$actions = list(attack = 0, up = 0, left = 0, down = 0, right = 0)

When a key is registered, the corresponding action in RAM$actions is set to 1 for one frame. (If a key is pressed multiple times in the same input, e.g. "ww", the action will be set to 2, and so on. This is useful for allowing for more input combinations with a single button.)

The game should read RAM$actions to control game behavior; see vignette('rrio') to see this in action.

Examples

#only used internally, in ram.update()