You've reached a page on the Ren'Py wiki. Due to massive spam, the wiki hasn't been updated in over 5 years, and much of the information here is very out of date. We've kept it because some of it is of historic interest, but all the information relevant to modern versions of Ren'Py has been moved elsewhere.
Some places to look are:
Please do not create new links to this page.
You can remember user choices by assigning to variables. For example:
menu: "Buy her an Iguana": $ gift = "iguana" b "I'll take an iguana, my good man!" "Buy her a Corn Snake": $ gift = "corn snake" b "I'll take a Corn Snake, my good man!" "Buy her a tortoise": $ gift = "tortoise" b "Give me your slowest tortoise, please!"
Please note that a single "=" is used to assign a variable.
Later in the game, you can then use the to change the script based on the previous choice:
b "Open it, Mary." if gift == "iguana": m "Oh Bob, I've always wanted an iguana!" if gift == "corn snake": m "Oh Bob, I needed a corn snake that matches my red dress! Thank you so much!" if gift == "tortoise" m "Bob! It's so slow! I love you!"
Please note that the double "==" is used to test for equality.
You can call your variables anything that you like, as long as it doesn't conflict with keywords or character objects. The only rule with variables is that you have to assign to a variable before you can use it in a conditional.
Often, when you get to a particular point in a game, you'll want to tailor the options offered to the player depending on what they've chosen to do earlier in the game. Let's imagine that Bob and Mary are going out on their second date, and the player gets to choose between the Park and the Cafe - unless Bob gave Mary the tortoise as a gift, in which case they can go to the Tortoise Land Speed Trials!
b "So, where would you like to go, Mary?" menu: "I'd like to go to the park!": jump park_date "I'd like to go to the cafe!": jump cafe_date "Can we go tortoise racing?" if gift == "tortoise": jump tortoise_racing
(Notice the two equals signs "==" between gift and tortoise.)
The menu choice for tortoise racing will only appear when the result of the "if" test is true. If Mary was given a snake or an iguana, then the player will only be able to choose the park or cafe dates.
This system can be easily adapted if you want to have the player returned to a menu, but to hide the options(s) which have already been chosen.
First create the variables which the game will use.
$ park_date_done = False $ cafe_date_done = False $ tortoise_date_done = False
Notice that we use a single equals sign "=" because we're setting a value. Two equals signs "==" are for testing a value.
The names of variables can be any length you like, but can't contain spaces. The longer a name, the more descriptive it is, and so the easier it is to tell what it's for when you look back at your script in a few weeks, months or year's time. Of course it's also more typing, so it's worth choosing short names for variables that you'll use a lot.
... label date_choice: b "So, where would you like to go, Mary?" menu: "I'd like to go to the park!" if park_date_done == False: $ park_date_done = True jump park_date "I'd like to go to the cafe!" if cafe_date_done == False: $ cafe_date_done = True jump cafe_date "Can we go tortoise racing?" if gift == "tortoise": jump tortoise_racing "Let's just go home" if park_date_done ==True: jump date_over label park_date: b "Well, here we are, at the park!" m "Yes, it's very interesting. Can we do something else now?" jump date_choice label cafe_date: m "Gee, what an exciting cafe!" jump date choice # WRONG! should be date_choice label tortoise_date: # WRONG! Ren'Py will complain about this until you # correct it to "tortoise_racing" m "Well! A whole lot of tortoise-related fun!" b "Yeah, great." jump date_choice label date_over: "... and the game goes on from here." etc.
The park and cafe dates can only be chosen once, because Ren'Py changes the value of the variable concerned after the player chooses that option. At the end of that date, the "jump" instruction takes the player back to the date-choosing menu.
However, the lucky couple can go tortoise racing as often as they want, because Ren'Py isn't told to change the value of "tortoise_date_done." (That variable is just wasted, although Ren'Py won't complain.)
Notice that you have to have at least one "Exit" option that doesn't loop back to the menu, otherwise the player will get stuck. The "Just go home" option will appear after they've been to the park, because choosing the park option changes the variable the "Just go home" option tests.
Be careful not to make the "Exit" option the tortoise choice - otherwise players who gave iguanas or snakes will likewise be stuck, since that option won't show up for them.
A point-based game is one in which the choices that a user makes at menus cumulatively change the story after many of them have been made.
First, you'll need to decide what you want to be able to gain points for. For example, you might want the user to be able to win points by (1) building big muscles (strength) (2) learning to juggle large numbers of objects (dexterity) and (3) performing chemical experiments and creating increasingly advanced forms of life (mad science).
Next, you'll need to initialize the variables that you're going to use to keep track of these points. You do this immediately after the start label:
label start: $ strength_points = 0 $ dexterity_points = 0 $ mad_science_points = 0
During the game, you'll present the user with choices that affect these points, and then modify the variables based on the choices. To increase the points, use:
$ variable += 1
(That's plus followed by equals.) You can use any number, it doesn't have to be 1. To decrease the points:
$ variable -= 1
(That's minus followed by equals.) You can again use any number, not just 1.
menu: "Go to the gym": $ strength_points += 1 "The gym was hot and sweaty." "I picked up heavy things, then put them down again." "I always wonder why I bother, since I could achieve the same thing by not picking them up in the first place." "Practice juggling balls": $ dexterity_points += 1 "I practiced juggling seven balls." "It was hard, but I finally managed to get it at least once." "Practice juggling angry porcupines": $ dexterity_points += 3 $ strength_points -= 1 "Practicing with angry porcupines really sharpened my reflexes. Unfortunately, I'm feeling weak from blood loss." "Invent a happy porcupine": $ mad_science_points += 1 "Unfortunately I was only able to create a melancholy echidna, but I learned a lot and I was sure that next time would be better."
(You can of course customize the responses based on the current points, using the techniques outlined in the earlier section on variables.)
Finally, customize your ending using the variables:
if strength_points > max(dexterity_points, mad_science_points): "You pick up a cow and jump over the moon." elif dexterity_points > max(strength_points, mad_science_points): "You juggle 215 balls and set the world record." else: "You create the perfect companion and retire with it to the castle built by the army of servile eight-armed giant gorilla-men you created earlier in the day." return
The above code decides ties in favor of the last option (mad science). If you would like to be explicit about how to handle ties, it's more complicated, as there are seven possible conditions, but still quite doable. It looks like this:
if strength_points > max(dexterity_points, mad_science_points): "You pick up a cow and jump over the moon." elif dexterity_points > max(strength_points, mad_science_points): "You juggle 215 balls and set the world record." elif mad_science_points > max(strength_points, dexterity_points): "You create the perfect companion and retire with it to the castle built by the army of servile eight-armed giant gorilla-men you created earlier in the day." elif strength_points == dexterity_points == mad_science_points: "Your band of servile sixteen-armed giant gorilla-men built you three castles, which you juggle to impress the perfect companion you created earlier in the day." elif strength_points == dexterity_points: "You juggle three large boulders and many attractive people of the opposite sex swoon." elif dexterity_points == mad_science_points: "You invent a species of round humming bird, and juggle 5,000 of them at once." elif strength_points == mad_science_points: "You invent a 30 ton 24-armed gorilla man, and then pick him up so that he can paint the top part of the house he's building for you." return
The ordering of the conditions above is important, because later alternatives assume that previous ones have been false. In general, you want to first test if any single variable wins, then test if they're all the same, then test to see which ones tied. This strategy avoids several possible pitfalls in the game logic.