Skip to contents

Unexpected crash? This documentation provides debugging resources and lists some common problems you might encounter.

The Snake vignette is goes through the basic development process and is very useful; you can view it with vignette("Snake").

Usage

rom.help()

ram.help()

Traceback

When the game crashes, it prints a traceback, call, and error:

Traceback A list showing which functions led to where the error is. Should be similar to what you get from base R's traceback().
CallThe call in which the error occurred.
ErrorThe specific error.

?ram.run has a function tree of that may be useful in understanding where an error occurred; the traceback will list the branches encompassing the error call.

Logging

Multiple options exist for printing information via game code.

  • The contents of RAM$echo are printed below the game render every frame.

  • Any base::print() calls will only be visible if the game crashes due to how the console is wiped.

  • A global variable foo <<- [debug info] can be modified via the game code.

Thus print() is ideal for debugging the source of a crash, as it prints information about the current tick. RAM$echo is useful for monitoring values while running the game, and using a global variable gives more control and the option to record info for every tick.

Timing

RAM$debug records a lot of timing-related data relevant to the timing and rollback systems (vignette("timing") and vignette("rollback")).

Empty Lists

Make sure you haven't accidentally wiped RAM or RAM$objects. This can happen if you define a custom function like ROM$my_function(RAM) and forget to return RAM at the end of it.

Inputs

Make sure that tools::R_user_dir("rcade") exists.

Double-check ROM$keybinds and make sure RAM$actions are properly referenced in your code. Consider adding RAM$echo = RAM$actions to ROM$custom to show the state of each action every tick.

Iterating

To iterate through RAM$objects, use the syntax

for (i in 1:length(RAM$objects)){
    obj = RAM$objects[[i]]

}

This is required due to how R handles nested lists; the format
for (obj in RAM$objects) will NOT work.

Examples

if (FALSE) { # \dontrun{
#traceback demo:
RAM = ram.init(Snake)
RAM$ROM$sprites = NULL #this will make the game crash
RAM = ram.run(RAM)
} # }