### 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.

`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.

`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.

`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)

  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.

`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)

  "Does the right thing" with the file. This means loading it if the load screen is showing, and saving to it 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 will be used.
  page
    The page that the file will be saved to or loaded from. If None, the current page is used.

`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, prompt if loading the file will end the game.
  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.

`FilePage`(page)

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

`FilePageNext`(max=None)

  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.

`FilePagePrevious`(self)

  Goes to the previous file page, if possible.

`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 will be used.
  confirm
    If true, then we will prompt before overwriting a file.
  newest
    If true, then this file will be marked as the newest save file when it's saved.
  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.

`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 pictue of the screen before a file save screen is shown.

`QuickLoad`()

  Performs a quick load.

`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, **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.

  Any 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.

`Stop`(channel, **kwargs)

  Causes an audio channel to be stopped.

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

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

### Other Actions

These are other actions, not found anywhere else.

`Help`(help=None)

  Displays help.

  help
    If this is a string giving a label in the programe, 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 wayt.

`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.

`Notify`(message)

  Displays message using `renpy.notify()`.

`OpenURL`(url)

  Causes url to be opened in a web browser.

`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) ]

`Skip`()

  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.

`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.

`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 approprate 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", "toggle") - toggle display mode.
  - Preference("transitions", "all") - show all transitions.
  - Preference("transitions", "none") - do not show transitions.
  - Preference("transitions", "toggle") - toggle transitions.
  - 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("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("music volume", 0.5) - Set the music volume.
  - Preference("sound volume", 0.5) - Set the sound volume.
  - Preference("volice volume", 0.5) - Set the voice volume.

  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.

`FileLoadable`(name, page=None)

  This is a function that returns true if the file is loadable, and 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 defauts:

  - When the first page is slowing, 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`(prefix_tag='side')

  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 creadted 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