1035 lines
75 KiB
HTML
1035 lines
75 KiB
HTML
<!DOCTYPE html>
|
||
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<title>Saving, Loading, and Rollback — Ren'Py Documentation</title>
|
||
<link rel="stylesheet" href="_static/renpydoc.css" type="text/css" />
|
||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/bootstrap-3.3.6/css/bootstrap.min.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/bootstrap-3.3.6/css/bootstrap-theme.min.css" />
|
||
<link rel="stylesheet" type="text/css" href="_static/bootstrap-sphinx.css" />
|
||
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||
<script type="text/javascript" src="_static/language_data.js"></script>
|
||
<script type="text/javascript" src="_static/js/jquery-1.11.0.min.js"></script>
|
||
<script type="text/javascript" src="_static/js/jquery-fix.js"></script>
|
||
<script type="text/javascript" src="_static/bootstrap-3.3.6/js/bootstrap.min.js"></script>
|
||
<script type="text/javascript" src="_static/bootstrap-sphinx.js"></script>
|
||
<link rel="index" title="Index" href="genindex.html" />
|
||
<link rel="search" title="Search" href="search.html" />
|
||
<link rel="next" title="Persistent Data" href="persistent.html" />
|
||
<link rel="prev" title="Statement Equivalents" href="statement_equivalents.html" />
|
||
<meta charset='utf-8'>
|
||
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
|
||
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
|
||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||
|
||
</head><body>
|
||
|
||
<div id="navbar" class="navbar navbar-default navbar-fixed-top">
|
||
<div class="container">
|
||
<div class="navbar-header">
|
||
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
|
||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
</button>
|
||
<a class="navbar-brand" href="index.html">
|
||
Ren'Py Documentation</a>
|
||
<span class="navbar-text navbar-version pull-left"><b>7.5.3</b></span>
|
||
</div>
|
||
|
||
<div class="collapse navbar-collapse nav-collapse">
|
||
<ul class="nav navbar-nav">
|
||
|
||
<li><a href="https://www.renpy.org">Home Page</a></li>
|
||
<li><a href="https://www.renpy.org/doc/html/">Online Documentation</a></li>
|
||
|
||
|
||
<li class="dropdown globaltoc-container">
|
||
<a role="button"
|
||
id="dLabelGlobalToc"
|
||
data-toggle="dropdown"
|
||
data-target="#"
|
||
href="index.html">Site <b class="caret"></b></a>
|
||
<ul class="dropdown-menu globaltoc"
|
||
role="menu"
|
||
aria-labelledby="dLabelGlobalToc"><ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quickstart</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="gui.html">GUI Customization Guide</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="language_basics.html">Language Basics</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="label.html">Labels & Control Flow</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="dialogue.html">Dialogue and Narration</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="displaying_images.html">Displaying Images</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="menus.html">In-Game Menus</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="python.html">Python Statements</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="conditional.html">Conditional Statements</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="audio.html">Audio</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="movie.html">Movie</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="voice.html">Voice</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="text.html">Text</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="translation.html">Translation</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="displayables.html">Displayables</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="transforms.html">Transforms</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="transitions.html">Transitions</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="atl.html">Animation and Transformation Language</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="matrixcolor.html">Matrixcolor</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="layeredimage.html">Layered Images</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="3dstage.html">3D Stage</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="live2d.html">Live2D Cubism</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="style.html">Styles</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="style_properties.html">Style Properties</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="screens.html">Screens and Screen Language</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="screen_actions.html">Screen Actions, Values, and Functions</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="screen_special.html">Special Screen Names</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="screen_optimization.html">Screen Language Optimization</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="config.html">Configuration Variables</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="preferences.html">Preference Variables</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="store_variables.html">Store Variables</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="mouse.html">Custom Mouse Cursors</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="launcher.html">Launcher</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="developer_tools.html">Developer Tools</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="director.html">Interactive Director</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="nvl_mode.html">NVL-Mode Tutorial</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="input.html">Text Input</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="side_image.html">Side Images</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="rooms.html">Image Gallery, Music Room, and Replay Actions</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="drag_drop.html">Drag and Drop</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="sprites.html">Sprites</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="keymap.html">Customizing the Keymap</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="achievement.html">Achievements</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="history.html">Dialogue History</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="multiple.html">Multiple Character Dialogue</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="splashscreen_presplash.html">Splashscreen and Presplash</a></li>
|
||
</ul>
|
||
<ul class="current">
|
||
<li class="toctree-l1"><a class="reference internal" href="statement_equivalents.html">Statement Equivalents</a></li>
|
||
<li class="toctree-l1 current"><a class="current reference internal" href="#">Saving, Loading, and Rollback</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="persistent.html">Persistent Data</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="trans_trans_python.html">Transforms and Transitions in Python</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="gui_advanced.html">Advanced GUI</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="screen_python.html">Screens and Python</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="modes.html">Modes</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="cdd.html">Creator-Defined Displayables</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="cds.html">Creator-Defined Statements</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="custom_text_tags.html">Custom Text Tags</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="character_callbacks.html">Character Callbacks</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="file_python.html">File Access</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="color_class.html">Color Class</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="matrix.html">Matrix</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="model.html">Model-Based Rendering</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="other.html">Other Functions and Variables</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="build.html">Building Distributions</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="updater.html">Web Updater</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="android.html">Android</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="chromeos.html">Chrome OS/Chromebook</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="ios.html">iOS</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="iap.html">In-App Purchasing</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="gesture.html">Gestures</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="raspi.html">Raspberry Pi</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="security.html">Security</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="problems.html">Dealing with Problems</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="environment_variables.html">Environment Variables</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="self_voicing.html">Self-Voicing</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="editor.html">Text Editor Integration</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="skins.html">Skins</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="translating_renpy.html">Translating Ren'Py</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog (Ren'Py 7.x-)</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="changelog6.html">Changelog (Ren'Py 6.11 - 6.99)</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="incompatible.html">Incompatible Changes</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="distributor.html">Distributor Notes</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="credits.html">Credits</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="sponsors.html">Ren'Py Development Sponsors</a></li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="thequestion.html">Script of The Question</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="thequestion_nvl.html">NVL-mode script for The Question</a></li>
|
||
</ul>
|
||
</ul>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</ul>
|
||
|
||
|
||
|
||
<form class="navbar-form navbar-right" action="search.html" method="get">
|
||
<div class="form-group">
|
||
<input type="text" name="q" class="form-control" placeholder="Search" />
|
||
</div>
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="container">
|
||
<div class="row">
|
||
<div class="col-md-3">
|
||
<div id="sidebar" class="bs-sidenav" role="complementary"><ul>
|
||
<li><a class="reference internal" href="#">Saving, Loading, and Rollback</a><ul>
|
||
<li><a class="reference internal" href="#what-is-saved">What is Saved</a></li>
|
||
<li><a class="reference internal" href="#what-isn-t-saved">What isn't Saved</a></li>
|
||
<li><a class="reference internal" href="#where-ren-py-saves">Where Ren'Py Saves</a></li>
|
||
<li><a class="reference internal" href="#what-ren-py-can-save">What Ren'Py Can Save</a></li>
|
||
<li><a class="reference internal" href="#what-ren-py-can-t-save">What Ren'Py Can't Save</a></li>
|
||
<li><a class="reference internal" href="#save-functions-and-variables">Save Functions and Variables</a></li>
|
||
<li><a class="reference internal" href="#retaining-data-after-load">Retaining Data After Load</a></li>
|
||
<li><a class="reference internal" href="#rollback">Rollback</a></li>
|
||
<li><a class="reference internal" href="#what-data-is-rolled-back">What Data is Rolled Back?</a></li>
|
||
<li><a class="reference internal" href="#supporting-rollback-and-roll-forward">Supporting Rollback and Roll Forward</a></li>
|
||
<li><a class="reference internal" href="#blocking-rollback">Blocking Rollback</a></li>
|
||
<li><a class="reference internal" href="#fixing-rollback">Fixing Rollback</a></li>
|
||
<li><a class="reference internal" href="#styling-fixed-rollback">Styling Fixed Rollback</a></li>
|
||
<li><a class="reference internal" href="#fixed-rollback-and-custom-screens">Fixed Rollback and Custom Screens</a></li>
|
||
<li><a class="reference internal" href="#rollback-blocking-and-fixing-functions">Rollback-blocking and -fixing Functions</a></li>
|
||
<li><a class="reference internal" href="#norollback">NoRollback</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="col-md-9 content">
|
||
|
||
<div class="section" id="saving-loading-and-rollback">
|
||
<h1>Saving, Loading, and Rollback<a class="headerlink" href="#saving-loading-and-rollback" title="Permalink to this headline"> link</a></h1>
|
||
<p>Ren'Py has support for saving game state, loading game state, and rolling
|
||
back to a previous game state. Although implemented in a slightly different
|
||
fashion, rollback can be thought of as saving the game at the start of each
|
||
statement that interacts with the user, and loading saves when the user
|
||
rolls back.</p>
|
||
<div class="admonition note">
|
||
<p class="first admonition-title">Note</p>
|
||
<p class="last">While we usually attempt to keep save compatibility between releases, this
|
||
compatibility is not guaranteed. We may decide to break save-compatibility
|
||
if doing so provides a sufficiently large benefit.</p>
|
||
</div>
|
||
<div class="section" id="what-is-saved">
|
||
<h2>What is Saved<a class="headerlink" href="#what-is-saved" title="Permalink to this headline"> link</a></h2>
|
||
<p>Ren'Py attempts to save the game state. This includes both internal state
|
||
and Python state.</p>
|
||
<p>The internal state consists of all aspects of Ren'Py that are intented to
|
||
change once the game has started, and includes:</p>
|
||
<ul class="simple">
|
||
<li>The current statement, and all statements that can be returned to.</li>
|
||
<li>The images and displayables that are being shown.</li>
|
||
<li>The screens being shown, and the values of variables within those
|
||
screens.</li>
|
||
<li>The music that Ren'Py is playing.</li>
|
||
<li>The list of nvl-mode text blocks.</li>
|
||
</ul>
|
||
<p>The Python state consists of the variables in the store that have changed since
|
||
the game began, and all objects reachable from those variables. Note that it's
|
||
the change to the variables that matters – changes to fields in objects will
|
||
not cause those objects to be saved.</p>
|
||
<p>Variables set using the <a class="reference internal" href="python.html#default-statement"><span class="std std-ref">default statement</span></a> will
|
||
always be saved.</p>
|
||
<p>In this example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">define</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">1</span>
|
||
<span class="k">define</span> <span class="n">o</span> <span class="o">=</span> <span class="nb">object</span><span class="p">()</span>
|
||
<span class="k">default</span> <span class="n">c</span> <span class="o">=</span> <span class="mi">17</span>
|
||
|
||
<span class="k">label</span> <span class="n">start</span><span class="p">:</span>
|
||
<span class="k">$</span> <span class="n">b</span> <span class="o">=</span> <span class="mi">1</span>
|
||
<span class="k">$</span> <span class="n">o</span><span class="o">.</span><span class="na">value</span> <span class="o">=</span> <span class="mi">42</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>only <cite>b</cite> and <cite>c</cite> will be saved. <cite>A</cite> will not be saved because it does not change once
|
||
the game begins. <cite>O</cite> is not saved because it does not change – the object it
|
||
refers to changes, but the variable itself does not.</p>
|
||
</div>
|
||
<div class="section" id="what-isn-t-saved">
|
||
<h2>What isn't Saved<a class="headerlink" href="#what-isn-t-saved" title="Permalink to this headline"> link</a></h2>
|
||
<p>Python variables that are not changed after the game begins will not be
|
||
saved. This can be a major problem if a variable that is not saved and one that is
|
||
refer to the same object. (Alias the object.) In this example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">init</span> <span class="k">python</span><span class="p">:</span>
|
||
<span class="n">a</span> <span class="o">=</span> <span class="nb">object</span><span class="p">()</span>
|
||
<span class="n">a</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="mi">1</span>
|
||
|
||
<span class="k">label</span> <span class="n">start</span><span class="p">:</span>
|
||
<span class="k">$</span> <span class="n">b</span> <span class="o">=</span> <span class="n">a</span>
|
||
<span class="k">$</span> <span class="n">b</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="mi">2</span>
|
||
|
||
<span class="s2">"a.f=[a.f] b.f=[b.f]"</span>
|
||
</pre></div>
|
||
</div>
|
||
<p><cite>a</cite> and <cite>b</cite> are aliased. Saving and loading may break this aliasing, causing
|
||
<cite>a</cite> and <cite>b</cite> to refer to different objects. Since this can be very confusing,
|
||
it's best to avoid aliasing saved and unsaved variables. (This is rare to
|
||
encounter directly, but might come up when an unsaved variable and saved field
|
||
alias.)</p>
|
||
<p>There are several other kinds of state that isn't saved:</p>
|
||
<dl class="docutils">
|
||
<dt>control flow path</dt>
|
||
<dd>Ren'Py only saves the current statement, and the statement it needs
|
||
to return to. It doesn't remember how it got there. Importantly, statements
|
||
(including variable assignments) that are added to the game won't run.</dd>
|
||
<dt>mappings of image names to displayables</dt>
|
||
<dd>Since this mapping is not saved, the image may change to a new image
|
||
when the game loads again. This allows an image to change to a new
|
||
file as the game evolves.</dd>
|
||
<dt>configuration variables, styles, and style properties</dt>
|
||
<dd>Configuration variables and styles aren't saved as part of the game.
|
||
Therefore, they should only be changed in <code class="docutils literal notranslate"><span class="pre">init</span></code> blocks, and left alone
|
||
once the game has started.</dd>
|
||
</dl>
|
||
</div>
|
||
<div class="section" id="where-ren-py-saves">
|
||
<h2>Where Ren'Py Saves<a class="headerlink" href="#where-ren-py-saves" title="Permalink to this headline"> link</a></h2>
|
||
<p>Saves occur at the start of a Ren'Py statement in the outermost interaction
|
||
context.</p>
|
||
<p>What's important here is to note that saving occurs at the <strong>start</strong> of a
|
||
statement. If a load or rollback occurs in the middle of a statement that
|
||
interacts multiple times, the state will be the state that was active
|
||
when the statement began.</p>
|
||
<p>This can be a problem in Python-defined statements. In:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">python</span><span class="p">:</span>
|
||
|
||
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
|
||
|
||
<span class="k">while</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">10</span><span class="p">:</span>
|
||
|
||
<span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
|
||
|
||
<span class="n">narrator</span><span class="p">(</span><span class="s2">"The count is now [i]."</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>if the user saves and loads in the middle, the loop will begin anew. Using
|
||
Ren'Py script – rather than Python – to loop avoids this problem.:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">$</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
|
||
|
||
<span class="k">while</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">10</span><span class="p">:</span>
|
||
|
||
<span class="k">$</span> <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
|
||
|
||
<span class="s2">"The count is now [i]."</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="what-ren-py-can-save">
|
||
<h2>What Ren'Py Can Save<a class="headerlink" href="#what-ren-py-can-save" title="Permalink to this headline"> link</a></h2>
|
||
<p>Ren'Py uses the Python pickle system to save game state. This module can
|
||
save:</p>
|
||
<ul class="simple">
|
||
<li>Basic types, such as True, False, None, int, str, float, complex, str, and Unicode objects.</li>
|
||
<li>Compound types, like lists, tuples, sets, and dicts.</li>
|
||
<li>Creator-defined objects, classes, functions, methods, and bound methods. For
|
||
pickling these functions to succeed, they must remain available under their
|
||
original names.</li>
|
||
<li>Character, Displayable, Transform, and Transition objects.</li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="what-ren-py-can-t-save">
|
||
<span id="cant-save"></span><h2>What Ren'Py Can't Save<a class="headerlink" href="#what-ren-py-can-t-save" title="Permalink to this headline"> link</a></h2>
|
||
<p>There are certain types that cannot be pickled:</p>
|
||
<ul class="simple">
|
||
<li>Render objects.</li>
|
||
<li>Iterator objects.</li>
|
||
<li>Generator objects.</li>
|
||
<li>Coroutine tasks and futures, like those created with <code class="docutils literal notranslate"><span class="pre">async</span></code> and <code class="docutils literal notranslate"><span class="pre">await</span></code>.</li>
|
||
<li>File-like objects.</li>
|
||
<li>Network sockets, and objects that enclose them.</li>
|
||
<li>Inner functions and lambdas.</li>
|
||
</ul>
|
||
<p>This may not be an exhaustive list.</p>
|
||
<p>Objects that can't be pickled can still be used, provided that their use
|
||
is combined to namespaces that aren't saved by Ren'Py (like init variables,
|
||
namespaces inside functions, or <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">hide</span></code> blocks.)</p>
|
||
<p>For example, using a file object like:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">$</span> <span class="n">monika_file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">gamedir</span> <span class="o">+</span> <span class="s2">"/monika.chr"</span><span class="p">,</span> <span class="s2">"w"</span><span class="p">)</span>
|
||
<span class="k">$</span> <span class="n">monika_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"Do not delete.</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">)</span>
|
||
<span class="k">$</span> <span class="n">monika_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Won't work, as <code class="docutils literal notranslate"><span class="pre">f</span></code> could be saved between any of the three Python statements.
|
||
Putting this in a <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">hide</span></code> block will work:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">python</span> <span class="k">hide</span><span class="p">:</span>
|
||
|
||
<span class="n">monika_file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">gamedir</span> <span class="o">+</span> <span class="s2">"/monika.chr"</span><span class="p">,</span> <span class="s2">"w"</span><span class="p">)</span>
|
||
<span class="n">monika_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"Do not delete.</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">)</span>
|
||
<span class="n">monika_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(Of course, using the python <code class="docutils literal notranslate"><span class="pre">with</span></code> statement would be cleaner.)</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">python</span> <span class="k">hide</span><span class="p">:</span>
|
||
|
||
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">config</span><span class="o">.</span><span class="n">gamedir</span> <span class="o">+</span> <span class="s2">"/monika.chr"</span><span class="p">,</span> <span class="s2">"w"</span><span class="p">)</span> <span class="k">as</span> <span class="n">monika_file</span><span class="p">:</span>
|
||
<span class="n">monika_file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"Do not delete.</span><span class="se">\r\n</span><span class="s2">"</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Coroutines, like those made with <code class="docutils literal notranslate"><span class="pre">async</span></code>, <code class="docutils literal notranslate"><span class="pre">await</span></code>, or the <code class="docutils literal notranslate"><span class="pre">asyncio</span></code>
|
||
are similar. If you have:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">init</span> <span class="k">python</span><span class="p">:</span>
|
||
|
||
<span class="kn">import</span> <span class="nn">asyncio</span>
|
||
|
||
<span class="k">async</span> <span class="k">def</span> <span class="nf">sleep_func</span><span class="p">():</span>
|
||
<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
||
<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>then:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">$</span> <span class="n">sleep_task</span> <span class="o">=</span> <span class="n">sleep_func</span><span class="p">()</span>
|
||
<span class="k">$</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">sleep_task</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>will have problems, since <cite>sleep_task</cite> can't be saved. But if it's not assigned
|
||
to a variable:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">$</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">sleep_func</span><span class="p">())</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>will run fine.</p>
|
||
</div>
|
||
<div class="section" id="save-functions-and-variables">
|
||
<h2>Save Functions and Variables<a class="headerlink" href="#save-functions-and-variables" title="Permalink to this headline"> link</a></h2>
|
||
<p>There is one variable that is used by the high-level save system:</p>
|
||
<dl class="var">
|
||
<dt id="var-save_name">
|
||
<code class="descname">save_name</code> = ...<a class="headerlink" href="#var-save_name" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>This is a string that is stored with each save. It can be used to give
|
||
a name to the save, to help users tell them apart.</p>
|
||
<p>More per-save data customization can be done with the Json supplementary
|
||
data system, see <a class="reference internal" href="config.html#var-config.save_json_callbacks"><code class="xref std std-var docutils literal notranslate"><span class="pre">config.save_json_callbacks</span></code></a>.</p>
|
||
</dd></dl>
|
||
|
||
<p>There are a number of high-level save actions and functions defined in the
|
||
<a class="reference internal" href="screen_actions.html"><span class="doc">screen actions</span></a>. In addition, there are the following
|
||
low-level save and load actions.</p>
|
||
<dl class="function">
|
||
<dt id="renpy.can_load">
|
||
<code class="descclassname">renpy.</code><code class="descname">can_load</code><span class="sig-paren">(</span><em>filename</em>, <em>test=False</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.can_load" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns true if <cite>filename</cite> exists as a save slot, and False otherwise.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.copy_save">
|
||
<code class="descclassname">renpy.</code><code class="descname">copy_save</code><span class="sig-paren">(</span><em>old</em>, <em>new</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.copy_save" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Copies the save at <cite>old</cite> to <cite>new</cite>. (Does nothing if <cite>old</cite> does not
|
||
exist.)</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.list_saved_games">
|
||
<code class="descclassname">renpy.</code><code class="descname">list_saved_games</code><span class="sig-paren">(</span><em>regexp=u'.'</em>, <em>fast=False</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.list_saved_games" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Lists the save games. For each save game, returns a tuple containing:</p>
|
||
<ul class="simple">
|
||
<li>The filename of the save.</li>
|
||
<li>The extra_info that was passed in.</li>
|
||
<li>A displayable that, when displayed, shows the screenshot that was
|
||
used when saving the game.</li>
|
||
<li>The time the game was stayed at, in seconds since the UNIX epoch.</li>
|
||
</ul>
|
||
<dl class="docutils">
|
||
<dt><cite>regexp</cite></dt>
|
||
<dd>A regular expression that is matched against the start of the
|
||
filename to filter the list.</dd>
|
||
<dt><cite>fast</cite></dt>
|
||
<dd>If fast is true, the filename is returned instead of the
|
||
tuple.</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.list_slots">
|
||
<code class="descclassname">renpy.</code><code class="descname">list_slots</code><span class="sig-paren">(</span><em>regexp=None</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.list_slots" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns a list of non-empty save slots. If <cite>regexp</cite> exists, only slots
|
||
that begin with <cite>regexp</cite> are returned. The slots are sorted in
|
||
string-order.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.load">
|
||
<code class="descclassname">renpy.</code><code class="descname">load</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.load" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Loads the game state from the save slot <cite>filename</cite>. If the file is loaded
|
||
successfully, this function never returns.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.newest_slot">
|
||
<code class="descclassname">renpy.</code><code class="descname">newest_slot</code><span class="sig-paren">(</span><em>regexp=None</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.newest_slot" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns the name of the newest save slot (the save slot with the most
|
||
recent modification time), or None if there are no (matching) saves.</p>
|
||
<p>If <cite>regexp</cite> exists, only slots that begin with <cite>regexp</cite> are returned.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.rename_save">
|
||
<code class="descclassname">renpy.</code><code class="descname">rename_save</code><span class="sig-paren">(</span><em>old</em>, <em>new</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.rename_save" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Renames a save from <cite>old</cite> to <cite>new</cite>. (Does nothing if <cite>old</cite> does not
|
||
exist.)</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.save">
|
||
<code class="descclassname">renpy.</code><code class="descname">save</code><span class="sig-paren">(</span><em>filename</em>, <em>extra_info=''</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.save" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Saves the game state to a save slot.</p>
|
||
<dl class="docutils">
|
||
<dt><cite>filename</cite></dt>
|
||
<dd>A string giving the name of a save slot. Despite the variable name,
|
||
this corresponds only loosely to filenames.</dd>
|
||
<dt><cite>extra_info</cite></dt>
|
||
<dd>An additional string that should be saved to the save file. Usually,
|
||
this is the value of <a class="reference internal" href="store_variables.html#var-save_name"><code class="xref std std-var docutils literal notranslate"><span class="pre">save_name</span></code></a>.</dd>
|
||
</dl>
|
||
<p><a class="reference internal" href="#renpy.take_screenshot" title="renpy.take_screenshot"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.take_screenshot()</span></code></a> should be called before this function.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.slot_json">
|
||
<code class="descclassname">renpy.</code><code class="descname">slot_json</code><span class="sig-paren">(</span><em>slotname</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.slot_json" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns the json information for <cite>slotname</cite>, or None if the slot is
|
||
empty.</p>
|
||
<p>Much like the <code class="docutils literal notranslate"><span class="pre">d</span></code> argument to the <code class="xref std std-var docutils literal notranslate"><span class="pre">config.save_json_callback</span></code>
|
||
function, it will be returned as a dictionary. More precisely, the
|
||
dictionary will contain the same data as it did when the game was saved.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.slot_mtime">
|
||
<code class="descclassname">renpy.</code><code class="descname">slot_mtime</code><span class="sig-paren">(</span><em>slotname</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.slot_mtime" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns the modification time for <cite>slot</cite>, or None if the slot is empty.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.slot_screenshot">
|
||
<code class="descclassname">renpy.</code><code class="descname">slot_screenshot</code><span class="sig-paren">(</span><em>slotname</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.slot_screenshot" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns a display that can be used as the screenshot for <cite>slotname</cite>,
|
||
or None if the slot is empty.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.take_screenshot">
|
||
<code class="descclassname">renpy.</code><code class="descname">take_screenshot</code><span class="sig-paren">(</span><em>scale=None</em>, <em>background=False</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.take_screenshot" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Causes a screenshot to be taken. This screenshot will be saved as part of
|
||
a save game.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.unlink_save">
|
||
<code class="descclassname">renpy.</code><code class="descname">unlink_save</code><span class="sig-paren">(</span><em>filename</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.unlink_save" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Deletes the save slot with the given name.</p>
|
||
</dd></dl>
|
||
|
||
</div>
|
||
<div class="section" id="retaining-data-after-load">
|
||
<h2>Retaining Data After Load<a class="headerlink" href="#retaining-data-after-load" title="Permalink to this headline"> link</a></h2>
|
||
<p>When a game is loaded, the state of the game is reset (using the rollback
|
||
system described below) to the state of the game when the current statement
|
||
began executing.</p>
|
||
<p>In some cases, this may not be desirable. For example, when a screen allows
|
||
editing of a value, we may want to retain that value when the game is
|
||
loaded. When renpy.retain_after_load is called, data will not be reverted
|
||
when a game is saved and loaded before the end of the next checkpointed
|
||
interaction.</p>
|
||
<p>Note that while data is not changed, control is reset to the start of the
|
||
current statement. That statement will execute again, with the new data
|
||
in place at the start of the statement.</p>
|
||
<p>For example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">screen</span> <span class="n">edit_value</span><span class="p">:</span>
|
||
<span class="k">hbox</span><span class="p">:</span>
|
||
<span class="k">text</span> <span class="s2">"[value]"</span>
|
||
<span class="k">textbutton</span> <span class="s2">"+"</span> <span class="na">action</span> <span class="n">SetVariable</span><span class="p">(</span><span class="s2">"value"</span><span class="p">,</span> <span class="na">value</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
|
||
<span class="k">textbutton</span> <span class="s2">"-"</span> <span class="na">action</span> <span class="n">SetVariable</span><span class="p">(</span><span class="s2">"value"</span><span class="p">,</span> <span class="na">value</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span>
|
||
<span class="k">textbutton</span> <span class="s2">"+"</span> <span class="na">action</span> <span class="n">Return</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
|
||
|
||
<span class="k">label</span> <span class="n">start</span><span class="p">:</span>
|
||
<span class="k">$</span> <span class="na">value</span> <span class="o">=</span> <span class="mi">0</span>
|
||
<span class="k">$</span> <span class="n">renpy</span><span class="o">.</span><span class="n">retain_after_load</span><span class="p">()</span>
|
||
<span class="k">call</span> <span class="k">screen</span> <span class="n">edit_value</span>
|
||
</pre></div>
|
||
</div>
|
||
<dl class="function">
|
||
<dt id="renpy.retain_after_load">
|
||
<code class="descclassname">renpy.</code><code class="descname">retain_after_load</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#renpy.retain_after_load" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Causes data modified between the current statement and the statement
|
||
containing the next checkpoint to be retained when a load occurs.</p>
|
||
</dd></dl>
|
||
|
||
</div>
|
||
<div class="section" id="rollback">
|
||
<h2>Rollback<a class="headerlink" href="#rollback" title="Permalink to this headline"> link</a></h2>
|
||
<p>Rollback allows the user to revert the game to an earlier state in
|
||
much the same way as undo/redo systems that are available in most
|
||
modern applications. While the system takes care of maintaining the
|
||
visuals and game variables during rollback events, there are several
|
||
things that should be considered while creating a game.</p>
|
||
</div>
|
||
<div class="section" id="what-data-is-rolled-back">
|
||
<h2>What Data is Rolled Back?<a class="headerlink" href="#what-data-is-rolled-back" title="Permalink to this headline"> link</a></h2>
|
||
<p>Rollback affects variables that have been changed after the init phase, and
|
||
objects of revertable types reachable from those variables. The short version
|
||
is that lists, dicts, and sets created in Ren'Py script are revertable as are
|
||
instances of classes defined in Ren'Py scripts. Data created inside Python
|
||
or inside Ren'Py usually isn't revertable.</p>
|
||
<p>In more detail, inside the stores
|
||
that Python embedded inside Ren'Py scripts run in, the object, list, dict, and
|
||
set types have been replaced with equivalent types that are revertable. Objects
|
||
that inherit from these types are also revertable. The <a class="reference internal" href="cdd.html#renpy.Displayable" title="renpy.Displayable"><code class="xref py py-class docutils literal notranslate"><span class="pre">renpy.Displayable</span></code></a>
|
||
type inherits from the revertable object type.</p>
|
||
<p>To make the use of revertable objects more convenient, Ren'Py modifies Python
|
||
found inside Ren'Py script files in the following way.</p>
|
||
<ul class="simple">
|
||
<li>Literal lists, dicts, and sets are automatically converted to the
|
||
revertable equivalent.</li>
|
||
<li>List, dict, and set comprehensions are also automatically converted to
|
||
the revertable equivalent.</li>
|
||
<li>Other python syntax, such as extended unpacking, that can create lists,
|
||
dicts, or sets converts the result to the revertable equivalent. However,
|
||
for performance reasons, double-starred parameters to functions and methods
|
||
(that create dictionaries of extra keyword arguments) are not converted
|
||
to revertable objects.</li>
|
||
<li>Classes that do not inherit from any other types automatically inherit
|
||
from the revertable object.</li>
|
||
</ul>
|
||
<p>In addition:</p>
|
||
<ul class="simple">
|
||
<li>The methods and operators of revertable types have been modified to return
|
||
revertable objects when a list, dict, or set is produced.</li>
|
||
<li>Built in functions that return lists, dicts, and sets return a revertable
|
||
equivalent.</li>
|
||
</ul>
|
||
<p>Calling into Python code will not generally produce a revertable object. Some
|
||
cases where you'll get an object that may not participate in rollback are:</p>
|
||
<ul class="simple">
|
||
<li>Calling methods on built-in types, like the str.split method.</li>
|
||
<li>When the object is created in a Python module that's been imported, and
|
||
then return to Ren'Py. (For example, an instance of collections.defaultdict
|
||
won't participate in rollback.)</li>
|
||
<li>Objects returned from Ren'Py's API, unless documented otherwise.</li>
|
||
</ul>
|
||
<p>If such data needs to participate in rollback, it may make sense to convert
|
||
it to a type that does partipate. For example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="c1"># Calling list inside Python-in-Ren'Py converts a non-revertable list</span>
|
||
<span class="c1"># into a revertable one.</span>
|
||
<span class="k">$</span> <span class="n">attrs</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">renpy</span><span class="o">.</span><span class="n">get_attributes</span><span class="p">(</span><span class="s2">"eileen"</span><span class="p">))</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="supporting-rollback-and-roll-forward">
|
||
<h2>Supporting Rollback and Roll Forward<a class="headerlink" href="#supporting-rollback-and-roll-forward" title="Permalink to this headline"> link</a></h2>
|
||
<p>Most Ren'Py statements automatically support rollback and roll forward. If
|
||
you call <a class="reference internal" href="screen_python.html#ui.interact" title="ui.interact"><code class="xref py py-func docutils literal notranslate"><span class="pre">ui.interact()</span></code></a> directly, you'll need to add support for rollback
|
||
and roll-forward yourself. This can be done using the following structure:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="c1"># This is None if we're not rolling back, or else the value that was</span>
|
||
<span class="c1"># passed to checkpoint last time if we're rolling forward.</span>
|
||
<span class="na">roll_forward</span> <span class="o">=</span> <span class="n">renpy</span><span class="o">.</span><span class="n">roll_forward_info</span><span class="p">()</span>
|
||
|
||
<span class="c1"># Set up the screen here...</span>
|
||
|
||
<span class="c1"># Interact with the user.</span>
|
||
<span class="n">rv</span> <span class="o">=</span> <span class="n">ui</span><span class="o">.</span><span class="n">interact</span><span class="p">(</span><span class="na">roll_forward</span><span class="o">=</span><span class="na">roll_forward</span><span class="p">)</span>
|
||
|
||
<span class="c1"># Store the result of the interaction.</span>
|
||
<span class="n">renpy</span><span class="o">.</span><span class="n">checkpoint</span><span class="p">(</span><span class="n">rv</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>It's important that your game does not interact with the user after renpy.checkpoint
|
||
has been called. (If you do, the user may not be able to rollback.)</p>
|
||
<dl class="function">
|
||
<dt id="renpy.can_rollback">
|
||
<code class="descclassname">renpy.</code><code class="descname">can_rollback</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#renpy.can_rollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns true if we can rollback.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.checkpoint">
|
||
<code class="descclassname">renpy.</code><code class="descname">checkpoint</code><span class="sig-paren">(</span><em>data=None</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.checkpoint" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Makes the current statement a checkpoint that the user can rollback to. Once
|
||
this function has been called, there should be no more interaction with the
|
||
user in the current statement.</p>
|
||
<p>This will also clear the current screenshot used by saved games.</p>
|
||
<dl class="docutils">
|
||
<dt><cite>data</cite></dt>
|
||
<dd>This data is returned by <a class="reference internal" href="#renpy.roll_forward_info" title="renpy.roll_forward_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.roll_forward_info()</span></code></a> when the
|
||
game is being rolled back.</dd>
|
||
<dt><cite>hard</cite></dt>
|
||
<dd>If true, this is a hard checkpoint that rollback will stop at. If false,
|
||
this is a soft checkpoint that will not stop rollback.</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.get_identifier_checkpoints">
|
||
<code class="descclassname">renpy.</code><code class="descname">get_identifier_checkpoints</code><span class="sig-paren">(</span><em>identifier</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.get_identifier_checkpoints" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Given a rollback_identifier from a HistoryEntry object, returns the number
|
||
of checkpoints that need to be passed to <a class="reference internal" href="#renpy.rollback" title="renpy.rollback"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.rollback()</span></code></a> to reach
|
||
that identifier. Returns None of the identifier is not in the rollback
|
||
history.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.in_rollback">
|
||
<code class="descclassname">renpy.</code><code class="descname">in_rollback</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#renpy.in_rollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns true if the game has been rolled back.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.roll_forward_info">
|
||
<code class="descclassname">renpy.</code><code class="descname">roll_forward_info</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#renpy.roll_forward_info" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>When in rollback, returns the data that was supplied to <a class="reference internal" href="#renpy.checkpoint" title="renpy.checkpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.checkpoint()</span></code></a>
|
||
the last time this statement executed. Outside of rollback, returns None.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.rollback">
|
||
<code class="descclassname">renpy.</code><code class="descname">rollback</code><span class="sig-paren">(</span><em>force=False</em>, <em>checkpoints=1</em>, <em>defer=False</em>, <em>greedy=True</em>, <em>label=None</em>, <em>abnormal=True</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.rollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Rolls the state of the game back to the last checkpoint.</p>
|
||
<dl class="docutils">
|
||
<dt><cite>force</cite></dt>
|
||
<dd>If true, the rollback will occur in all circumstances. Otherwise,
|
||
the rollback will only occur if rollback is enabled in the store,
|
||
context, and config.</dd>
|
||
<dt><cite>checkpoints</cite></dt>
|
||
<dd>Ren'Py will roll back through this many calls to renpy.checkpoint. It
|
||
will roll back as far as it can, subject to this condition.</dd>
|
||
<dt><cite>defer</cite></dt>
|
||
<dd>If true, the call will be deferred until control returns to the main
|
||
context.</dd>
|
||
<dt><cite>greedy</cite></dt>
|
||
<dd>If true, rollback will finish just after the previous checkpoint.
|
||
If false, rollback finish just before the current checkpoint.</dd>
|
||
<dt><cite>label</cite></dt>
|
||
<dd>If not None, a label that is called when rollback completes.</dd>
|
||
<dt><cite>abnormal</cite></dt>
|
||
<dd>If true, the default, script executed after the transition is run in
|
||
an abnormal mode that skips transitions that would have otherwise
|
||
occured. Abnormal mode ends when an interaction begins.</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.suspend_rollback">
|
||
<code class="descclassname">renpy.</code><code class="descname">suspend_rollback</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#renpy.suspend_rollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Rollback will skip sections of the game where rollback has been
|
||
suspended.</p>
|
||
<dl class="docutils">
|
||
<dt><cite>flag</cite>:</dt>
|
||
<dd>When <cite>flag</cite> is true, rollback is suspended. When false,
|
||
rollback is resumed.</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
</div>
|
||
<div class="section" id="blocking-rollback">
|
||
<h2>Blocking Rollback<a class="headerlink" href="#blocking-rollback" title="Permalink to this headline"> link</a></h2>
|
||
<div class="admonition warning">
|
||
<p class="first admonition-title">Warning</p>
|
||
<p class="last">Blocking rollback is a user-unfriendly thing to do. If a user mistakenly
|
||
clicks on an unintended choice, he or she will be unable to correct their
|
||
mistake. Since rollback is equivalent to saving and loading, your users
|
||
will be forced to save more often, breaking game engagement.</p>
|
||
</div>
|
||
<p>It is possible to disable rollback in part or in full. If rollback is
|
||
not wanted at all, it can simply be turned off through the
|
||
<a class="reference internal" href="config.html#var-config.rollback_enabled"><code class="xref std std-var docutils literal notranslate"><span class="pre">config.rollback_enabled</span></code></a> option.</p>
|
||
<p>More common is a partial block of rollback. This can be achieved by the
|
||
<a class="reference internal" href="#renpy.block_rollback" title="renpy.block_rollback"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.block_rollback()</span></code></a> function. When called, it will instruct
|
||
Ren'Py not to roll back before that point. For example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">label</span> <span class="n">final_answer</span><span class="p">:</span>
|
||
<span class="s2">"Is that your final answer?"</span>
|
||
|
||
<span class="k">menu</span><span class="p">:</span>
|
||
<span class="s2">"Yes"</span><span class="p">:</span>
|
||
<span class="k">jump</span> <span class="n">no_return</span>
|
||
<span class="s2">"No"</span><span class="p">:</span>
|
||
<span class="s2">"We have ways of making you talk."</span>
|
||
<span class="s2">"You should contemplate them."</span>
|
||
<span class="s2">"I'll ask you one more time..."</span>
|
||
<span class="k">jump</span> <span class="n">final_answer</span>
|
||
|
||
<span class="k">label</span> <span class="n">no_return</span><span class="p">:</span>
|
||
<span class="k">$</span> <span class="n">renpy</span><span class="o">.</span><span class="n">block_rollback</span><span class="p">()</span>
|
||
|
||
<span class="s2">"So be it. There's no turning back now."</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>When the label no_return is reached, Ren'Py won't allow a rollback
|
||
back to the menu.</p>
|
||
</div>
|
||
<div class="section" id="fixing-rollback">
|
||
<h2>Fixing Rollback<a class="headerlink" href="#fixing-rollback" title="Permalink to this headline"> link</a></h2>
|
||
<p>Fixing rollback provides for an intermediate choice between
|
||
unconstrained rollback and blocking rollback entirely. Rollback is
|
||
allowed, but the user is not allowed to make changes to their
|
||
decisions. Fixing rollback is done with the <a class="reference internal" href="#renpy.fix_rollback" title="renpy.fix_rollback"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.fix_rollback()</span></code></a>
|
||
function, as shown in the following example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">label</span> <span class="n">final_answer</span><span class="p">:</span>
|
||
<span class="s2">"Is that your final answer?"</span>
|
||
<span class="k">menu</span><span class="p">:</span>
|
||
<span class="s2">"Yes"</span><span class="p">:</span>
|
||
<span class="k">jump</span> <span class="n">no_return</span>
|
||
<span class="s2">"No"</span><span class="p">:</span>
|
||
<span class="s2">"We have ways of making you talk."</span>
|
||
<span class="s2">"You should contemplate them."</span>
|
||
<span class="s2">"I'll ask you one more time..."</span>
|
||
<span class="k">jump</span> <span class="n">final_answer</span>
|
||
|
||
<span class="k">label</span> <span class="n">no_return</span><span class="p">:</span>
|
||
<span class="k">$</span> <span class="n">renpy</span><span class="o">.</span><span class="n">fix_rollback</span><span class="p">()</span>
|
||
|
||
<span class="s2">"So be it. There's no turning back now."</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Now, after the fix_rollback function is called, it will still be
|
||
possible for the user to roll back to the menu. However, it will not be
|
||
possible to make a different choice.</p>
|
||
<p>There are some caveats to consider when designing a game for
|
||
fix_rollback. Ren'Py will automatically take care of locking any data
|
||
that is given to <code class="xref py py-func docutils literal notranslate"><span class="pre">checkpoint()</span></code>. However, due to the generic nature
|
||
of Ren'Py, it is possible to write scripts that bypass this and
|
||
change things in ways that may have unpredictable results. Most notably,
|
||
<code class="docutils literal notranslate"><span class="pre">call</span> <span class="pre">screen</span></code> doesn't work well with fixed rollback. It is up
|
||
to the creator to block rollback at problematic locations.</p>
|
||
<p>The internal user interaction options for menus, <a class="reference internal" href="input.html#renpy.input" title="renpy.input"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.input()</span></code></a>
|
||
and <code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.imagemap()</span></code> are designed to fully work with fix_rollback.</p>
|
||
</div>
|
||
<div class="section" id="styling-fixed-rollback">
|
||
<h2>Styling Fixed Rollback<a class="headerlink" href="#styling-fixed-rollback" title="Permalink to this headline"> link</a></h2>
|
||
<p>Because fix_rollback changes the functionality of menus and imagemaps,
|
||
it is advisable to reflect this in the appearance. To do this, it is
|
||
important to understand how the widget states of the menu buttons are
|
||
changed. There are two modes that can be selected through the
|
||
<a class="reference internal" href="config.html#var-config.fix_rollback_without_choice"><code class="xref std std-var docutils literal notranslate"><span class="pre">config.fix_rollback_without_choice</span></code></a> option.</p>
|
||
<p>The default option will set the chosen option to "selected", thereby
|
||
activating the style properties with the "selected_" prefix. All other
|
||
buttons will be made insensitive and show using the properties with the
|
||
"insensitive_" prefix. Effectively this leaves the menu with a single
|
||
selectable choice.</p>
|
||
<p>When the <a class="reference internal" href="config.html#var-config.fix_rollback_without_choice"><code class="xref std std-var docutils literal notranslate"><span class="pre">config.fix_rollback_without_choice</span></code></a> option is set to
|
||
False, all buttons are made insensitive. This means that the chosen
|
||
option will use the "selected_insensitive_" prefix for the style
|
||
properties while the other buttons use properties with the
|
||
"insensitive_" prefix.</p>
|
||
</div>
|
||
<div class="section" id="fixed-rollback-and-custom-screens">
|
||
<h2>Fixed Rollback and Custom Screens<a class="headerlink" href="#fixed-rollback-and-custom-screens" title="Permalink to this headline"> link</a></h2>
|
||
<p>When writing custom Python routines that must play nice with the
|
||
fix_rollback system there are a few simple things to know. First of all
|
||
the <a class="reference internal" href="#renpy.in_fixed_rollback" title="renpy.in_fixed_rollback"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.in_fixed_rollback()</span></code></a> function can be used to determine whether
|
||
the game is currently in fixed rollback state. Second, when in
|
||
fixed rollback state, <a class="reference internal" href="screen_python.html#ui.interact" title="ui.interact"><code class="xref py py-func docutils literal notranslate"><span class="pre">ui.interact()</span></code></a> will always return the
|
||
supplied roll_forward data regardless of what action was performed. This
|
||
effectively means that when the <a class="reference internal" href="screen_python.html#ui.interact" title="ui.interact"><code class="xref py py-func docutils literal notranslate"><span class="pre">ui.interact()</span></code></a>/<a class="reference internal" href="#renpy.checkpoint" title="renpy.checkpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">renpy.checkpoint()</span></code></a>
|
||
functions are used, most of the work is done.</p>
|
||
<p>To simplify the creation of custom screens, two actions are
|
||
provided to help with the most common uses. The <a class="reference internal" href="#ui.ChoiceReturn" title="ui.ChoiceReturn"><code class="xref py py-func docutils literal notranslate"><span class="pre">ui.ChoiceReturn()</span></code></a> action
|
||
returns the value when the button it is attached to is clicked. The
|
||
<a class="reference internal" href="#ui.ChoiceJump" title="ui.ChoiceJump"><code class="xref py py-func docutils literal notranslate"><span class="pre">ui.ChoiceJump()</span></code></a> action can be used to jump to a script label. However, this
|
||
action only works properly when the screen is called trough a
|
||
<code class="docutils literal notranslate"><span class="pre">call</span> <span class="pre">screen</span></code> statement.</p>
|
||
<p>Example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">screen</span> <span class="n">demo_imagemap</span><span class="p">:</span>
|
||
<span class="k">imagemap</span><span class="p">:</span>
|
||
<span class="na">ground</span> <span class="s2">"imagemap_ground.jpg"</span>
|
||
<span class="na">hover</span> <span class="s2">"imagemap_hover.jpg"</span>
|
||
<span class="na">selected_idle</span> <span class="s2">"imagemap_selected_idle.jpg"</span>
|
||
<span class="na">selected_hover</span> <span class="s2">"imagemap_hover.jpg"</span>
|
||
|
||
<span class="k">hotspot</span> <span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">78</span><span class="p">)</span> <span class="na">action</span> <span class="n">ui</span><span class="o">.</span><span class="n">ChoiceJump</span><span class="p">(</span><span class="s2">"swimming"</span><span class="p">,</span> <span class="s2">"go_swimming"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||
<span class="k">hotspot</span> <span class="p">(</span><span class="mi">204</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">78</span><span class="p">)</span> <span class="na">action</span> <span class="n">ui</span><span class="o">.</span><span class="n">ChoiceJump</span><span class="p">(</span><span class="s2">"science"</span><span class="p">,</span> <span class="s2">"go_science_club"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||
<span class="k">hotspot</span> <span class="p">(</span><span class="mi">452</span><span class="p">,</span> <span class="mi">79</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">78</span><span class="p">)</span> <span class="na">action</span> <span class="n">ui</span><span class="o">.</span><span class="n">ChoiceJump</span><span class="p">(</span><span class="s2">"art"</span><span class="p">,</span> <span class="s2">"go_art_lessons"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||
<span class="k">hotspot</span> <span class="p">(</span><span class="mi">602</span><span class="p">,</span> <span class="mi">316</span><span class="p">,</span> <span class="mi">78</span><span class="p">,</span> <span class="mi">78</span><span class="p">)</span> <span class="na">action</span> <span class="n">ui</span><span class="o">.</span><span class="n">ChoiceJump</span><span class="p">(</span><span class="s2">"home"</span><span class="p">,</span> <span class="s2">"go_home"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">python</span><span class="p">:</span>
|
||
<span class="na">roll_forward</span> <span class="o">=</span> <span class="n">renpy</span><span class="o">.</span><span class="n">roll_forward_info</span><span class="p">()</span>
|
||
<span class="k">if</span> <span class="na">roll_forward</span> <span class="k">not</span> <span class="k">in</span> <span class="p">(</span><span class="s2">"Rock"</span><span class="p">,</span> <span class="s2">"Paper"</span><span class="p">,</span> <span class="s2">"Scissors"</span><span class="p">):</span>
|
||
<span class="na">roll_forward</span> <span class="o">=</span> <span class="kc">None</span>
|
||
|
||
<span class="n">ui</span><span class="o">.</span><span class="k">hbox</span><span class="p">()</span>
|
||
<span class="n">ui</span><span class="o">.</span><span class="k">imagebutton</span><span class="p">(</span><span class="s2">"rock.png"</span><span class="p">,</span> <span class="s2">"rock_hover.png"</span><span class="p">,</span> <span class="na">selected_insensitive</span><span class="o">=</span><span class="s2">"rock_hover.png"</span><span class="p">,</span> <span class="na">clicked</span><span class="o">=</span><span class="n">ui</span><span class="o">.</span><span class="n">ChoiceReturn</span><span class="p">(</span><span class="s2">"rock"</span><span class="p">,</span> <span class="s2">"Rock"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
|
||
<span class="n">ui</span><span class="o">.</span><span class="k">imagebutton</span><span class="p">(</span><span class="s2">"paper.png"</span><span class="p">,</span> <span class="s2">"paper_hover.png"</span><span class="p">,</span> <span class="na">selected_insensitive</span><span class="o">=</span><span class="s2">"paper_hover.png"</span><span class="p">,</span> <span class="na">clicked</span><span class="o">=</span><span class="n">ui</span><span class="o">.</span><span class="n">ChoiceReturn</span><span class="p">(</span><span class="s2">"paper"</span><span class="p">,</span> <span class="s2">"Paper"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
|
||
<span class="n">ui</span><span class="o">.</span><span class="k">imagebutton</span><span class="p">(</span><span class="s2">"scissors.png"</span><span class="p">,</span> <span class="s2">"scissors_hover.png"</span><span class="p">,</span> <span class="na">selected_insensitive</span><span class="o">=</span><span class="s2">"scissors_hover.png"</span><span class="p">,</span> <span class="na">clicked</span><span class="o">=</span><span class="n">ui</span><span class="o">.</span><span class="n">ChoiceReturn</span><span class="p">(</span><span class="s2">"scissors"</span><span class="p">,</span> <span class="s2">"Scissors"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
|
||
<span class="n">ui</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||
|
||
<span class="k">if</span> <span class="n">renpy</span><span class="o">.</span><span class="n">in_fixed_rollback</span><span class="p">():</span>
|
||
<span class="n">ui</span><span class="o">.</span><span class="n">saybehavior</span><span class="p">()</span>
|
||
|
||
<span class="k">choice</span> <span class="o">=</span> <span class="n">ui</span><span class="o">.</span><span class="n">interact</span><span class="p">(</span><span class="na">roll_forward</span><span class="o">=</span><span class="na">roll_forward</span><span class="p">)</span>
|
||
<span class="n">renpy</span><span class="o">.</span><span class="n">checkpoint</span><span class="p">(</span><span class="k">choice</span><span class="p">)</span>
|
||
|
||
<span class="k">$</span> <span class="n">renpy</span><span class="o">.</span><span class="n">fix_rollback</span><span class="p">()</span>
|
||
<span class="n">m</span> <span class="s2">"[choice]!"</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="rollback-blocking-and-fixing-functions">
|
||
<h2>Rollback-blocking and -fixing Functions<a class="headerlink" href="#rollback-blocking-and-fixing-functions" title="Permalink to this headline"> link</a></h2>
|
||
<dl class="function">
|
||
<dt id="renpy.block_rollback">
|
||
<code class="descclassname">renpy.</code><code class="descname">block_rollback</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#renpy.block_rollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Prevents the game from rolling back to before the current
|
||
statement.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.fix_rollback">
|
||
<code class="descclassname">renpy.</code><code class="descname">fix_rollback</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#renpy.fix_rollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Prevents the user from changing decisions made before the current
|
||
statement.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="renpy.in_fixed_rollback">
|
||
<code class="descclassname">renpy.</code><code class="descname">in_fixed_rollback</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#renpy.in_fixed_rollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Returns true if rollback is currently occurring and the current
|
||
context is before an executed renpy.fix_rollback() statement.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="ui.ChoiceJump">
|
||
<code class="descclassname">ui.</code><code class="descname">ChoiceJump</code><span class="sig-paren">(</span><em>label</em>, <em>value</em>, <em>location=None</em>, <em>block_all=None</em>, <em>sensitive=True</em>, <em>args=None</em>, <em>kwargs=None</em><span class="sig-paren">)</span><a class="headerlink" href="#ui.ChoiceJump" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>A menu choice action that returns <cite>value</cite>, while managing the button
|
||
state in a manner consistent with fixed rollback. (See block_all for
|
||
a description of the behavior.)</p>
|
||
<dl class="docutils">
|
||
<dt><cite>label</cite></dt>
|
||
<dd>The label text of the button. For imagebuttons and hotspots this
|
||
can be anything. This label is used as a unique identifier of
|
||
the options within the current screen. Together with <cite>location</cite>
|
||
it is used to store whether this option has been chosen.</dd>
|
||
<dt><cite>value</cite></dt>
|
||
<dd>The location to jump to.</dd>
|
||
<dt><cite>location</cite></dt>
|
||
<dd>A unique location identifier for the current choices screen.</dd>
|
||
<dt><cite>block_all</cite></dt>
|
||
<dd><p class="first">If false, the button is given the selected role if it was
|
||
the chosen choice, and insensitive if it was not selected.</p>
|
||
<p>If true, the button is always insensitive during fixed
|
||
rollback.</p>
|
||
<p>If None, the value is taken from the <a class="reference internal" href="config.html#var-config.fix_rollback_without_choice"><code class="xref std std-var docutils literal notranslate"><span class="pre">config.fix_rollback_without_choice</span></code></a>
|
||
variable.</p>
|
||
<p class="last">When true is given to all items in a screen, it will
|
||
become unclickable (rolling forward will still work). This can
|
||
be changed by calling <code class="xref py py-func docutils literal notranslate"><span class="pre">ui.saybehavior()</span></code> before the call
|
||
to <a class="reference internal" href="screen_python.html#ui.interact" title="ui.interact"><code class="xref py py-func docutils literal notranslate"><span class="pre">ui.interact()</span></code></a>.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="function">
|
||
<dt id="ui.ChoiceReturn">
|
||
<code class="descclassname">ui.</code><code class="descname">ChoiceReturn</code><span class="sig-paren">(</span><em>label</em>, <em>value</em>, <em>location=None</em>, <em>block_all=None</em>, <em>sensitive=True</em>, <em>args=None</em>, <em>kwargs=None</em><span class="sig-paren">)</span><a class="headerlink" href="#ui.ChoiceReturn" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>A menu choice action that returns <cite>value</cite>, while managing the button
|
||
state in a manner consistent with fixed rollback. (See block_all for
|
||
a description of the behavior.)</p>
|
||
<dl class="docutils">
|
||
<dt><cite>label</cite></dt>
|
||
<dd>The label text of the button. For imagebuttons and hotspots this
|
||
can be anything. This label is used as a unique identifier of
|
||
the options within the current screen. Together with <cite>location</cite>
|
||
it is used to store whether this option has been chosen.</dd>
|
||
<dt><cite>value</cite></dt>
|
||
<dd>The value this is returned when the choice is chosen.</dd>
|
||
<dt><cite>location</cite></dt>
|
||
<dd>A unique location identifier for the current choices screen.</dd>
|
||
<dt><cite>block_all</cite></dt>
|
||
<dd><p class="first">If false, the button is given the selected role if it was
|
||
the chosen choice, and insensitive if it was not selected.</p>
|
||
<p>If true, the button is always insensitive during fixed
|
||
rollback.</p>
|
||
<p>If None, the value is taken from the <a class="reference internal" href="config.html#var-config.fix_rollback_without_choice"><code class="xref std std-var docutils literal notranslate"><span class="pre">config.fix_rollback_without_choice</span></code></a>
|
||
variable.</p>
|
||
<p class="last">When true is given to all items in a screen, it will
|
||
become unclickable (rolling forward will still work). This can
|
||
be changed by calling <code class="xref py py-func docutils literal notranslate"><span class="pre">ui.saybehavior()</span></code> before the call
|
||
to <a class="reference internal" href="screen_python.html#ui.interact" title="ui.interact"><code class="xref py py-func docutils literal notranslate"><span class="pre">ui.interact()</span></code></a>.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
</div>
|
||
<div class="section" id="norollback">
|
||
<h2>NoRollback<a class="headerlink" href="#norollback" title="Permalink to this headline"> link</a></h2>
|
||
<dl class="class">
|
||
<dt id="NoRollback">
|
||
<em class="property">class </em><code class="descname">NoRollback</code><a class="headerlink" href="#NoRollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Instances of this class, and classes inheriting from this class,
|
||
do not participate in rollback. Objects reachable through an instance
|
||
of a NoRollback class only participate in rollback if they are
|
||
reachable through other paths.</p>
|
||
</dd></dl>
|
||
|
||
<dl class="class">
|
||
<dt id="SlottedNoRollback">
|
||
<em class="property">class </em><code class="descname">SlottedNoRollback</code><a class="headerlink" href="#SlottedNoRollback" title="Permalink to this definition"> link</a></dt>
|
||
<dd><p>Instances of classes inheriting from this class do not participate
|
||
in rollback. The difference between this and <a class="reference internal" href="#NoRollback" title="NoRollback"><code class="xref py py-class docutils literal notranslate"><span class="pre">NoRollback</span></code></a> is that
|
||
this class does not have an associated dictionary, hence can be used
|
||
with <code class="docutils literal notranslate"><span class="pre">__slots__</span></code> to reduce memory usage.</p>
|
||
<p>Objects reachable through an instance of a NoRollback class only participate
|
||
in rollback if they are reachable through other paths.</p>
|
||
</dd></dl>
|
||
|
||
<p>For example:</p>
|
||
<div class="highlight-renpy notranslate"><div class="highlight"><pre><span></span><span class="k">init</span> <span class="k">python</span><span class="p">:</span>
|
||
|
||
<span class="k">class</span> <span class="nc">MyClass</span><span class="p">(</span><span class="n">NoRollback</span><span class="p">):</span>
|
||
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="na">value</span> <span class="o">=</span> <span class="mi">0</span>
|
||
|
||
<span class="k">label</span> <span class="n">start</span><span class="p">:</span>
|
||
<span class="k">$</span> <span class="n">o</span> <span class="o">=</span> <span class="n">MyClass</span><span class="p">()</span>
|
||
|
||
<span class="s2">"Welcome!"</span>
|
||
|
||
<span class="k">$</span> <span class="n">o</span><span class="o">.</span><span class="na">value</span> <span class="o">+=</span> <span class="mi">1</span>
|
||
|
||
<span class="s2">"o.value is [o.value]. It will increase each time you rolllback and then click ahead."</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<footer class="footer">
|
||
<div class="container">
|
||
<p class="pull-right">
|
||
<a href="#">Back to top</a>
|
||
|
||
</p>
|
||
<p>
|
||
© Copyright 2012-2022, Tom Rothamel.<br/>
|
||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.6.<br/>
|
||
</p>
|
||
</div>
|
||
</footer>
|
||
</body>
|
||
</html> |