File: The_Ren%27Py_Language.html

package info (click to toggle)
renpy 6.6.2.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 8,740 kB
  • ctags: 3,407
  • sloc: python: 22,153; ansic: 3,724; makefile: 138; lisp: 128; sh: 14
file content (563 lines) | stat: -rw-r--r-- 44,832 bytes parent folder | download
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
<html><head><title>renpy/doc/reference/The Ren'Py Language - Ren'Py</title><link href="../shared.css" rel="stylesheet"><link href="../monobook.css" rel="stylesheet"><link href="../common.css" rel="stylesheet"><link href="../monobook2.css" rel="stylesheet"><link href="../docs.css" rel="stylesheet" /></link></link></link></link></head><body><div id="bodyContent">
			<p class="docnav"><a href="../index.html">documentation index</a> &#9702; <a href="Reference_Manual.html">reference manual</a> &#9702; <a href="Function_Index.html">function index</a></p><p><a id="The_Ren.27Py_Language" name="The_Ren.27Py_Language"></a></p>
<h1><span class="mw-headline">The Ren'Py Language</span></h1>
<p>This section describes the Ren'Py language, and the functions found in that language.</p>
<table class="toc" id="toc" summary="Contents">
<tr>
<td>
<div id="toctitle">
<h2>Contents</h2>
</div>
<ul>
<li class="toclevel-1"><a href="#The_Ren.27Py_Language"><span class="tocnumber">1</span> <span class="toctext">The Ren'Py Language</span></a>
<ul>
<li class="toclevel-2"><a href="#Script.2C_Line.2C_and_Block_Structure"><span class="tocnumber">1.1</span> <span class="toctext">Script, Line, and Block Structure</span></a></li>
<li class="toclevel-2"><a href="#Syntax_Constructs"><span class="tocnumber">1.2</span> <span class="toctext">Syntax Constructs</span></a>
<ul>
<li class="toclevel-3"><a href="#Name_Munging"><span class="tocnumber">1.2.1</span> <span class="toctext">Name Munging</span></a></li>
<li class="toclevel-3"><a href="#Grammar_Rules"><span class="tocnumber">1.2.2</span> <span class="toctext">Grammar Rules</span></a></li>
</ul>
</li>
<li class="toclevel-2"><a href="#Statements"><span class="tocnumber">1.3</span> <span class="toctext">Statements</span></a>
<ul>
<li class="toclevel-3"><a href="#Call_Statement"><span class="tocnumber">1.3.1</span> <span class="toctext">Call Statement</span></a></li>
<li class="toclevel-3"><a href="#Hide_Statement"><span class="tocnumber">1.3.2</span> <span class="toctext">Hide Statement</span></a></li>
<li class="toclevel-3"><a href="#If_Statement"><span class="tocnumber">1.3.3</span> <span class="toctext">If Statement</span></a></li>
<li class="toclevel-3"><a href="#Image_Statement"><span class="tocnumber">1.3.4</span> <span class="toctext">Image Statement</span></a></li>
<li class="toclevel-3"><a href="#Init_Statement"><span class="tocnumber">1.3.5</span> <span class="toctext">Init Statement</span></a></li>
<li class="toclevel-3"><a href="#Jump_Statement"><span class="tocnumber">1.3.6</span> <span class="toctext">Jump Statement</span></a></li>
<li class="toclevel-3"><a href="#Label_Statement"><span class="tocnumber">1.3.7</span> <span class="toctext">Label Statement</span></a></li>
<li class="toclevel-3"><a href="#Menu_Statement"><span class="tocnumber">1.3.8</span> <span class="toctext">Menu Statement</span></a>
<ul>
<li class="toclevel-4"><a href="#Details"><span class="tocnumber">1.3.8.1</span> <span class="toctext">Details</span></a></li>
</ul>
</li>
<li class="toclevel-3"><a href="#Play_Statement"><span class="tocnumber">1.3.9</span> <span class="toctext">Play Statement</span></a></li>
<li class="toclevel-3"><a href="#Pass_Statement"><span class="tocnumber">1.3.10</span> <span class="toctext">Pass Statement</span></a></li>
<li class="toclevel-3"><a href="#Python_Statement"><span class="tocnumber">1.3.11</span> <span class="toctext">Python Statement</span></a></li>
<li class="toclevel-3"><a href="#Queue_Statement"><span class="tocnumber">1.3.12</span> <span class="toctext">Queue Statement</span></a></li>
<li class="toclevel-3"><a href="#Return_Statement"><span class="tocnumber">1.3.13</span> <span class="toctext">Return Statement</span></a></li>
<li class="toclevel-3"><a href="#Say_Statement"><span class="tocnumber">1.3.14</span> <span class="toctext">Say Statement</span></a>
<ul>
<li class="toclevel-4"><a href="#Details_2"><span class="tocnumber">1.3.14.1</span> <span class="toctext">Details</span></a></li>
</ul>
</li>
<li class="toclevel-3"><a href="#Scene_Statement"><span class="tocnumber">1.3.15</span> <span class="toctext">Scene Statement</span></a></li>
<li class="toclevel-3"><a href="#Show_Statement"><span class="tocnumber">1.3.16</span> <span class="toctext">Show Statement</span></a></li>
<li class="toclevel-3"><a href="#Stop_Statement"><span class="tocnumber">1.3.17</span> <span class="toctext">Stop Statement</span></a></li>
<li class="toclevel-3"><a href="#With_Statement_and_Clauses"><span class="tocnumber">1.3.18</span> <span class="toctext">With Statement and Clauses</span></a></li>
<li class="toclevel-3"><a href="#While_Statement"><span class="tocnumber">1.3.19</span> <span class="toctext">While Statement</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</td>
</tr>
</table>
<script type="text/javascript">
//
 if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } 
//
</script>
<p><br /></p>
<div id="Script_Line_and_Block_Structure" />
<p><a id="Script.2C_Line.2C_and_Block_Structure" name="Script.2C_Line.2C_and_Block_Structure"></a></p>
<h2><span class="mw-headline">Script, Line, and Block Structure</span></h2>
<p>Ren'Py scripts consist of one or more .rpy files. These script files may be read in any order, and all of them together make up a Ren'Py script. Please see <a class="new" href="http://www.renpy.org/w/index.php?title=renpy/doc/reference/The_Ren%27Py_Runtime_Environment&amp;action=edit" title="renpy/doc/reference/The Ren&apos;Py Runtime Environment">The Ren'Py Runtime Environment</a> for information about where Ren'Py searches for .rpy files.</p>
<p>Each of these files is divided into a series of <b>logical lines</b>. The first logical line of a file begins at the start of a file, and another logical line begins after each logical line ends, until the end of the file is reached. By default, a logical line is terminated by the first newline encountered. However, a line will not terminate if any of the following are true:</p>
<ul>
<li>The newline is immediately preceded by a backslash. In this case, the backslash is removed, and the newline is ignored.</li>
<li>An opening parenthesis, bracket, or brace has been encountered without encountering the corresponding closing character.</li>
<li>The newline occurs within a string.</li>
</ul>
<p>Ren'Py script files also can include <b>comments</b>. A comment begins with a hash mark that is not contained within a string, and continues to, but does not include, the next newline character. Some examples are:</p>
<pre>
<span class="slc"># This line contains only a comment.</span>
<span class="kwa">scene</span> bg whitehouse  <span class="slc"># This line contains a statement as well.</span>
</pre>
<p>If, after eliminating comments, a logical line is empty, that logical line is ignored.</p>
<p>Logical lines are then combined into <b>blocks</b>. Two logical lines are in the same block if the lines have the same indentation preceding them, and no logical line with a lesser amount of indentation occurs between the two lines. Indentation may only consist of spaces, not tabs. In the following example:</p>
<pre>
line 1
    line a
    line b
line 2
    line c
    line d
</pre>
<p>In this example, here are three blocks. One block contains lines 1 and 2, another lines a and b, and the third contains lines c and d. This example can also serve to illustrate the concept of a <i>block associated with a line</i>. A block is associated with a line if the block starts on the next logical line following the line. For example, the block containing lines a and b is associated with line #</p>
<p>There are three kinds of blocks in an Ren'Py program. The most common is a block containing Ren'Py statements. Blocks may also contain menuitems or python code. The top-level block (the one that contains the first line of a file) is always a block of Ren'Py statements.</p>
<div id="Syntax_Constructs" />
<p><a id="Syntax_Constructs" name="Syntax_Constructs"></a></p>
<h2><span class="mw-headline">Syntax Constructs</span></h2>
<p>Before we can describe Ren'Py statements, we must first describe a number of syntactic constructs those statements are built out of. In this subsection, we describe such constructs.</p>
<p><b>Keywords</b> are words that must literally appear in the source code. They're used ito introduce statements, or to delimit parts of statements. You'll see keywords throughout the descriptions of statements. In grammar rules, keywords are in quotes. The keywords used by Ren'Py are:</p>
<pre>
at
behind
call
elif
else
expression
hide
if
image
init
jump
label
menu
onlayer
pass
python
return
scene
set
show
while
with
zorder
</pre>
<div id="name" />
<p>A <b>name</b> consists of a letter or underscore (_) followed by zero or more letters, numbers, or underscores. For this purpose, unicode characters between U+00a0 and U+fffd are considered to be letters. A name may not be a keyword.</p>
<div id="simple_expression" />
<p>A <b>simple_expression</b> is a Python expression that starts with a name, a string, or any Python expression in parenthesis. This may be followed by any number of the following:</p>
<ul>
<li>A dot followed by a name.</li>
<li>A parenthesized python expression.</li>
</ul>
<div id="python_expression" />
<p>A <b>python_expression</b> is an arbitrary python expression that may not include a colon. These expressions are generally used to express the conditions in the if and while statements.</p>
<div id="image_name" />
<p>An <b>image_name</b> consists of one or more names, separated by spaces. The first name in an image_name is known as the <b>image_tag</b>.</p>
<pre>
image_spec -&gt; image_name ("as" name)? ( "onlayer" name)? ( "at" transform_list )? ( "with" simple_expression )? ("behind" name_list)?
</pre>
<p>An <b>image_spec</b> consists of an image name, followed by zer or more of the following clauses (in any order, provided each clause is only given once).</p>
<ul>
<li>an `as` clause giving an alternative tag for the image.</li>
<li>an `onlayer` clause, followed by a name giving the layer this image is on.</li>
<li>an `at` clause with a comma-separated list of simple_expressions that evaluate to functions that transform displayables to displayables,</li>
<li>a `with` clause. (see the <a href="../reference/The_Ren%27Py_Language#with" title="renpy/doc/reference/The Ren&apos;Py Language">with statement</a> for details.)</li>
<li>a `behind` clause, with a comma-separated list of names, which are interpreted as image tags the image will be displayed behind.</li>
</ul>
<pre>
image_spec -&gt; ("image | "expression") simple_expression ("as" name)? ( "onlayer" name)? ( "at" transform_list )? ( "with" simple_expression )? ("behind" name_list)? 
</pre>
<p>Alternatively, an image may be specified as the keyword "image" followed by a simple expression that is interpreted as a displayable. This allows images to be defined inline. Note that an "as" clause is recommended if it is desired to hide the image. All clauses are interpreted in the same way. "expression" may be used as a synonym for "image" here.</p>
<p><br /></p>
<p><a id="Name_Munging" name="Name_Munging"></a></p>
<h4><span class="mw-headline">Name Munging</span></h4>
<p>Before parsing a file, Ren'Py looks for names of the form _'<i><b>_'</b></i>_word, where word does not contain an _'<i><b>_. It munges these names in a filename-specific manner, generally ensuring that they will not conflict with the same name in other files. For example, in the file script.rpy, _'</b></i>_v is munged into _'<i><b>_'</b></i>_script_'<b><i>_v.</i></b></p>
<p>Names beginning with an odd number of underscores are reserved for Ren'Py, while those beginning with an even number of underscores can safely be used in scripts.</p>
<p><a id="Grammar_Rules" name="Grammar_Rules"></a></p>
<h4><span class="mw-headline">Grammar Rules</span></h4>
<p>We will be giving grammar rules for some of the statements. In these rules, a word in quotes means that that word is literally expected in the script. Parenthesis are used to group things together, but they don't correspond to anything in the script. Star, question mark, and plus are used to indicate that the token or group they are to the right of can occur zero or more, zero or one, or one or more times, respectively.</p>
<p>If we give a name for the rule, it will be separated from the body of the rule with a crude ascii-art arrow (-&gt;).</p>
<p><a id="Statements" name="Statements"></a></p>
<h2><span class="mw-headline">Statements</span></h2>
<div id="Call_Statement" />
<div id="call" />
<p><a id="Call_Statement" name="Call_Statement"></a></p>
<h3><span class="mw-headline">Call Statement</span></h3>
<p>The `call` statement is used to transfer control to the statement with the given name. It also pushes the name of the statement following this one onto the call stack, allowing the return statement to return control to the statement following this one.</p>
<pre>
call_statement -&gt; "call" name ( "from" name )?
call_statement -&gt; "call" "expression" simple_expression ( "from" name )?

call_statement -&gt; "call" name "(" arguments ")" ( "from" name )?
call_statement -&gt; "call" "expression" simple_expression "(" arguments ")" ( "from" name )?
</pre>
<p>If the `expression` keyword is present, the expression is evaluated, and the string so computed is used as the name of the statement to call. If the `expression` keyword is not present, the name of the statement to call must be explicitly given.</p>
<p>If the optional `from` clause is present, it has the effect of including a label statement with the given name as the statement immediately following the call statement. An explicit label is required here to ensure that saved games with return stacks can return to the proper place when loaded on a changed script. From clauses should be included for all calls in released games.</p>
<p>As from clauses may be distracting when a game is still under development, we provide with Ren'Py a program, called `add_from`, that adds from clauses to all bare calls in any game directory. It can be found in `tools/add_from`, although it needs to be run from the base directory. The easiest way to do this on windows is by running `tools/game_add_from.bat`. It should be run before a final release of your game is made. Be sure to make a backup of your game directories before running add_from. Also note that `add_from` produces .bak files for all files it can change, so delete them when you're satisfied that everything worked.</p>
<pre>
e <span class="str">"First, we will call a subroutine."</span>

<span class="kwa">call</span> subroutine <span class="kwa">from</span> _call_site_1

<span class="slc"># ...</span>

<span class="kwa">label</span> subroutine<span class="sym">:</span>

    e <span class="str">"Next, we will return from the subroutine."</span>

    <span class="kwa">return</span>
</pre>
<p>The call statement may take arguments, which are processed as described in PEP 3012. If the return statement returns a value, that value is stored in the _return variable, which is dynamically scoped to each context.</p>
<div id="Hide_Statement" />
<div id="hide" />
<p><a id="Hide_Statement" name="Hide_Statement"></a></p>
<h3><span class="mw-headline">Hide Statement</span></h3>
<p>The `hide` statement is used to hide an image from the screen, based on a supplied <i>image_spec</i>.</p>
<pre>
hide_statement -&gt; "hide" image_spec
</pre>
<p>A `hide` statement operates on the layer supplied in the `onlayer` clause of the <i>image_spec</i>, defaulting to "master" if no such clause has been supplied. It finds an image beginning with the image tag of the image name in the <i>image_spec</i>, and removes it from that layer.</p>
<p>Please note that the `hide` statement is rarely used in practice. Show can be used by itself when a character is changing emotion, while `scene` is used to remove all images at the end of a scene. Hide is only necessary when a character leaves before the end of a scene.</p>
<div id="If_Statement" />
<div id="if" />
<p><a id="If_Statement" name="If_Statement"></a></p>
<h3><span class="mw-headline">If Statement</span></h3>
<p>The `if` statement is used to conditionally execute a block of statements.</p>
<pre>
if_statement -&gt; "if" python_expression ":"
elif_clause -&gt; "elif" python_expression ":"
else_clause -&gt; "else" ":"
</pre>
<p>The `if` statement is the only statement which consists of more than one logical line in the same block. The initial `if` statement may be followed by zero or more `elif` clauses, concluded with an optional `else` clause. The expression is evaluated for each clause in turn, and if it evaluates to a true value, then the block associated with that clause is executed. If no expression evaluates to true, then the block associated with the `else` clause is executed. (If an `else` clause exists, execution immediately continues with the next statement.) In any case, at the end of the block, control is transferred to the statement following the if statement.</p>
<pre>
<span class="kwa">if</span> points <span class="sym">&gt;=</span> <span class="num">10</span><span class="sym">:</span>

   e <span class="str">"Congratulations! You're getting the best ending!"</span>

<span class="kwa">elif</span> points <span class="sym">&gt;=</span> <span class="num">5</span><span class="sym">:</span>

   e <span class="str">"It's the good ending for you."</span>

<span class="kwa">else</span><span class="sym">:</span>

   e <span class="str">"Sorry, you're about to get the bad ending."</span>
</pre>
<div id="Image_Statement" />
<div id="image" />
<p><a id="Image_Statement" name="Image_Statement"></a></p>
<h3><span class="mw-headline">Image Statement</span></h3>
<p>The `image` statement is used to declare images to Ren'Py. Image statements can only appear in init blocks.</p>
<pre>
image_statement -&gt; "image" image_name "=" python_expression
</pre>
<p>An `image` statement binds an <a href="../reference/The_Ren%27Py_Language#image_name" title="renpy/doc/reference/The Ren&apos;Py Language">image name</a> to a displayable. The displayable is computed by the supplied python expression, with the result of the expression being passed to the <a href="../reference/functions/im.Image.html" title="renpy/doc/reference/functions/im.Image">im.Image</a> function in loose mode. This means that if the assignment is a single string, it is interpreted as an image filename. Displayables are passed through unmolested. Once an image has been defined using an `image` statement, it can be used by the `scene`, `show`, and `hide` statements.</p>
<pre>
<span class="kwa">init</span><span class="sym">:</span>
    <span class="kwa">image</span> eileen happy <span class="sym">=</span> <span class="str">"eileen/happy.png"</span>
    <span class="kwa">image</span> eileen upset <span class="sym">=</span> <span class="str">"eileen/upset.png"</span>
</pre>
<div id="Init_Statement" />
<div id="init" />
<p><a id="Init_Statement" name="Init_Statement"></a></p>
<h3><span class="mw-headline">Init Statement</span></h3>
<p>The `init` statement is used to execute blocks of Ren'Py statements before the script executes. Init blocks are used to define images and characters, to set up unchanging game data structures, and to customize Ren'Py. Code inside init blocks should not interact with the user or change any of the layers, and so should not contain `say`, `menu`, `scene`, `show`, or `hide` statements, as well as calls to any function that can do these things.</p>
<pre>
init_statement -&gt; "init" (number)? ":"
</pre>
<p>An `init` statement is introduced with the keyword `init`, followed by an optional priority number, and a mandatory colon. If the priority is not given, it defaults to 0.</p>
<p>The priority number is used to determine when the code inside the init block executes. Init blocks are executed in priority order from low to high. Within a file, init blocks with the same priority are run in order from the top of the file to the bottom. The order of evaluation of priority blocks with the same priority between files is undefined.</p>
<p>The init blocks are all run once, during a special init phase. When control reaches the end of an init block during normal execution, execution of that block ends. If an init statement is encountered during normal execution, the init block is not run. Instead, control passes to the next statement.</p>
<div id="Jump_Statement" />
<div id="jump" />
<p><a id="Jump_Statement" name="Jump_Statement"></a></p>
<h3><span class="mw-headline">Jump Statement</span></h3>
<p>The `jump` statement is used to transfer control to the statement with the given name.</p>
<pre>
jump_statement -&gt; "jump" name 
jump_statement -&gt; "jump" "expression" simple_expression 
</pre>
<p>If the `expression` keyword is present, the expression is evaluated, and the string so computed is used as the name of the statement to jump to. If the `expression` keyword is not present, the name of the statement to jump to must be explicitly given.</p>
<p>Unlike `call`, `jump` does not push the target onto any stack. As a result, there's no way to return to where you've jumped from.</p>
<pre>
<span class="kwa">label</span> loop_start<span class="sym">:</span>

e <span class="str">"Oh no! It looks like we're trapped in an infinite loop."</span>

<span class="kwa">jump</span> loop_start
</pre>
<div id="Label_Statement" />
<div id="label" />
<p><a id="Label_Statement" name="Label_Statement"></a></p>
<h3><span class="mw-headline">Label Statement</span></h3>
<p>Label statements allow a name to be assigned to a program point. They exist solely to be called or jumped to, whether by script code or the Ren'Py config.</p>
<pre>
label_statement -&gt; "label" name ":"
label_statement -&gt; "label" name "(" parameters ")" ":"
</pre>
<p>A `label` statement may have a block associated with it. In that case, control enters the block whenever the label statement is reached, and proceeds with the statement after the label statement whenever the end of the block is reached.</p>
<p>The label statement may take an optional list of parameters. These parameters are processed as described in PEP 3102, with two exceptions:</p>
<ul>
<li>The values of default parameters are evaluated at call time.</li>
<li>The variables are dynamically, rather than lexically, scoped.</li>
</ul>
<p>Inside a called label, variables can be declared dynamic using the renpy.dynamic function:</p>
<p><br />
<span id="renpy.dynamic" /></p>
<table>
<tr>
<td valign="top">Function:</td>
<td valign="top"><b><a href="../reference/functions/renpy.dynamic.html" title="renpy/doc/reference/functions/renpy.dynamic">renpy.dynamic</a></b></td>
<td valign="top">(*vars):</td>
</tr>
</table>
<div class="renpy-doc">
<p>This declares a variable as dynamically scoped to the current Ren'Py call. The first time renpy.dynamic is called in the current call, the values of the variables named in the supplied strings are stored. When we return from the current call, the variables get their old values back. If renpy.dynamic is called twice for the same variable in a given call, it has no effect the second time.</p>
</div>
<p><br /></p>
<div id="Menu_Statement" />
<div id="menu" />
<p><a id="Menu_Statement" name="Menu_Statement"></a></p>
<h3><span class="mw-headline">Menu Statement</span></h3>
<p>Menus are used to present the user with a list of choices that can be made. In a visual novel, menus are the primary means by which the user can influence the story.</p>
<pre>
menu_statement -&gt; "menu" ( name )? ":"
</pre>
<p>A `menu` statement is introduced by the keyword `menu`, an optional name, and a colon. If the name is supplied, it is treated as a label for this `menu` statement, as if the menu statement was preceded by a label statement.</p>
<p>A `menu` statement must have a block associated with it. This is a menuitem block that must contain one or more menuitems in it. There are several kinds of menuitems that can be contained in a menuitem block.</p>
<pre>
caption_menuitem -&gt; string
</pre>
<p>The first kind of menuitem is a string. This string is placed into a menu as a caption that cannot be selected. In general, captions are used to indicate what the menu is for, especially when it is not clear from the choices.</p>
<pre>
choice_menuitem -&gt; string ( "if" python_expression )? ":"
</pre>
<p>The second kind of menuitem gives a choice the user can make. Each choice must have a block of Ren'Py statements associated with it. If the choice is selected by the user, then block of statements associated with the choice is executed. A choice may also have an optional `if` clause that includes a Python expression. This clause gives a condition that must be satisfied for the choice to be presented to the user. A terminating colon is used to indicate that this menuitem is a choice.</p>
<pre>
set_menuitem -&gt; "set" variable_name
</pre>
<p>The third kind of menuitem provides a variable in which to store the list of choices the user has made, and prevent the user making the same choice if the menu is visited multiple times. This variable must be defined before the menu statement, and should be an empty list, [ ]. When the user chooses a choice from the menu, that choice will be stored in the list. When the game reaches another menu statement using the same variable name in a `set` clause (or reaches the same menu again), any choices matching items in the list will not be shown.</p>
<pre>
with_menuitem -&gt; "with" simple_expression
</pre>
<p>The final kind of menuitem is a `with` clause. Please see <a href="../reference/Transitions.html" title="renpy/doc/reference/Transitions">Transitions</a> for more information on `with` clauses.</p>
<pre>
<span class="kwa">menu</span> what_to_do<span class="sym">:</span>

    <span class="str">"What should we do today?"</span>

    <span class="str">"Go to the movies."</span><span class="sym">:</span>
        <span class="str">"We went to the movies."</span>

    <span class="str">"Go shopping."</span><span class="sym">:</span>
        <span class="str">"We went shopping, and the girls bought swimsuits."</span>
        $ have_swimsuits <span class="sym">=</span> <span class="kwa">True</span>

    <span class="str">"Go to the beach."</span> <span class="kwa">if</span> have_swimsuits<span class="sym">:</span>
        <span class="str">"We went to the beach together. I got to see the girls in their</span>
<span class="str">         new swimsuits."</span>
</pre>
<p><a id="Details" name="Details"></a></p>
<h4><span class="mw-headline">Details</span></h4>
<p>When a menu is to be shown to the user, the first thing that happens is that a list of captions and choices is built up from the menuitems associated with the menu. Each of the choices that has an expression associated with it has that expression evaluated, and if not true, that choice is removed from the list. If no choices survive this process, the menu is not displayed and execution continues with the next statement. Otherwise, the `menu` function is called with the list of choices, displays the menu to the user, and returns a chosen choice. Execution continues with the block corresponding to the chosen choice. If execution reaches the end of that block, it continues with the the statement after the menu.</p>
<div id="Play_Statement" />
<p><a id="Play_Statement" name="Play_Statement"></a></p>
<h3><span class="mw-headline">Play Statement</span></h3>
<p>The play statement is used to play sound and music. If a file is currently playing, it is interrupted and replaced with the new file.</p>
<pre>
play_statement -&gt; "play" ( "sound" | "music" ) simple_expression 
                       ( "fadeout" simple_expression )?
                       ( "fadein" simple_expression )?
                       ( "channel" simple_expression )?
</pre>
<p>The first simple_expression in the play statement is expected to evaluate to either a string containing a filename, or a list of filenames to be played. The file is played using <a href="../reference/functions/renpy.sound.play.html" title="renpy/doc/reference/functions/renpy.sound.play">renpy.sound.play</a> or <a href="../reference/functions/renpy.music.play.html" title="renpy/doc/reference/functions/renpy.music.play">renpy.music.play</a>}, depending on the second keyword in the statement. The other clauses are all optional. Fadeout and fadein expect times in seconds, while channel expects a channel number. The channel number defaults to 0 for sound and 7 for music.</p>
<pre>
play music <span class="str">"mozart.ogg"</span>
play sound <span class="str">"woof.ogg"</span>

<span class="str">"Let's try something more complicated."</span>

play music <span class="sym">[</span> <span class="str">"a.ogg"</span><span class="sym">,</span> <span class="str">"b.ogg"</span> <span class="sym">]</span> fadeout <span class="num">1.0</span> fadein <span class="num">1.0</span>
</pre>
<div id="Pass_Statement" />
<div id="pass" />
<p><a id="Pass_Statement" name="Pass_Statement"></a></p>
<h3><span class="mw-headline">Pass Statement</span></h3>
<p>The `pass` statement does not perform an action. It exists because blocks of Ren'Py statements require at least one statement in them, and it's not always sensible to perform an action in those blocks.</p>
<pre>
pass_statement -&gt; "pass"
</pre>
<pre>
<span class="kwa">menu</span><span class="sym">:</span>
    <span class="str">"Should I go to the movies?"</span>

    <span class="str">"Yes"</span><span class="sym">:</span>
        <span class="kwa">call</span> go_see_movie

    <span class="str">"No"</span><span class="sym">:</span>
        <span class="kwa">pass</span>

<span class="str">"Now it's getting close to dinner time, and I'm starving."</span>
</pre>
<div id="Python_Statement" />
<div id="python" />
<p><a id="Python_Statement" name="Python_Statement"></a></p>
<h3><span class="mw-headline">Python Statement</span></h3>
<p>The `python` statement allows one to execute Python code in a Ren'Py script. This allows one to use Python code to declare things to Ren'Py, to invoke much of Ren'Py's functionality, and to store data in variables that can be accessed by user code. There are two forms of the `python` statement:</p>
<pre>
python_statement -&gt; "$" python_code
python_statement -&gt; "python" ( "hide" )? ":"
</pre>
<p>The first form of a python consists of a dollar sign (`$`) followed by Python code extending to the end of the line. This form is used to execute a single Python statement.</p>
<p>A second form consists of the keyword `python`, optionally the keyword `hide`, and a colon. This is used to execute a block of Python code, supplied after the statement. Normally, Python code executes in a script-global namespace, but if the `hide` keyword is given, a new namespace is created for this block. (The script-global namespace can be accessed from the block, but not assigned to.)</p>
<pre>
$ score <span class="sym">+=</span> <span class="num">1</span>

<span class="kwa">python</span><span class="sym">:</span>
    ui<span class="sym">.</span><span class="kwd">text</span><span class="sym">(</span><span class="str">"This is text on the screen."</span><span class="sym">)</span>
    ui<span class="sym">.</span><span class="kwd">saybehavior</span><span class="sym">()</span>
    ui<span class="sym">.</span><span class="kwd">interact</span><span class="sym">()</span>
</pre>
<p><b>Init Python Statement.</b> For convenience, we have created the init pythons statement. This statement combines an init statement and a python statement into a single statement, to reduce the indentation required for python-heavy files.</p>
<pre>
init python_statement -&gt; "init" ( number )? "python" ( "hide" )? ":"
</pre>
<div id="Queue_Statement" />
<p><a id="Queue_Statement" name="Queue_Statement"></a></p>
<h3><span class="mw-headline">Queue Statement</span></h3>
<p>The queue statement is used to queue up sound and music files. They will be played when the current track finishes playing.</p>
<pre>
queue_statement -&gt; "queue" ( "sound" | "music" ) simple_expression 
                       ( "channel" simple_expression )?
</pre>
<p>The first simple_expression in the queue statement is expected to evaluate to either a string containing a filename, or a list of filenames to be queued up. The files are queued using <a href="../reference/functions/renpy.sound.queue.html" title="renpy/doc/reference/functions/renpy.sound.queue">renpy.sound.queue</a> or <a href="../reference/functions/renpy.music.queue.html" title="renpy/doc/reference/functions/renpy.music.queue">renpy.music.queue</a>}, depending on the second keyword in the statement. The channel number defaults to 0 for sound and 7 for music, if not given.</p>
<pre>
queue sound <span class="str">"woof.ogg"</span>
queue music <span class="sym">[</span> <span class="str">"a.ogg"</span><span class="sym">,</span> <span class="str">"b.ogg"</span> <span class="sym">]</span>
</pre>
<div id="Return_Statement" />
<p><a id="Return_Statement" name="Return_Statement"></a></p>
<h3><span class="mw-headline">Return Statement</span></h3>
<p>The `return` statement pops the top location off of the call stack, and transfers control to it. If the call stack is empty, the return statement performs a full restart of Ren'Py.</p>
<pre>
return_statement -&gt; "return"
return_statement -&gt; "return" expression
</pre>
<p>If the optional expression is given to return, it is evaluated, and it's result is stored in the _return variable. This variable is dynamically scoped to each context.</p>
<div id="Say_Statement" />
<div id="say" />
<p><a id="Say_Statement" name="Say_Statement"></a></p>
<h3><span class="mw-headline">Say Statement</span></h3>
<p>The say statement is used to present text to the user, in the form of dialogue or thoughts. Since the bulk of the of the content of a script will be dialogue or thoughts, it's important that the say statement be as convenient as possible. Because of this, the say statement is the only statement that is not delimited with a keyword or other form of delimiter. Instead, it consists of a string, with an optional <i>simple_expression</i> before it to designate who is doing the speaking, and an optional `with` clause after it used to specify a transition.</p>
<pre>
say_statement -&gt; ( simple_expression )? string ( "with" simple_expression )?
</pre>
<p>There are two forms of the say statement, depending on if the simple expression is provided. The single-argument form consists of a single string (with or without the optional with clause). This form causes the string to be displayed to the user as without any label as to who is saying it. Conventionally, this is used to indicate POV character thoughts or narration.</p>
<pre>
<span class="str">"I moved to my left, and she moved to her right."</span>

<span class="str">"So we were still blocking each other's path."</span>

<span class="str">"I then moved to my right, and at the same time she moved to her</span>
<span class="str"> left."</span>

<span class="str">"We could be at this all day."</span>
</pre>
<p>The two-argument form of the say statement consist of a <i>simple_expression</i>, a string, and optionally a `with` clause. This form of the statement is used to indicate dialogue. The first argument is expected to be an object (usually a <a href="../reference/functions/Character.html" title="renpy/doc/reference/functions/Character">Character</a> or <a href="../reference/functions/DynamicCharacter.html" title="renpy/doc/reference/functions/DynamicCharacter">DynamicCharacter</a> object) that knows how to show dialogue to the user. The string is then passed to that object, which is responsible for showing it to to the user.</p>
<p>The <i>simple_expression</i> can also be a string, rather than an object. Strings are used directly as the name of the character.</p>
<pre>
<span class="str">"Girl"</span> <span class="str">"Hi, my name is Eileen."</span>

e <span class="str">"Starting today, I'll be living here."</span>
</pre>
<p><a id="Details_2" name="Details_2"></a></p>
<h4><span class="mw-headline">Details</span></h4>
<p>The two-argument say statement first evaluates the supplied simple expression. It then attempts to call that value (the who value) with the string giving the line of dialogue (the what string). If it can do so, it's finished, as the object that is called is responsible for interacting with the user.</p>
<p>If it can't call the value of the expression, then it copies the `name_only` character object, supplying the given string as a new character name, and then uses that to say the dialogue. (This is done by the `say` and `predict_say` functions found in the store. Changing these functions can change this behavior.)</p>
<p>The single-argument form of the statement simply calls the special function (or object) `narrator` with the string to be shown. This function is responsible for showing the string to the user. <a href="../reference/functions/Character.html" title="renpy/doc/reference/functions/Character">Character</a> and <a href="../reference/functions/DynamicCharacter.html" title="renpy/doc/reference/functions/DynamicCharacter">DynamicCharacter</a> objects are suitable for use as the `narrator`.</p>
<p>The `with` clause is used to specify a transition, see With Statement and Clauses for details.</p>
<div id="Scene_Statement" />
<div id="scene" />
<p><a id="Scene_Statement" name="Scene_Statement"></a></p>
<h3><span class="mw-headline">Scene Statement</span></h3>
<p>The `scene` statement clears a layer by removing all images from it. It may then show a supplied image to the user. This makes it appropriate for changing the background of a scene.</p>
<pre>
scene_statement -&gt; "scene" ("onlayer" name | image_spec )?
</pre>
<p>The scene statement first clears out all images from a layer. The layer is taken from the <i>image_spec</i> or `onlayer` clause, if present. The "master" layer is used if no other layer is specified.</p>
<p>If an <i>image_spec</i> is present, it is then added to the layer, as with the `show` statement.</p>
<p>By default, no background is added to the screen, so we recommend that every script begin with a scene statement that shows a full-screen background to the user.</p>
<div id="Show_Statement" />
<div id="show" />
<p><a id="Show_Statement" name="Show_Statement"></a></p>
<h3><span class="mw-headline">Show Statement</span></h3>
<p>The `show` statement takes an image specifier, and adds the specified image to the specified layer, with the "master" layer used if no `onlayer` clause is present.</p>
<pre>
show_statement -&gt; "show" image_spec
</pre>
<p>The `show` statement first finds a displayable to add to the screen. This is done by looking up the image name in the list of registered images. It then applies all transformations into the at list to the displayable. This yields the image to be added to the layer. The show statement then checks to see if an image beginning with the same image tag can be found in the layer. If such an image exists, it is replaces with the new image. Otherwise, the new image is added to the layer, in a position that makes it closer to the user than any other image.</p>
<pre>
<span class="kwa">scene</span> living_room
<span class="kwa">show</span> eileen happy <span class="kwa">at</span> left

e <span class="str">"I'm feeling happy right now."</span>

<span class="kwa">show</span> eileen upset <span class="kwa">at</span> left

e <span class="str">"But sometimes, I can get upset for no good reason."</span>
</pre>
<div id="Stop_Statement" />
<p><a id="Stop_Statement" name="Stop_Statement"></a></p>
<h3><span class="mw-headline">Stop Statement</span></h3>
<p>The stop statement is used to stop playing sound and music.</p>
<pre>
stop_statement -&gt; "stop" ( "sound" | "music" )
                       ( "fadeout" simple_expression )?
                       ( "channel" simple_expression )?
</pre>
<p><br />
The sound or music is stopped using <a href="../reference/functions/renpy.sound.stop.html" title="renpy/doc/reference/functions/renpy.sound.stop">renpy.sound.stop</a> or <a href="../reference/functions/renpy.music.stop.html" title="renpy/doc/reference/functions/renpy.music.stop">renpy.music.stop</a>}, depending on the second keyword in the statement. The other clauses are all optional. Fadeout expects a time in seconds, while channel expects a channel number. The channel number defaults to 0 for sound and 7 for music.</p>
<pre>
stop sound
stop music fadeout <span class="num">1.0</span>
</pre>
<p><br /></p>
<div id="With_Statement_and_Clauses" />
<div id="with" />
<p><a id="With_Statement_and_Clauses" name="With_Statement_and_Clauses"></a></p>
<h3><span class="mw-headline">With Statement and Clauses</span></h3>
<p>The `with` statement and `with` clauses are used to show transitions to the user. These transitions are always from the last screen shown to the user to the current screen. At the end of a `with` statement, the last screen shown to the user is set to the current screen. The last screen shown to the user can also be updated by `say` or `menu` statements, as well as by Python code.</p>
<p>The `with` statement has the form:</p>
<pre>
with_statement -&gt; "with" simple_expression
</pre>
<p>The <i>simple_expression</i> is expected to evaluate to a transition function. If it evaluates to the value <i>None</i>, the last screen shown to the user is updated to the current screen, without performing a transition. This is useful to remove transient interface items (like a prior `say` statement) from partaking in a transition.</p>
<p>For convenience, a number of statements support `with` clauses. In the case of the `scene`, `show`, and `hide` statements, the `with` clause is equivalent to placing a "with None" statement before the `scene`, `show` or `hide` statement, and a "with transition" statement after it. For example, the statement:</p>
<pre>
<span class="kwa">show</span> eileen happy <span class="kwa">with</span> dissolve
</pre>
<p>is equivalent to:</p>
<pre>
<span class="kwa">with None</span>
<span class="kwa">show</span> eileen happy
<span class="kwa">with</span> dissolve
</pre>
<p>This behavior can lead to undesired side-effects. The code:</p>
<pre>
<span class="kwa">show</span> bg whitehouse <span class="kwa">with</span> dissolve
<span class="kwa">show</span> eileen happy <span class="kwa">with</span> dissolve
</pre>
<p>will cause two transitions to occur. To ensure only a single transition occurs, one must write:</p>
<pre>
<span class="kwa">with None</span>
<span class="kwa">show</span> bg whitehouse
<span class="kwa">show</span> eileen happy
<span class="kwa">with</span> dissolve
</pre>
<p>With clauses can also be applied to `say` and `menu` statements. In this case, the transition occurs when the dialogue or menu is first shown to the user.</p>
<p>For pre-defined transition functions that can be used in any script, see <a href="../reference/Transitions#predefined" title="renpy/doc/reference/Transitions">Pre-defined Transitions</a>. For functions that return transition functions, see <a href="../reference/Transitions#constructors" title="renpy/doc/reference/Transitions">Transition Constructors</a>.</p>
<div id="While_Statement" />
<div id="while" />
<p><a id="While_Statement" name="While_Statement"></a></p>
<h3><span class="mw-headline">While Statement</span></h3>
<p>The `while` statement is used to execute a block of Ren'Py statement while a condition remains true.</p>
<pre>
while_statement -&gt; "while" python_expression ":"
</pre>
<p>When a `while` statement is executed, the <i>python_expression</i> is evaluated. If it evaluates to true, control is transferred to the first statement in the block associated with this `while` statement. If false, control is instead sent to the statement following the `while` statement.</p>
<p>When control reaches the end of the block associated with the while statement, it returns to the `while` statement. This allows the `while` statement to check the condition again, and evaluate the block if the condition remains true.</p>
<pre>
<span class="kwa">while not</span> endgame<span class="sym">:</span>

   <span class="str">"It's now morning. Time to get up and seize the day."</span>

    <span class="kwa">call</span> morning
    <span class="kwa">call</span> afternoon
    <span class="kwa">call</span> evening

    <span class="str">"Well, time to call it a night."</span>

<span class="str">"Now it's time to wake up and face the endgame."</span>
</pre>



<div class="visualClear" />
		<hr /><p class="docnav"><a href="../index.html">documentation index</a> &#9702; <a href="Reference_Manual.html">reference manual</a> &#9702; <a href="Function_Index.html">function index</a></p></div>
	</body></html>