/usr/share/doc/renpy/html/python.html is in renpy-doc 6.15.7-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Python Statements — 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.15.6',
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" />
</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> <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="#">Python Statements</a><ul>
<li><a class="reference internal" href="#python">Python</a></li>
<li><a class="reference internal" href="#one-line-python-statement">One-line Python Statement</a></li>
<li><a class="reference internal" href="#named-stores">Named Stores</a></li>
</ul>
</li>
</ul>
<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="python-statements">
<h1>Python Statements<a class="headerlink" href="#python-statements" title="Permalink to this headline">¶</a></h1>
<p>Ren'Py is written in the Python programmming language, and includes
support for including python code inside Ren'Py scripts. Python
support can be used for many things, from setting a flag to creating
new displayables. This chapter covers ways in which Ren'Py scripts can
directly invoke Ren'Py code, through the various python statements.</p>
<div class="section" id="python">
<span id="python-statement"></span><h2>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h2>
<p>The python statement takes a block of python code, and runs that code
when control reaches the statement. A basic python statement can be
very simple:</p>
<div class="highlight-renpy"><div class="highlight"><pre><span class="k">python</span><span class="p">:</span>
<span class="n">flag</span> <span class="o">=</span> <span class="bp">True</span>
</pre></div>
</div>
<p>Python statements can get more complex, when necessary:</p>
<div class="highlight-renpy"><div class="highlight"><pre><span class="k">python</span><span class="p">:</span>
<span class="n">player_health</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">player_health</span> <span class="o">-</span> <span class="n">damage</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">enemy_vampire</span><span class="p">:</span>
<span class="n">enemy_health</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">enemy_health</span> <span class="o">+</span> <span class="n">damage</span><span class="p">,</span> <span class="n">enemy_max_health</span><span class="p">)</span>
</pre></div>
</div>
<p>There are two modifiers to the python statement that change its
behavior:</p>
<p><tt class="docutils literal"><span class="pre">hide</span></tt></p>
<blockquote>
<div><p>If given the hide modifier, the python statement will run the
code in an anonymous scope. The scope will be lost when the python
block terminates.</p>
<p>This allows python code to use temporary variables that can't be
saved - but it means that the store needs to be accessed as fields
on the store object, rather than directly.</p>
</div></blockquote>
<p><tt class="docutils literal"><span class="pre">in</span></tt></p>
<blockquote>
<div>The <tt class="docutils literal"><span class="pre">in</span></tt> modifier takes a name. Instead of executing in the
default store, the python code will execute in the store that
name.</div></blockquote>
</div>
<div class="section" id="one-line-python-statement">
<h2>One-line Python Statement<a class="headerlink" href="#one-line-python-statement" title="Permalink to this headline">¶</a></h2>
<p>A common case is to have a single line of python that runs in the
default store. For example, a python one-liner can be used to
initialize or update a flag. To make writing python one-liners
more convenient, there is the one-line python statement.</p>
<p>The one-line python statement begins with the dollar-sign ($)
character, and contains all of the code on that line. Here
are some example of python one-liners:</p>
<div class="highlight-renpy"><div class="highlight"><pre><span class="c"># Set a flag.</span>
<span class="k">$</span> <span class="n">flag</span> <span class="o">=</span> <span class="bp">True</span>
<span class="c"># Increment a variable.</span>
<span class="k">$</span> <span class="n">rabu_rabu_points</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="c"># Call a function that exposes Ren'Py functionality.</span>
<span class="k">$</span> <span class="n">renpy</span><span class="o">.</span><span class="n">movie_cutscene</span><span class="p">(</span><span class="s">"opening.ogv"</span><span class="p">)</span>
</pre></div>
</div>
<p>Python one-liners always run in the default store.</p>
</div>
<div class="section" id="named-stores">
<h2>Named Stores<a class="headerlink" href="#named-stores" title="Permalink to this headline">¶</a></h2>
<p>Named stores provide a way of organizing python code into modules. By
placing code in modules, you can minimize the chance of name
conflicts.</p>
<p>Named stores can be accessed by supplying the <tt class="docutils literal"><span class="pre">in</span></tt> clause to
<tt class="docutils literal"><span class="pre">python</span></tt> or <tt class="docutils literal"><span class="pre">init</span> <span class="pre">python</span></tt>, code can run accessed in a named
store. Each store corresponds to a python module. The default store is
<tt class="docutils literal"><span class="pre">store</span></tt>, while a named store is accessed a <tt class="docutils literal"><span class="pre">store</span></tt>.`name`. These
python modules can be imported using the python import statement,
while names in the modules can be imported using the python from
statement.</p>
<p>Named stores participate in save, load, and rollback in the same way
that the default store does.</p>
<p>TODO:</p>
<ul class="simple">
<li>Note that names beginning with a single _ are reserved for Ren'Py's
use.</li>
</ul>
</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> <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>
|