Getting started and "common" mistakes in Renpy

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
spiral
Regular
Posts: 47
Joined: Mon Mar 04, 2013 5:48 am
Location: Australia
Contact:

Getting started and "common" mistakes in Renpy

#1 Post by spiral »

Hi! This is only my second post, so I hope I'm not inadvertently putting my foot in my mouth, but I've really appreciated all the help I've gotten from lurking on these forums and wanted to share something back. Thus, a "getting started" guide I made to help the writers on my team code their dialogue into Ren'py, since the "Quickstart" guide didn't seem to be enough. I also included some "common" mistakes, but this is based on my very limited experience. Please let me know if I've made any mistakes or if you can think of other common mistakes people make when just starting out with simple dialogue. I hope someone finds this useful!
---------------
(Originally posted to my blog)
So, you have a script for a scene you want to turn into renpy code. Where do you start?

Renpy has a very nice Quickstart Guide for downloading Renpy and creating a simple game, as well as a good inbuilt tutorial and some patchy but mostly useful online documentation.

I recommend following their advice for installing Renpy, then running the tutorial. Don't stress if some parts are a bit confusing. Now go through the Quickstart Guide and play around with the example game they give you.

Finally, try writing your script up yourself, then running it. If it works exactly as planned, hurrah! You don't need me :) If it doesn't, poke at the categories below to figure out where you went wrong, and if THAT still doesn't work look at the "where next" section.

(I've written code in italics. I haven't gone into images since I can't think of anything to say not covered better by the Quickstart guide)

Starting
Open the Renpy launcher. If you're working within an existing project, choose that, otherwise start a new one. Click "Edit Script" to open jEdit (on the Mac, anyway), it's not perfect but helps a lot with indenting and keeping track of data types. You can create a new document using File->New, make sure to save it with the extension .rpy or it won't be compiled.

Give your scene a label, with the line label scene_name: at the start. Now go to script.rpy and put jump scene_name after the start label, like so:

Code: Select all

label start:

    jump scene_name
Note the indenting. Now when you run the project, it will go straight to your scene.

Indenting
Indenting is the only way Renpy has to keep track of what code goes where in branching paths. An indent is required after any command followed by a colon, such as label, menu, or if. Specifically, the first line after the label at the start of your scene needs to be indented.

To indent a single line you can use Tab. To shift a block of text all at once, select the text you want to indent and choose Edit->Indent->Shift Indent Left/Shift Indent Right from the jEdit menu.

The number of spaces used to indent doesn't matter as long as it's consistent, but since jEdit automatically uses 4 spaces per indent you might as well stick to that.

jEdit will guess which lines need to be indented and by how much, and sometimes guesses wrong. This can be annoying.

Dialogue
Make sure all your dialogue is in the form of lines like character_name "Dialogue". You will probably have to search and replace a lot of smartquotes, and do searches like character_name: " to character_name ", depending on how your original script is formatted. The editor will highlight all the strings (dialogue) in the same colour (for me it's green), make sure you haven't missed any quotes anywhere.

Every character with a speaking line needs to be defined outside the script. The easiest way to do this is in a block at the start of your file. The format is define character_name = Character('Name', color="#c8ffc8").

Name is the name that shows up on screen, character_name is the name you use in code, and #c8ffc8 is the colour of the text their name is shown in.

So, you should have something like this:

Code: Select all

define jane = Character('Jane Smith', color="#FF0000")
define bob = Character('Robert Smith', color="#0000FF")
label scene_name:
    jane "Hey Bob!"
    bob "Hey Jane!"
Congratulations, 90% of your code is done! If you have no branches, you should be able to test and run your code right now, though you won't see any images.

Branches
Branching choices have the following format:

Code: Select all

menu:
    "First menu choice":
        character_name "Only those who choose first can see this"
    "Second menu choice":
        character_name "Only those who choose second can see this"
character_name "Everyone can see this."
NOTE THE INDENTING, after the menu command AND after each menu choice. If you don't indent correctly, Renpy will either crash or show your dialogue at the wrong time.

If a block of text is getting unwieldy or you want to link to it more than once, give it a label and use jump to jump to it. Here is an equivalent way to code the menu above:

Code: Select all

menu:
    "First menu choice":
        jump first_part
    "Second menu choice":
        jump second_part

label first_part:
    character_name "Only those who choose first can see this"
    jump last_part

label second_part:
    character_name "Only those who choose second can see this"
    jump last_part

label last_part:
    character_name "Everyone can see this."
Regarding If and while statements and variables:
1)Changing variables has to be done in a Python block, usually by using a dollar sign
2) You SET a variable with a single equals sign, but you TEST it with a double equals sign.

See for example:

Code: Select all

    $ countdown =10

    while countdown >= 0:
      if countdown ==0:
          "BLASTOFF!!"
      elif countdown == 10:
          "Starting countdown! 10..."
      else: 
          "[countdown]..."
      $ countdown -=1
    
    "And now the rocket is gone forever..."
Common errors

Forgetting to save the file you've just edited before running Renpy.

Doing a whole big scene at once instead of starting small to get the hang of the syntax.

Unclosed dialogue tags or smart quotes. If you want to use a quote symbol within dialogue use a backslash bore it, \".

Using the same label twice. Renpy will crash and say something like "Cannot assign style outside of init phase". This is the default "I am crashing and I don't know why" error, and usually means something has been defined twice.

Forgetting to go into Python mode when dealing with variables. Remember the dollar sign!

Using == (testing equality) when you mean = (setting a variable) and vice versa.

Using - or + when you mean -= or +=. Note that the following statements are equivalent:

Code: Select all

    $ x = x-1
    $ x -= 1
    $ x += -1
Not indenting correctly. Everything in the same if: while: menu: etc block needs to have the same indenting. The first line after a label: has to be indented.

Forgetting the colon after if elif else while menu label etc, including menu choices.

Also, a handy hint for jEdit: search and search and replace both have an "all buffers" option which makes it easier to track down bugs and fix wide scale mistakes.

Where next?

If you've gotten the hang of basic dialogue and want to do fancier things, here's some places to look for help:
Follow the 'Next Topic' trail on the sidebar of Renpy Docs pages
Read the relevant parts of the FAQ
Poke at the cookbook
Use the Renpy Docs page Search, search at LemmaSoft or just type "Renpy (what you want)" into google.
Ask at Lemmasoft. Haven't tried this yet I am too shy :)

gekiganwing
Lemma-Class Veteran
Posts: 2473
Joined: Wed Sep 29, 2004 1:38 pm
Contact:

Re: Getting started and "common" mistakes in Renpy

#2 Post by gekiganwing »

Otome-games.com offers their own six-step Ren'py tutorial. While the site is aimed at fans of girl x boy(s) stories, I think just about any creator will benefit from reading the advice.

User avatar
spiral
Regular
Posts: 47
Joined: Mon Mar 04, 2013 5:48 am
Location: Australia
Contact:

Re: Getting started and "common" mistakes in Renpy

#3 Post by spiral »

gekiganwing wrote:Otome-games.com offers their own six-step Ren'py tutorial. While the site is aimed at fans of girl x boy(s) stories, I think just about any creator will benefit from reading the advice.
Wow, that tutorial looks great, thanks!

rainseed
Newbie
Posts: 9
Joined: Mon Aug 08, 2011 10:44 am
Contact:

Re: Getting started and "common" mistakes in Renpy

#4 Post by rainseed »

Hello, I successfully used Renpy two years ago prior to a lot of updates and am now having a common user issue when attempting to jump back in. Where within the filepaths do we need to place the images for projects for them to be correctly used and identified?

Here's my code:
image loadscreen = "loadscreen.png"
image iris = "iris.png"

image irisb = "irisbust.png"
image overall = "overall map.jpg"

define k = Character('Iris', color="#9900CC")


init python:
config.screen_width = 1080
config.screen_height = 720
label start:
label map:
with fade
show image loadscreen
with fade
show image irisb at right

k "Why hello there. Where would like to go?"
with fade
show image overall at left behind irisb

And here's the error message I get:
An exception has occured.
While running game code:
File "game/script.rpy", line 16, in script
File "game/script.rpy", line 16, in python
NameError: name 'loadscreen' is not defined

Here is the file path for where I currently have the images (they are within the game directory):
C:\Users\rainseed\Downloads\renpy\renpy-6.15.5-sdk\renpy-6.15.5-sdk\DnD Map Navi\game

If this post is in the wrong location please contact me and I will remove it, since your topic is on common mistakes I figured file path management was one of them.

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Getting started and "common" mistakes in Renpy

#5 Post by OokamiKasumi »

rainseed wrote:Hello, I successfully used Renpy two years ago prior to a lot of updates and am now having a common user issue when attempting to jump back in. Where within the filepaths do we need to place the images for projects for them to be correctly used and identified?
You only need to worry about filepaths when you use images in folders inside the game folder. However, your indentation appears to be missing. That will cause a whole slew of errors right there.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
spiral
Regular
Posts: 47
Joined: Mon Mar 04, 2013 5:48 am
Location: Australia
Contact:

Re: Getting started and "common" mistakes in Renpy

#6 Post by spiral »

rainseed wrote: show image loadscreen
with fade
show image irisb at right
I'm not sure this is the right place but I'll answer your question anyway ;)

You don't need those "image"s. The "image" command is used to define images, not show them. You should just say

Code: Select all

show loadscreen
with fade 
show irisb at right
etc.

Actually, you may want to say

Code: Select all

scene loadscreen
with fade 
show irisb at right
The "scene" command clears the screen and is used for whole screen images like backgrounds and titles etc, which is what I assume your loadscreen is. But "show" will work too.

Also, if you use the "code" option when you post to the forums it keeps your indentation.

rainseed
Newbie
Posts: 9
Joined: Mon Aug 08, 2011 10:44 am
Contact:

Re: Getting started and "common" mistakes in Renpy

#7 Post by rainseed »

Thank you, everyone's been wonderfully helpful :)

emocookie41
Regular
Posts: 55
Joined: Thu Aug 29, 2013 4:44 pm
Projects: Island Story
Contact:

Re: Getting started and "common" mistakes in Renpy

#8 Post by emocookie41 »

I was using that tutorial that you have posted as a link. Win I got through the sixth step it did not explain how to do the "if" formulas after day 2. I feel like the if metchris option is in accurate since you already used it once. Any idea how I write the "if" formula for day 3 and up?

User avatar
spiral
Regular
Posts: 47
Joined: Mon Mar 04, 2013 5:48 am
Location: Australia
Contact:

Re: Getting started and "common" mistakes in Renpy

#9 Post by spiral »

emocookie41 wrote:I was using that tutorial that you have posted as a link. Win I got through the sixth step it did not explain how to do the "if" formulas after day 2. I feel like the if metchris option is in accurate since you already used it once. Any idea how I write the "if" formula for day 3 and up?
I must admit I hadn't actually read that tutorial all the way through myself. And the code they provide is ambiguous so I'm not surprised you're confused. I'm pretty sure what they MEANT was that by the end of Day2, whatever choices you make you've met both Brandon and Chris. But they don't seem to state it explicitly. Here's what I think the beachday2 code should look like (with crappy dialogue :)):

Code: Select all

    
label beachday2:
    scene bg beach with dissolve
    show alice at right with moveinright
        if metbrandon:
            a "Hi Brandon nice to see you again."
            b "Hi Alice! This is Chris!"
            a "Hi Chris! Nice to meet you!"
            $ metchris=True
        else:
            a "Wait, that boy over there...I think I've seen him at school! Brandon, is that you?"
            b "Yes it is!"
            $ metbrandon=True
    return   
And the cafeday2 code would be similar. So at the start of day3 we know that metchris and metbrandon are both True, and don't have to test for either of them.

User avatar
SBG_Eric
Regular
Posts: 65
Joined: Fri Feb 07, 2014 11:40 pm
Completed: Warhammer 40K (non-commercial MTG set), Tales of Symphonia (non-commercial MTG set)
Projects: Galactic Domain, Dragonfish Racers, *A Yet Unnamed Miniatures Wargame*
Organization: Sunbridge Games LLC
IRC Nick: SBG_Eric
Location: USA, East Coast
Contact:

Re: Getting started and "common" mistakes in Renpy

#10 Post by SBG_Eric »

Hey, just a little nitpick about jumping. I actually find it easier to make a file called Scenes.rpy and then call them to Script.rpy using the call feature. A rough example may look like this.

(from Scenes.rpy)

label BD1:
# BD1 Content
return

label R1:
# R1 Content
return

label CD1:
# CD1 Content
return

(from Script.rpy)

label start:
menu:
"Option BD1":
call BD1
"Option R1":
call R1
"Option CD1":
call CD1
return

This is a very basic example which would allow you to structure you're game by calling each scene as needed. From this point, you can add flags and variables to the game and change them during the called scenes, using logic statements to progress from call statement to call statement. Hope that helps someone out a bit! :mrgreen:

EDIT: Seems that the forums don't want to leave the indentations... but just imagine that they're there. :lol:
Sunbridge Games Projects
Visual Novel Project (Pre-Dev): http://lemmasoft.renai.us/forums/viewto ... 60&t=33087
- Seeking Writer (5% per scenario) [1 Scenarios Remaining]

Galactic Domain (Post-Dev/Testing) & Dragonfish Racers (In-Dev): Projects on Hold // Require Artist(s)

Other projects TBA: 2+

Fantasy/Play-or-Die Light Novel (Outline/Drafting)

Anima
Veteran
Posts: 448
Joined: Wed Nov 18, 2009 11:17 am
Completed: Loren
Projects: PS2
Location: Germany
Contact:

Re: Getting started and "common" mistakes in Renpy

#11 Post by Anima »

SBG_Eric wrote: (from Scenes.rpy)

Code: Select all

label BD1:
    # BD1 Content
    return

label R1:
    # R1 Content
    return

label CD1:
    # CD1 Content
    return
(from Script.rpy)

Code: Select all

label start:
    menu:
        "Option BD1":
            call BD1
        "Option R1":
            call R1
        "Option CD1":
            call CD1
    return
EDIT: Seems that the forums don't want to leave the indentations... but just imagine that they're there. :lol:
You can quote my post to see how to use the code tags.
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase III

Post Reply

Who is online

Users browsing this forum: No registered users