Skip to contents

Uses a game ROM object to create a RAM object, which stores all dynamic data of the game. As ram.run() runs the game, the RAM is updated and read.

Usage

ram.init(ROM)

Arguments

ROM

ROM object containing game code.

Value

A RAM object contains the following elements.

$ROM ROM object the game is run with.
$ticksNumber of ticks the game has processed.
$timeTime of the latest frame reached by the RAM.
$rngLocal RNG state for the RAM; see ram.set_rng
$seedInteger used to set the rng during ram.init. Random by default.
$objectsList of game-related objects; dynamic game data should generally be stored here. Objects in this list which have a $spritename are drawn in render.ram().
$inputsList of all inputs the game has received, matching inputs.csv. See inputs.process().
$actionsList of all game actions that are currently active.
$n_inputsNumber of inputs from inputs.csv the RAM has read. Used to determine which are new.
$backupCopy of RAM from a couple seconds ago, excluding $ROM, $inputs, $debug, $backup, and $intermediate (since these shouldn't be rolled back). See ram.rollback
$intermediateSame as $backup, but more recent. Used in ram.tick() to update $backup on a rolling basis.
$beganVector of c(time,tick) indicating when ram.run was last run, used for timing inputs.
$pausedBoolean; is the game allowed to tick?
$debugCollection of info about the current game session; see ram.debug.

Notes

Custom game code (in RAM$ROM$custom) should typically only modify RAM$objects. This makes inspecting and handling the RAM more consistent across games.

Examples

if (FALSE) { # \dontrun{
RAM = ram.init(Snake)
View(RAM)
} # }