A Simple Ren'Py Script
The following is a simple but complete Ren'Py script. The colors are added to make it easier to read, and aren't part of the script proper.
init: image bg whitehouse = "whitehouse.jpg" image eileen happy = "eileen_happy.png" image eileen upset = "eileen_upset.png" $ e = Character('Eileen') label start: scene bg whitehouse show eileen happy e "I'm standing in front of the White House." show eileen upset e "I once wanted to go on a tour of the West Wing, but you have to know somebody to get in." "For some reason, she really seems upset about this." e "I considered sneaking in, but that probably isn't a good idea."
The beginning of this script is an init block, used to setup the overall game configuration and to declare resource names that will be used throughout the rest of the script. First, three images are defined:
image bg whitehouse = "whitehouse.jpg" image eileen happy = "eileen_happy.png" image eileen upset = "eileen_upset.png"
These definitions create what in Ren'Py terminology are called Displayables, which can then be referred to in other script statements, such as show, by name. It's worth noting that the names must be valid Python variable names, which cannot start with numbers.
In the next line in the init block, a Character variable is declared:
$ e = Character('Eileen')
The $ at the start of this line indicates that the line is actually a Python statement. It can be difficult at first to know what needs to be done in your script in a Python statement, and what can be done with the normal, simple Ren'Py core language statements, but at the most basic level you will only need a few Python statements.
In this case, the statement is creating a variable, e, and assigning to it the result of a call to the Character function with the argument 'Eileen'. In simpler terms, it creates a shortcut for use when writing lines of dialogue in the script, so that the full name Eileen doesn't have to be typed out every time she says something.
The next line introduces the label statement:
label start:
A label provides a spot for other Ren'Py script statements to call or jump to. By default, the Ren'Py main menu jumps to the label start when you start a new game.
Following the start label is the part of the script where you write the actual interactive game, so to speak. First, a scene statement:
scene bg whitehouse
This scene statement simply adds the previously defined Displayable bg whitehouse to the screen.
Next, a show statement:
show eileen happy
This show statement adds the previously defined eileen happy to the screen, on top of the image shown by the preceding scene statement.
e "I'm standing in front of the White House."
This line is an example of a say statement, although you will notice that it doesn't start with an actual 'say' keyword. Since say statements make up the bulk of a game script, they use the most basic syntax possible.
Here, the statement starts with the previously defined Python variable e, which is used to indicate to the Ren'Py interpreter that the line of dialogue should be shown on screen with the name defined in the call to its Character function - 'Eileen', of course.
Next comes another show statement:
show eileen upset
This line demonstrates one of the subtle advantages to using a show statement in combination with a multi-word Displayable label. Recall that in the init block, there were eileen happy and eileen upset definitions. When the show statement executes, it first checks whether there are already any images on the screen where the first word of the name matches the first word of the new image to show. If it finds any, the previous image is hidden and replaced with the new one.
Put simply, the eileen happy image already on the screen is hidden and replaced with eileen upset, since they both start with eileen.
Next is another line of Eileen dialogue:
e "I once wanted to go on a tour of the West Wing, but you have to
know somebody to get in."
This line happens to be split onto two physical script lines, but will be joined when shown on screen. Note that script line breaks will not be carried into the displayed line - if you want to force a linebreak on screen, you will need to use an explicit newline (\n).
Next, another say statement, in its simplest form:
"For some reason, she really seems upset about this."
The simplest say statement is just one quoted string. It will be shown on screen without a character name label, and is thus generally used as narration of POV character thoughts.
Finally, the last line is more dialogue:
e "I considered sneaking in, but that probably isn't a good idea."
After you click on the final line of dialogue in-game, you will be returned to the main menu.