1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
|
<!DOCTYPE html>
<html>
<head>
<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/screen.css" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="_static/renpydoc.css" type="text/css" media="print" />
<!--[if lt IE 8]>
<link rel="stylesheet" href="_static/renpydoc.css" type="text/css" media="screen, projection"/>
<![endif]-->
<link rel="stylesheet" href="_static/renpydoc.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '6.18.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</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>
<link rel="top" title="Ren'Py Documentation" href="index.html" />
<link rel="next" title="Persistent Data" href="persistent.html" />
<link rel="prev" title="Statement Equivalents" href="statement_equivalents.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="persistent.html" title="Persistent Data"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="statement_equivalents.html" title="Statement Equivalents"
accesskey="P">previous</a> |</li>
<li> <img src="_static/logo.png" width=19 height=21 align=center>
<li> <a href="http://www.renpy.org/">Ren'Py Home</a> |
<li><a href="index.html">Ren'Py Documentation</a></li>
</ul>
</div>
<div class="container">
<div class="span4">
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<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="#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="#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>
<h4>Previous topic</h4>
<p class="topless"><a href="statement_equivalents.html"
title="previous chapter">Statement Equivalents</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="persistent.html"
title="next chapter">Persistent Data</a></p>
<h4>Search</h4>
<div id="cse-search-form" style="width: 100%;"></div>
<div class="copydata">
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
<br>
</div>
</div>
</div>
</div>
<div class="document span20 last">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<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">¶</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">¶</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>In this example:</p>
<div class="highlight-renpy"><div class="highlight"><pre><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">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> will be saved. A 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">¶</a></h2>
<p>Python variables that are not changed before the game begins will not be
saved. This can be a major problem if a variable that is saved and one that is
refer to the same object. (Alias the object.) In this example:</p>
<div class="highlight-renpy"><div class="highlight"><pre><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="s">"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, if
code (like variable assignments) is added to the game, it 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 init 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">¶</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 code like:</p>
<div class="highlight-renpy"><div class="highlight"><pre><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="s">"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
similar code in Ren'Py - rather than Python - avoids this problem.:</p>
<div class="highlight-renpy"><div class="highlight"><pre><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="s">"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">¶</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>
<p>There are certain types that cannot be pickled:</p>
<ul class="simple">
<li>Render objects.</li>
<li>Iterator objects.</li>
<li>File-like objects.</li>
<li>Inner functions and lambdas.</li>
</ul>
<p>By default, Ren'Py uses the cPickle module to save the game. Setting
<tt class="xref std std-var docutils literal"><span class="pre">config.use_cpickle</span></tt> will make Ren'Py use the pickle module instead. This
makes the game slower, but is better at reporting save errors.</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">¶</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">
<tt class="descname">save_name</tt> = ...<a class="headerlink" href="#var-save_name" title="Permalink to this definition">¶</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>
</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#screen-actions"><em>screen actions</em></a>. In addition, there are the following
low-level save and load actions.</p>
<dl class="function">
<dt id="renpy.can_load">
<tt class="descclassname">renpy.</tt><tt class="descname">can_load</tt><big>(</big><em>filename</em>, <em>test=False</em><big>)</big><a class="headerlink" href="#renpy.can_load" title="Permalink to this definition">¶</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.list_saved_games">
<tt class="descclassname">renpy.</tt><tt class="descname">list_saved_games</tt><big>(</big><em>regexp='.'</em>, <em>fast=False</em><big>)</big><a class="headerlink" href="#renpy.list_saved_games" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">list_slots</tt><big>(</big><em>regexp=None</em><big>)</big><a class="headerlink" href="#renpy.list_slots" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">load</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#renpy.load" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">newest_slot</tt><big>(</big><em>regexp=None</em><big>)</big><a class="headerlink" href="#renpy.newest_slot" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">rename_save</tt><big>(</big><em>old</em>, <em>new</em><big>)</big><a class="headerlink" href="#renpy.rename_save" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">save</tt><big>(</big><em>filename</em>, <em>extra_info=''</em><big>)</big><a class="headerlink" href="#renpy.save" title="Permalink to this definition">¶</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"><tt class="xref std std-var docutils literal"><span class="pre">save_name</span></tt></a>.</dd>
</dl>
<p><a class="reference internal" href="#renpy.take_screenshot" title="renpy.take_screenshot"><tt class="xref py py-func docutils literal"><span class="pre">renpy.take_screenshot()</span></tt></a> should be called before this function.</p>
</dd></dl>
<dl class="function">
<dt id="renpy.slot_json">
<tt class="descclassname">renpy.</tt><tt class="descname">slot_json</tt><big>(</big><em>slotname</em><big>)</big><a class="headerlink" href="#renpy.slot_json" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the json information for <cite>slotname</cite>, or None if the slot is
empty.</p>
</dd></dl>
<dl class="function">
<dt id="renpy.slot_mtime">
<tt class="descclassname">renpy.</tt><tt class="descname">slot_mtime</tt><big>(</big><em>slotname</em><big>)</big><a class="headerlink" href="#renpy.slot_mtime" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">slot_screenshot</tt><big>(</big><em>slotname</em><big>)</big><a class="headerlink" href="#renpy.slot_screenshot" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">take_screenshot</tt><big>(</big><em>scale=None</em>, <em>background=False</em><big>)</big><a class="headerlink" href="#renpy.take_screenshot" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">unlink_save</tt><big>(</big><em>filename</em><big>)</big><a class="headerlink" href="#renpy.unlink_save" title="Permalink to this definition">¶</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">¶</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"><div class="highlight"><pre><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="s">"[value]"</span>
<span class="k">textbutton</span> <span class="s">"+"</span> <span class="na">action</span> <span class="n">SetVariable</span><span class="p">(</span><span class="s">"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="s">"-"</span> <span class="na">action</span> <span class="n">SetVariable</span><span class="p">(</span><span class="s">"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="s">"+"</span> <span class="na">action</span> <span class="n">Return</span><span class="p">(</span><span class="bp">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">
<tt class="descclassname">renpy.</tt><tt class="descname">retain_after_load</tt><big>(</big><big>)</big><a class="headerlink" href="#renpy.retain_after_load" title="Permalink to this definition">¶</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">¶</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="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">¶</a></h2>
<p>Most Ren'Py statements automatically support rollback and roll forward. If
you call <tt class="xref py py-func docutils literal"><span class="pre">ui.interact()</span></tt> 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"><div class="highlight"><pre><span class="c"># This is None if we're not rolling back, or else the value that was</span>
<span class="c"># passed to checkpoint last time if we're rolling forward.</span>
<span class="n">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="c"># Set up the screen here...</span>
<span class="c"># 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="n">roll_forward</span><span class="o">=</span><span class="n">roll_forward</span><span class="p">)</span>
<span class="c"># 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">
<tt class="descclassname">renpy.</tt><tt class="descname">can_rollback</tt><big>(</big><big>)</big><a class="headerlink" href="#renpy.can_rollback" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns true if we can rollback.</p>
</dd></dl>
<dl class="function">
<dt id="renpy.checkpoint">
<tt class="descclassname">renpy.</tt><tt class="descname">checkpoint</tt><big>(</big><em>data=None</em><big>)</big><a class="headerlink" href="#renpy.checkpoint" title="Permalink to this definition">¶</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>
<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"><tt class="xref py py-func docutils literal"><span class="pre">renpy.roll_forward_info()</span></tt></a> when the
game is being rolled back.</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="renpy.in_rollback">
<tt class="descclassname">renpy.</tt><tt class="descname">in_rollback</tt><big>(</big><big>)</big><a class="headerlink" href="#renpy.in_rollback" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">roll_forward_info</tt><big>(</big><big>)</big><a class="headerlink" href="#renpy.roll_forward_info" title="Permalink to this definition">¶</a></dt>
<dd><p>When in rollback, returns the data that was supplied to <a class="reference internal" href="#renpy.checkpoint" title="renpy.checkpoint"><tt class="xref py py-func docutils literal"><span class="pre">renpy.checkpoint()</span></tt></a>
the last time this statement executed. Outside of rollback, returns None.</p>
</dd></dl>
<dl class="function">
<dt id="renpy.rollback">
<tt class="descclassname">renpy.</tt><tt class="descname">rollback</tt><big>(</big><em>force=False</em>, <em>checkpoints=1</em>, <em>defer=False</em>, <em>greedy=True</em>, <em>label=None</em><big>)</big><a class="headerlink" href="#renpy.rollback" title="Permalink to this definition">¶</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 code from the main context is
executed.</dd>
<dt><cite>greedy</cite></dt>
<dd>If true, rollback will occur just before the previous checkpoint.
If false, rollback occurs to just before the current checkpoint.</dd>
<dt><cite>label</cite></dt>
<dd>If not None, a label that is called when rollback completes.</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">¶</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"><tt class="xref std std-var docutils literal"><span class="pre">config.rollback_enabled</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">renpy.block_rollback()</span></tt></a> function. When called, it will instruct
Ren'Py not to roll back before that point. For example:</p>
<div class="highlight-renpy"><div class="highlight"><pre><span class="k">label</span> <span class="n">final_answer</span><span class="p">:</span>
<span class="s">"Is that your final answer?"</span>
<span class="k">menu</span><span class="p">:</span>
<span class="s">"Yes"</span><span class="p">:</span>
<span class="k">jump</span> <span class="n">no_return</span>
<span class="s">"No"</span><span class="p">:</span>
<span class="s">"We have ways of making you talk."</span>
<span class="s">"You should contemplate them."</span>
<span class="s">"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="s">"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">¶</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"><tt class="xref py py-func docutils literal"><span class="pre">renpy.fix_rollback()</span></tt></a>
function, as shown in the following example:</p>
<div class="highlight-renpy"><div class="highlight"><pre><span class="k">label</span> <span class="n">final_answer</span><span class="p">:</span>
<span class="s">"Is that your final answer?"</span>
<span class="k">menu</span><span class="p">:</span>
<span class="s">"Yes"</span><span class="p">:</span>
<span class="k">jump</span> <span class="n">no_return</span>
<span class="s">"No"</span><span class="p">:</span>
<span class="s">"We have ways of making you talk."</span>
<span class="s">"You should contemplate them."</span>
<span class="s">"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="s">"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 <tt class="xref py py-func docutils literal"><span class="pre">checkpoint()</span></tt>. However, due to the generic nature
of Ren'Py, it is possible to write Python code that bypasses this and
changes things in ways that may have unpredictable results. It is up
to the game designer to block rollback at problematic locations or
write additional code to deal with it.</p>
<p>The internal user interaction options for menus, <a class="reference internal" href="input.html#renpy.input" title="renpy.input"><tt class="xref py py-func docutils literal"><span class="pre">renpy.input()</span></tt></a>
and <tt class="xref py py-func docutils literal"><span class="pre">renpy.imagemap()</span></tt> 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">¶</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"><tt class="xref std std-var docutils literal"><span class="pre">config.fix_rollback_without_choice</span></tt></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"><tt class="xref std std-var docutils literal"><span class="pre">config.fix_rollback_without_choice</span></tt></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">¶</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"><tt class="xref py py-func docutils literal"><span class="pre">renpy.in_fixed_rollback()</span></tt></a> function can be used to determine whether
the game is currently in fixed rollback state. Second, when in
fixed rollback state, <tt class="xref py py-func docutils literal"><span class="pre">ui.interact()</span></tt> will always return the
supplied roll_forward data regardless of what action was performed. This
effectively means that when the <tt class="xref py py-func docutils literal"><span class="pre">ui.interact()</span></tt>/<a class="reference internal" href="#renpy.checkpoint" title="renpy.checkpoint"><tt class="xref py py-func docutils literal"><span class="pre">renpy.checkpoint()</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">ui.ChoiceReturn()</span></tt></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"><tt class="xref py py-func docutils literal"><span class="pre">ui.ChoiceJump()</span></tt></a> action can be used to jump to a script label. However, this
action only works properly when the screen is called trough a
<tt class="docutils literal"><span class="pre">call</span> <span class="pre">screen</span></tt> statement.</p>
<p>Example:</p>
<div class="highlight-renpy"><div class="highlight"><pre><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="s">"imagemap_ground.jpg"</span>
<span class="na">hover</span> <span class="s">"imagemap_hover.jpg"</span>
<span class="na">selected_idle</span> <span class="s">"imagemap_selected_idle.jpg"</span>
<span class="na">selected_hover</span> <span class="s">"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="s">"swimming"</span><span class="p">,</span> <span class="s">"go_swimming"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="bp">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="s">"science"</span><span class="p">,</span> <span class="s">"go_science_club"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="bp">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="s">"art"</span><span class="p">,</span> <span class="s">"go_art_lessons"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="bp">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">uiChoiceJump</span><span class="p">(</span><span class="s">"home"</span><span class="p">,</span> <span class="s">"go_home"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-renpy"><div class="highlight"><pre><span class="k">python</span><span class="p">:</span>
<span class="n">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="n">roll_forward</span> <span class="k">not</span> <span class="k">in</span> <span class="p">(</span><span class="s">"Rock"</span><span class="p">,</span> <span class="s">"Paper"</span><span class="p">,</span> <span class="s">"Scissors"</span><span class="p">):</span>
<span class="n">roll_forward</span> <span class="o">=</span> <span class="bp">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="s">"rock.png"</span><span class="p">,</span> <span class="s">"rock_hover.png"</span><span class="p">,</span> <span class="na">selected_insensitive</span><span class="o">=</span><span class="s">"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="s">"rock"</span><span class="p">,</span> <span class="s">"Rock"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="bp">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="s">"paper.png"</span><span class="p">,</span> <span class="s">"paper_hover.png"</span><span class="p">,</span> <span class="na">selected_insensitive</span><span class="o">=</span><span class="s">"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="s">"paper"</span><span class="p">,</span> <span class="s">"Paper"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="bp">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="s">"scissors.png"</span><span class="p">,</span> <span class="s">"scissors_hover.png"</span><span class="p">,</span> <span class="na">selected_insensitive</span><span class="o">=</span><span class="s">"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="s">"scissors"</span><span class="p">,</span> <span class="s">"Scissors"</span><span class="p">,</span> <span class="n">block_all</span><span class="o">=</span><span class="bp">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="n">roll_forward</span><span class="o">=</span><span class="n">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="s">"[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">¶</a></h2>
<dl class="function">
<dt id="renpy.block_rollback">
<tt class="descclassname">renpy.</tt><tt class="descname">block_rollback</tt><big>(</big><big>)</big><a class="headerlink" href="#renpy.block_rollback" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">fix_rollback</tt><big>(</big><big>)</big><a class="headerlink" href="#renpy.fix_rollback" title="Permalink to this definition">¶</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">
<tt class="descclassname">renpy.</tt><tt class="descname">in_fixed_rollback</tt><big>(</big><big>)</big><a class="headerlink" href="#renpy.in_fixed_rollback" title="Permalink to this definition">¶</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">
<tt class="descclassname">ui.</tt><tt class="descname">ChoiceJump</tt><big>(</big><em>label</em>, <em>value</em>, <em>location=None</em>, <em>block_all=None</em><big>)</big><a class="headerlink" href="#ui.ChoiceJump" title="Permalink to this definition">¶</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"><tt class="xref std std-var docutils literal"><span class="pre">config.fix_rollback_without_choice</span></tt></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 <tt class="xref py py-func docutils literal"><span class="pre">ui.saybehavior()</span></tt> before the call
to <tt class="xref py py-func docutils literal"><span class="pre">ui.interact()</span></tt>.</p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="ui.ChoiceReturn">
<tt class="descclassname">ui.</tt><tt class="descname">ChoiceReturn</tt><big>(</big><em>label</em>, <em>value</em>, <em>location=None</em>, <em>block_all=None</em><big>)</big><a class="headerlink" href="#ui.ChoiceReturn" title="Permalink to this definition">¶</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"><tt class="xref std std-var docutils literal"><span class="pre">config.fix_rollback_without_choice</span></tt></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 <tt class="xref py py-func docutils literal"><span class="pre">ui.saybehavior()</span></tt> before the call
to <tt class="xref py py-func docutils literal"><span class="pre">ui.interact()</span></tt>.</p>
</dd>
</dl>
</dd></dl>
</div>
<div class="section" id="norollback">
<h2>NoRollback<a class="headerlink" href="#norollback" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="NoRollback">
<em class="property">class </em><tt class="descname">NoRollback</tt><a class="headerlink" href="#NoRollback" title="Permalink to this definition">¶</a></dt>
<dd><p>Instances of 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>
<p>For example:</p>
<div class="highlight-renpy"><div class="highlight"><pre><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="nf">__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="s">"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="s">"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>
</div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="persistent.html" title="Persistent Data"
>next</a> |</li>
<li class="right" >
<a href="statement_equivalents.html" title="Statement Equivalents"
>previous</a> |</li>
<li> <img src="_static/logo.png" width=19 height=21 align=center>
<li> <a href="http://www.renpy.org/">Ren'Py Home</a> |
<li><a href="index.html">Ren'Py Documentation</a></li>
</ul>
</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en' });
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('012476843541036121001:gx3sqkoaxkm');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.enableSearchboxOnly("http://www.google.com/cse?cx=012476843541036121001:gx3sqkoaxkm");
customSearchControl.draw('cse-search-form', options);
}, true);
</script>
</body>
</html>
|