Screen Actions, Values, and Functions — Ren'Py Documentation

### Navigation

- index
- next |
- previous |
- Ren'Py Home |
- Ren'Py Documentation

# Screen Actions, Values, and Functions

Ren'Py ships with a number of actions, values, and functions intended for use with screens and the screen language.

## Actions

Actions are invoked when a button (including imagebuttons, textbuttons, and hotspots) is activated, hovered, or unhovered. Actions may determine when a button is selected or insensitive.

Along with these actions, an action may be a function that does not take any arguments. The function is called when the action is invoked. If the action returns a value, then the value is returned from an interaction.

An action may also be a list of actions, in which case the actions in the list are run in order.

### Control Actions

These are actions that manage screens, interaction results, and control flow.

`Hide`(screen, transition=None)

  This causes the screen named screen to be hidden, if it is shown.

  transition
    If not None, a transition that occurs when hiding the screen.

`Jump`(label)

  Causes control to transfer to the given label. This can be used in conjunction with renpy.run_screen to define an imagemap that jumps to a label when run.

`NullAction`()

  Does nothing.

  This can be used to make a button responsive to hover/unhover events, without actually doing anything.

`Return`(value=None)

  Causes the current interaction to return the supplied value. This is often used with menus and imagemaps, to select what the return value of the interaction is.

  When in a menu, this returns from the menu.

`Show`(screen, transition=None, *args, **kwargs)

  This causes another screen to be shown. screen is a string giving the name of the screen. The keyword arguments are passed to the screen being shown.

  If not None, transition is use to show the new screen.

`ShowTransient`(screen, *args, **kwargs)

  Shows a transient screen. A transient screen will be hidden when the current interaction completes.

### Data Actions

These set or toggle data.

`AddToSet`(set, value)

  Adds value to set.

  set
    The set to add to. This may be a python set or list, in which case the value is appended to the list.
  value
    The value to add or append.

`RemoveFromSet`(set, value)

  Removes value from set.

  set
    The set to remove from. This may be a set or list.
  value
    The value to add or append.

`SetDict`(dict, key, value)

  Causes the value of key in dict to be set to value.

`SetField`(object, field, value)

  Causes the a field on an object to be set to a given value. object is the object, field is a string giving the name of the field to set, and value is the value to set it to.

`SetScreenVariable`(name, value)

  Causes the variable name associated with the current screen to be set to value.

`SetVariable`(variable, value)

  Causes variable to be set to value.

`ToggleDict`(dict, key, true_value=None, false_value=None)

  Toggles the value of key in dict. Toggling means to invert the value when the action is performed.

  true_value
    If not None, then this is the true value we use.
  false_value
    If not None, then this is the false value we use.

`ToggleField`(object, field, true_value=None, false_value=None)

  Toggles field on object. Toggling means to invert the boolean value of that field when the action is performed.

  true_value
    If not None, then this is the true value we use.
  false_value
    If not None, then this is the false value we use.

`ToggleScreenVariable`(name, true_value=None, false_value=None)

  Toggles the value of the variable name in the current screen.

  true_value
    If not None, then this is the true value we use.
  false_value
    If not None, then this is the false value we use.

`ToggleSetMembership`(set, value)

  Toggles the membership of value in set. If the value is not in the set, it's added. Otherwise, it is removed.

  Buttons with this action are marked as selected if and only if the value is in the set.

  set
    The set to add to or remove from. This may be a set or list. In the case of a list, new items are appended.
  value
    The value to add or append.

`ToggleVariable`(variable, true_value=None, false_value=None)

  Toggles variable.

  true_value
    If not None, then this is the true value we use.
  false_value
    If not None, then this is the false value we use.

### Menu Actions

These actions invoke menus, or are primarily useful while in the main or game menus.

`MainMenu`(confirm=True)

  Causes Ren'Py to return to the main menu.

  confirm
    If true, causes Ren'Py to ask the user if he wishes to return to the main menu, rather than returning directly.

`Quit`(confirm=True)

  Quits the game.

  confirm
    If true, prompts the user if he wants to quit, rather than quitting directly.

`ShowMenu`(screen=None, *args, **kwargs)

  Causes us to enter the game menu, if we're not there already. If we are in the game menu, then this shows a screen or jumps to a label.

  screen is usually the name of a screen, which is shown using the screen mechanism. If the screen doesn't exist, then "_screen" is appended to it, and that label is jumped to.

  - ShowMenu("load")
  - ShowMenu("save")
  - ShowMenu("preferences")

  This can also be used to show user-defined menu screens. For example, if one has a "stats" screen defined, one can show it as part of the game menu using:

  - ShowMenu("stats")

  ShowMenu without an argument will enter the game menu at the default screen, taken from _game_menu_screen.

  Extra arguments and keyword arguments are passed on to the screen

`Start`(label='start')

  Causes Ren'Py to jump out of the menu context to the named label. The main use of this is to start a new game from the main menu. Common uses are:

  - Start() - Start at the start label.
  - Start("foo") - Start at the "foo" label.

### File Actions

These actions handle saving, loading, and deleting of files. Many of these take the name and page arguments.

name
  The name of the file to save to. This can be a string or an integer. It's combined with the page to create the filename.
page
  The page that this action acts on. This is one of "auto", "quick", or a positive integer. If None, the page is determined automatically, based on a persistent page number.

`FileAction`(name, page=None, **kwargs)

  "Does the right thing" with the file. This means loading it if the load screen is showing (current screen is named "load"), and saving otherwise.

  name
    The name of the slot to save to or load from. If None, an unused slot (a large number based on the current time) will be used.
  page
    The page that the file will be saved to or loaded from. If None, the current page is used.

  Other keyword arguments are passed to FileLoad or FileSave.

`FileDelete`(name, confirm=True, page=None)

  Deletes the file.

  confirm
    If true, prompts before deleting a file.

`FileLoad`(name, confirm=True, page=None, newest=True)

  Loads the file.

  name
    The name of the slot to load from. If None, an unused slot the file will not be loadable.
  confirm
    If true and not at the main menu, prompt for confirmation before loading the file.
  page
    The page that the file will be loaded from. If None, the current page is used.
  newest
    If true, the button is selected if this is the newest file.
  cycle
    Ignored.

`FilePage`(page)

  Sets the file page to page, which should be one of "auto", "quick", or an integer.

`FilePageNext`(max=None, wrap=False)

  Goes to the next file page.

  max
    If set, this should be an integer that gives the number of the maximum file page we can go to.
  wrap
    If true, we can go to the first page when on the last file page if max is set.

`FilePagePrevious`(max=None, wrap=False)

  Goes to the previous file page, if possible.

  max
    If set, this should be an integer that gives the number of the maximum file page we can go to. This is required to enable wrap.
  wrap
    If true, we can go to the last page when on the first file page if max is set.

`FileSave`(name, confirm=True, newest=True, page=None, cycle=False)

  Saves the file.

  The button with this slot is selected if it's marked as the newest save file.

  name
    The name of the slot to save to. If None, an unused slot (a large number based on the current time) will be used.
  confirm
    If true, then we will prompt before overwriting a file.
  newest
    Ignored.
  page
    The name of the page that the slot is on. If None, the current page is used.
  cycle
    If true, then saves on the supplied page will be cycled before being shown to the user. `config.quicksave_slots` slots are used in the cycle.

`FileTakeScreenshot`()

  Take a screenshot to be used when the game is saved. This can be used to ensure that the screenshot is accurate, by taking a picture of the screen before a file save screen is shown.

`QuickLoad`(confirm=True)

  Performs a quick load.

  confirm
    If true and not at the main menu, prompt for confirmation before loading the file.

`QuickSave`(message='Quick save complete.', newest=False)

  Performs a quick save.

  message
    A message to display to the user when the quick save finishes.
  newest
    Set to true to mark the quicksave as the newest save.

### Audio Actions

`Play`(channel, file, selected=None, **kwargs)

  Causes an audio file to be played on a given channel.

  channel
    The channel to play the sound on.
  file
    The file to play.
  selected
    If True, buttons using this action will be marked as selected if the file is playing on the channel. If False, this action will not cause the button to start playing. If None, the button is marked selected if the channel is a music channel, and not otherwise.

  Any other keyword arguments are passed to `renpy.music.play()`.

`Queue`(channel, file, **kwargs)

  Causes an audio file to be queued on a given channel.

  channel
    The channel to play the sound on.
  file
    The file to play.

  Any keyword arguments are passed to `renpy.music.queue()`

`SetMixer`(mixer, volume)

  Sets the volume of mixer to value.

  mixer
    The mixer to set the volume of. A string, usually one of "music", "sfx", or "voice".
  value
    The value to set the volume to. A number between 0.0 and 1.0, inclusive.

`SetMute`(mixer, mute)

  Sets the mute status of one or more mixers. When a mixer is muted, audio channels associated with that mixer will stop playing audio.

  mixer
    Either a single string giving a mixer name, or a list of strings giving a list of mixers. The strings should be mixer names, usually "music", "sfx", or "voice".
  mute
    True to mute the mixer, False to ummute it.

`Stop`(channel, **kwargs)

  Causes an audio channel to be stopped.

  channel
    The channel to stop the sound on.

  Any keyword arguments are passed to `renpy.music.stop()`

`ToggleMute`(mixer)

  Toggles the mute status of one or more mixers.

  mixer
    Either a single string giving a mixer name, or a list of strings giving a list of mixers. The strings should be mixer names, usually "music", "sfx", or "voice".

### Other Actions

These are other actions, not found anywhere else.

`Function`(callable, *args, **kwargs)

  This Action calls callable with args and kwargs.

  callable
    Callable object.
  args
    position arguments to be passed to callable.
  kwargs
    keyword arguments to be passed to callable.

  This Action takes an optional _update_screens keyword argument, which defaults to true. When it is true, the interaction restarts and the screens are updated after the function returns.

`Help`(help=None)

  Displays help.

  help
    If this is a string giving a label in the program, then that label is called in a new context when the button is chosen. Otherwise, it should be a string giving a file that is opened in a web browser. If None, the value of config.help is used in the same way.

`HideInterface`()

  Causes the interface to be hidden until the user clicks.

`If`(expression, true=None, false=None)

  This returns true if expression is true, and false otherwise. Use this to select an action based on an expression. Note that the default, None, can be used as an action that causes a button to be disabled.

`InvertSelected`(action)

  This inverts the selection state of the provided action, while proxying over all of the other methods.

`MouseMove`(x, y, duration=0)

  Move the mouse pointer to x, y. If the device does not have a mouse pointer or _preferences.mouse_move is False, this does nothing.

  duration
    The time it will take to perform the move, in seconds. During this time, the mouse may be unresponsive.

`Notify`(message)

  Displays message using `renpy.notify()`.

`OpenURL`(url)

  Causes url to be opened in a web browser.

`RestartStatement`()

  This action causes Ren'Py to rollback to before the current statement, and then re-run the current statement. This may be used when changing a persistent variable that affects how the statement is displayed.

  If run in a menu context, this waits until the player exits to a top-level context before performing the rollback.

`RollForward`()

  This action causes a rollforward to occur, if a roll forward is possible. Otherwise, it is insensitive.

`Rollback`()

  This action causes a rollback to occur, when a rollback is possible. Otherwise, nothing happens.

`Screenshot`()

  Takes a screenshot.

`SelectedIf`(expression)

  This allows an expression to control if a button should be marked as selected. It should be used as part of a list with one or more actions. For example:

      # The button is selected if mars_flag is True
      textbutton "Marsopolis":
          action [ Jump("mars"), SelectedIf(mars_flag) ]

`SensitiveIf`(expression)

  This allows an expression to control if a button should be marked as sensitive. It should be used as part of a list with one or more actions. For example:

      # The button is sensitive if mars_flag is True
      textbutton "Marsopolis":
          action [ Jump("mars"), SensitiveIf(mars_flag) ]

`Skip`(fast=False, confirm=False)

  Causes the game to begin skipping. If the game is in a menu context, then this returns to the game. Otherwise, it just enables skipping.

  fast
    If true, skips directly to the next menu choice.
  confirm
    If true, asks for confirmation before beginning skipping.

`With`(transition)

  Causes transition to occur.

## Values

Values are used with bars, to set the bar value, and to allow the bar to adjust an underlying property.

`AnimatedValue`(value=0.0, range=1.0, delay=1.0, old_value=None)

  This animates a value, taking delay seconds to vary the value from old_value to value.

  value
    The value itself, a number.
  range
    The range of the value, a number.
  delay
    The time it takes to animate the value, in seconds. Defaults to 1.0.
  old_value
    The old value. If this is None, then the value is taken from the AnimatedValue we replaced, if any. Otherwise, it is initialized to value.

`DictValue`(dict, key, range, max_is_zero=False, style='bar', offset=0, step=None)

  A value that allows the user to adjust the value of a key in a dict.

  dict
    The dict.
  key
    The key.
  range
    The range to adjust over.
  max_is_zero
    If True, then when the value of a key is zero, the value of the bar will be range, and all other values will be shifted down by 1. This works both ways - when the bar is set to the maximum, the value of a key is set to 0.
  style
    The styles of the bar created.
  offset
    An offset to add to the value.
  step
    The amount to change the bar by. If None, defaults to 1/10th of the bar.

`FieldValue`(object, field, range, max_is_zero=False, style='bar', offset=0, step=None)

  A value that allows the user to adjust the value of a field on an object.

  object
    The object.
  field
    The field, a string.
  range
    The range to adjust over.
  max_is_zero

    If True, then when the field is zero, the value of the bar will be range, and all other values will be shifted down by 1. This works both ways - when the bar is set to the maximum, the field is set to 0.

    This is used internally, for some preferences.

  style
    The styles of the bar created.
  offset
    An offset to add to the value.
  step
    The amount to change the bar by. If None, defaults to 1/10th of the bar.

`MixerValue`(mixer)

  The value of an audio mixer.

  mixer
    The name of the mixer to adjust. This is usually one of "music", "sfx", or "voice", but user code can create new mixers.

`StaticValue`(value=0.0, range=1.0)

  This allows a value to be specified statically.

  value
    The value itself, a number.
  range
    The range of the value.

`VariableValue`(variable, range, max_is_zero=False, style='bar', offset=0, step=None)
  variable
    A string giving the name of the variable to adjust.
  range
    The range to adjust over.
  max_is_zero

    If True, then when the field is zero, the value of the bar will be range, and all other values will be shifted down by 1. This works both ways - when the bar is set to the maximum, the field is set to 0.

    This is used internally, for some preferences.

  style
    The styles of the bar created.
  offset
    An offset to add to the value.
  step
    The amount to change the bar by. If None, defaults to 1/10th of the bar.

`XScrollValue`(viewport)

  The value of an adjustment that horizontally scrolls the the viewport with the given id, on the current screen. The viewport must be defined before a bar with this value is.

`YScrollValue`(viewport)

  The value of an adjustment that vertically scrolls the the viewport with the given id, on the current screen. The viewport must be defined before a bar with this value is.

## Functions and Classes

These functions and classes are useful in association with screens.

### Preferences

While all preferences can be defined based on the Actions and Values given above, it requires some knowledge of Ren'Py to figure out the correct one to use. The preferences constructor makes this easy, by creation an action or value, as appropriate, based on the names used in the default preferences screen.

`Preference`(name, value=None)

  This constructs the appropriate action or value from a preference. The preference name should be the name given in the standard menus, while the value should be either the name of a choice, "toggle" to cycle through choices, a specific value, or left off in the case of buttons.

  Actions that can be used with buttons and hotspots are:

  - Preference("display", "fullscreen") - displays in fullscreen mode.
  - Preference("display", "window") - displays in windowed mode at 1x normal size.
  - Preference("display", 2.0) - displays in windowed mode at 2.0x normal size.
  - Preference("display", "any window") - displays in windowed mode at the previous size.
  - Preference("display", "toggle") - toggle display mode.
  - Preference("transitions", "all") - show all transitions.
  - Preference("transitions", "none") - do not show transitions.
  - Preference("transitions", "toggle") - toggle transitions.
  - Preference("show empty window", "show") - Allow the "window show" and "window auto" statement to show an empty window outside of the say statement.
  - Preference("show empty window", "hide") - Prevent the above.
  - Preference("show empty window", "toggle") - Toggle the above.
  - Preference("text speed", 0) - make text appear instantaneously.
  - Preference("text speed", 142) - set text speed to 142 characters per second.
  - Preference("joystick") - Show the joystick preferences.
  - Preference("skip", "seen") - Only skip seen messages.
  - Preference("skip", "all") - Skip unseen messages.
  - Preference("skip", "toggle") - Toggle between skip seen and skip all.
  - Preference("begin skipping") - Starts skipping.
  - Preference("after choices", "skip") - Skip after choices.
  - Preference("after choices", "stop") - Stop skipping after choices.
  - Preference("after choices", "toggle") - Toggle skipping after choices.
  - Preference("auto-forward time", 0) - Set the auto-forward time to infinite.
  - Preference("auto-forward time", 10) - Set the auto-forward time (unit is seconds per 250 characters).
  - Preference("auto-forward", "enable") - Enable auto-forward mode.
  - Preference("auto-forward", "disable") - Disable auto-forward mode.
  - Preference("auto-forward", "toggle") - Toggle auto-forward mode.
  - Preference("auto-forward after click", "enable") - Remain in auto-forward mode after a click.
  - Preference("auto-forward after click", "disable") - Disable auto-forward mode after a click.
  - Preference("auto-forward after click", "toggle") - Toggle auto-forward after click.
  - Preference("automatic move", "enable") - Enable automatic mouse mode.
  - Preference("automatic move", "disable") - Disable automatic mouse mode.
  - Preference("automatic move", "toggle") - Toggle automatic mouse mode.
  - Preference("wait for voice", "enable") - Wait for the currently playing voice to complete before auto-forwarding.
  - Preference("wait for voice", "disable") - Do not wait for the currently playing voice to complete before auto-forwarding.
  - Preference("wait for voice", "toggle") - Toggle wait voice.
  - Preference("voice sustain", "enable") - Sustain voice past the current interaction.
  - Preference("voice sustain", "disable") - Don't sustain voice past the current interaction.
  - Preference("voice sustain", "toggle") - Toggle voice sustain.
  - Preference("music mute", "enable") - Mute the music mixer.
  - Preference("music mute", "disable") - Un-mute the music mixer.
  - Preference("music mute", "toggle") - Toggle music mute.
  - Preference("sound mute", "enable") - Mute the sound mixer.
  - Preference("sound mute", "disable") - Un-mute the sound mixer.
  - Preference("sound mute", "toggle") - Toggle sound mute.
  - Preference("voice mute", "enable") - Mute the voice mixer.
  - Preference("voice mute", "disable") - Un-mute the voice mixer.
  - Preference("voice mute", "toggle") - Toggle voice mute.
  - Preference("all mute", "enable") - Mute all mixers.
  - Preference("all mute", "disable") - Unmute all mixers.
  - Preference("all mute", "toggle") - Toggle mute of all mixers.
  - Preference("music volume", 0.5) - Set the music volume.
  - Preference("sound volume", 0.5) - Set the sound volume.
  - Preference("voice volume", 0.5) - Set the voice volume.
  - Preference("emphasize audio", "enable") - Emphasize the audio channels found in `config.emphasize_audio_channels`.
  - Preference("emphasize audio", "disable") - Do not emphasize audio channels.
  - Preference("emphasize audio", "toggle") - Toggle emphasize audio.
  - Preference("self voicing", "enable") - Enables self-voicing.
  - Preference("self voicing", "disable") - Disable self-voicing.
  - Preference("self voicing", "toggle") - Toggles self-voicing.
  - Preference("clipboard voicing", "enable") - Enables clipboard-voicing.
  - Preference("clipboard voicing", "disable") - Disable clipboard-voicing.
  - Preference("clipboard voicing", "toggle") - Toggles clipboard-voicing.
  - Preference("rollback side", "left") - Touching the left side of the screen causes rollback.
  - Preference("rollback side", "right") - Touching the right side of the screen causes rollback.
  - Preference("rollback side", "disable") - Touching the screen will not cause rollback.

  Values that can be used with bars are:

  - Preference("text speed")
  - Preference("auto-forward time")
  - Preference("music volume")
  - Preference("sound volume")
  - Preference("voice volume")

### File Functions

These functions return useful information about files. They use the same default page as the file actions.

`FileCurrentPage`()

  Returns the current file page as a string.

`FileCurrentScreenshot`(empty=None, **properties)

  A displayable that shows the screenshot that will be saved with the current file, if a screenshot has been taken when entering a menu or with `FileTakeScreenshot()`.

  If there is no current screenshot, empty is shown in its place. (If empty is None, it defaults to `Null()`.)

`FileJson`(name, key=None, empty=None, missing=None, page=None)

  Accesses the Json information associated with name.

  If key is None, returns the entire Json other object, or empty if the slot is empty.

  Otherwise, this returns json[key] if key is defined on the json object of the save, missing if there is a save with the given name, but it does not contain key, or empty if the save slot is empty.

  Json is added to a save slot by callbacks registered using `config.save_json_callbacks`.

`FileLoadable`(name, page=None)

  This is a function that returns true if the file is loadable, and false otherwise.

`FileNewest`(name, page=None)

  Returns True if this is the newest file slot, or False otherwise.

`FilePageName`(auto='a', quick='q')

  Returns the name of the current file page, as a string. If a normal page, this returns the page number. Otherwise, it returns auto or quick.

`FileSaveName`(name, empty='', page=None)

  Return the save_name that was in effect when the file was saved, or empty if the file does not exist.

`FileScreenshot`(name, empty=None, page=None)

  Returns the screenshot associated with the given file. If the file is not loadable, then empty is returned, unless it's None, in which case, a Null displayable is created.

  The return value is a displayable.

`FileSlotName`(slot, slots_per_page, auto='a', quick='q', format='%s%d')

  Returns the name of the numbered slot. This assumes that slots on normal pages are numbered in a linear order starting with 1, and that page numbers start with 1. When slot is 2, and slots_per_page is 10, and the other variables are the defaults:

  - When the first page is showing, this returns "2".
  - When the second page is showing, this returns "12".
  - When the auto page is showing, this returns "a2".
  - When the quicksave page is showing, this returns "q2".
  slot
    The number of the slot to access.
  slots_per_page
    The number of slots per page.
  auto
    A prefix to use for the auto page.
  quick
    A prefix to use for the quick page.
  format
    The formatting code to use. This is given two arguments: A string giving the page prefix, and an integer giving the slot number.

`FileTime`(name, format='%b %d, %H:%M', empty='', page=None)

  Returns the time the file was saved, formatted according to the supplied format. If the file is not found, empty is returned.

  The return value is a string.

`FileUsedSlots`(page=None, highest_first=True)

  Returns a list of used numeric file slots on the page.

  page
    The name of the page that will be scanned. If None, the current page is used.
  highest_first
    If true, the highest-numbered file slot is listed first. Otherwise, the lowest-numbered slot is listed first.

### Side Image Functions

This function returns the side image to use.

`SideImage`()

  Returns the side image associated with the currently speaking character, or a Null displayable if no such side image exists.

### Tooltips

The tooltip class changes the screen when a button is hovered.

class `Tooltip`(default)

  A tooltip object can be used to define a portion of a screen that is updated when the mouse hovers an area.

  A tooltip object has a `value` field, which is set to the default value passed to the constructor when the tooltip is created. When a button using an action created by the tooltip is hovered, the value field changes to the value associated with the action.

  `Action`(value)

    Returns an action that is generally used as the hovered property of a button. When the button is hovered, the value field of this tooltip is set to value. When the buttton loses focus, the value field of this tooltip reverts to the default.

When using a tooltip with a screen, the usual behavior is to create a tooltip object in a default statement. The value of the tooltip and the action method can then be used within the screen. The order of use within a screen doesn't matter - it's possible to use the value before an action is used.

Tooltips can take on any value. While in the example below we use the text statement to display a string on the screen, it's also possible to use the add statement to add a displayable. More complex behavior is also possible.

    screen tooltip_test:

        default tt = Tooltip("No button selected.")

        frame:
            xfill True

            has vbox

            textbutton "One.":
                action Return(1)
                hovered tt.Action("The loneliest number.")

            textbutton "Two.":
                action Return(2)
                hovered tt.Action("Is what it takes.")

            textbutton "Three.":
                action Return(3)
                hovered tt.Action("A crowd.")

            text tt.value

### Navigation

- index
- next |
- previous |
- Ren'Py Home |
- Ren'Py Documentation