Skip to content

How to Create a Shuffler Plugin

authorblues edited this page Jul 8, 2021 · 8 revisions

Creating a Shuffler Plugin

Download the empty base plugin. (Right click and Save As to download the file)

Events

All methods are sent (1) a data table that can be used to maintain persistent information, even across reloads, and (2) a settings table that contains key-value pairs with settings names as keys and their associated values. Both of these tables are unique to the plugin, so collisions will not happen with other plugins, even if they use the same keys. All methods are optional and any methods that are unused can be safely deleted.

  • function plugin.on_setup(data, settings)
    • called once when a shuffler session is started
  • function plugin.on_frame(data, settings)
    • called once per frame
  • function plugin.on_game_load(data, settings)
    • called when a new game is loaded
  • function plugin.on_game_save(data, settings)
    • called when a shuffle is about to happen, before the current game is unloaded
  • function plugin.on_complete(data, settings)
    • called when a game is marked as complete, before it is unloaded

The code you write in these methods can draw on any of the methods available through Bizhawk's Lua interface, as well as any functions or variables in shuffler.lua. For Bizhawk-specific methods, please refer to the limited documentation on tasvideos.org, but the shuffler-specific functions/variables you are most likely to find useful are as follows:

  • swap_game()
    • Forces a swap at the next possible frame
  • swap_game_delay(x)
    • Updates the next scheduled swap to take place x frames from now

Creating Settings

When a plugin is enabled, the user is shown a list plugin-specific settings created by the plugin author. This window looks like the one below.

An example of the Bizhawk shuffler plugins window for reference.

The "Enabled" button is added automatically, but the rest of the settings are generated from the plugin.settings table. Settings are represented by tables with a name (the name of the setting), type (the type of setting, refer to the list below), and a label (a human-readable description of the setting). The following list contains the types and any additional required information:

  • type='boolean'
    • Creates a checkbox. The setting will be a boolean value, true or false, indicating whether the box was checked
    • Optional key: default - if provided and true, the checkbox will default to being checked
  • type='romlist'
    • Creates a dropdown menu containing names of games in the games/ folder
  • type='select'
    • Creates a dropdown menu containing values specified by a table value associated the required key options
    • Optional key: default - if provided, the dropdown will default to the value associated with this key
  • type='file'
    • Creates a button that will open a file select dialog to choose a file. The setting will hold the filename of the chosen file
  • type='text'
    • Creates a text box. The setting will contain the contents of the box as a string
    • Optional key: default - if provided, the text box will start pre-filled with the value associated with this key
  • type='number'
    • Creates a text box. The setting will contain the contents of the box as a number
    • Optional key: datatype - if provided, the contents of the text box will be restricted based on the forms.textbox Bizhawk Lua function
    • Optional key: default - if provided, the text box will start pre-filled with the value associated with this key

Check existing plugins for examples of settings.

Clone this wiki locally