Skip to contents

Restores the RAM state from several seconds ago; ram.update() will then rapidly advance the game to catch up with the current time. See vignette("rollback") for more details.

This is usually triggered by inputs.read() upon registering an input that was supposed to have happened, but didn't because it was received late. To prevent the input from being dropped, the game rolls back and reruns the past few seconds to rectify the mistake.

Usage

ram.rollback(RAM)

Arguments

RAM

RAM object.

Backups

RAM always keeps a backup of itself saved in RAM$backup, containing the entire RAM from the time of the backup minus inputs, debug info, and the ROM; these are never rolled back.

Backups have a minimum age of RAM$ROM$backup_duration; the RAM can only be restored to around that time ago. Backups are saved during ram.tick().

RAM$intermediate is used to store the next backup before it replaces the current one, to ensure that backups are never younger than RAM$ROM$backup_duration.

Rollback

This function just restores RAM$backup with

RAM = utils::modifyList(RAM, RAM$backup)

Since this puts RAM$time behind, the gameloop automatically speeds up to catch the RAM back up.

This catchup process runs the inputs again, so if any inputs were received late, they will now be registered on time.

Examples

#inputting '/rollback' during gameplay will manually trigger a rollback, though it'll be hard to notice.
#RAM$debug$rollbacks saves a timestamp of each rollback that occurs.