RenPy code help

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
If someone could either help me with my code problem or give me advice as to which Web Forum will give me the best advice i'd appreciate it.
I am trying to create a branch in RenPy that only takes you to alternative paths but at the end of each path takes you back to the main story.

This is the code error:
Code:
[code]
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 53: menu statement expects a non-empty block.
    menu:
        ^

File "game/script.rpy", line 54: expected statement.
    "kitchen":
             ^

File "game/script.rpy", line 56: expected statement.
    "shower":
            ^

Ren'Py Version: Ren'Py 6.99.14.1.3218
Sun Mar 18 16:27:30 2018
[/code]

and here's my code in the script":

Code:
    menu:
    "kitchen":
    jump kitchen
    "shower":
    jump shower
                    
label kitchen:
label shower:
 

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
Ive read that you can use tab or spaces in the script as long as it's consistent which i believe mine are...

Ive watched this video (cute girl but talks like a chip munk) and mine looks correct compared to hers.
 
  • Like
Reactions: demoxxx82

knerre

Newbie
Jul 30, 2017
34
42
All the lines should be indented. Every menu item expects an indented entry, so:

Code:
    menu:
      "kitchen":
         jump kitchen
       "shower":
         jump shower
Hope that helps!
 

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
just copied your code and got below unfortunately..

Code:
[code]
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 52: indentation mismatch.

Ren'Py Version: Ren'Py 6.99.14.1.3218
Sun Mar 18 17:03:07 2018
[/code]
 

knerre

Newbie
Jul 30, 2017
34
42
Hmmm, it's a bit hard to debug without knowing what's on line 52. Based on your code I think Ren'Py will error on the indentation of the menu and the fact that there's no content under the labels. Could you try the code below?

Code:
    menu:
        "kitchen":
            jump kitchen
        "shower":
            jump shower
              
    label kitchen:
        "You're in the kitchen."
    label shower:
        "You're in the shower."
I've copy pasted this from my text editor, so the indentation should be correct.
 

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
Mmmm interesting it's now shifted to the return...

Code:
[code]
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 92: indentation mismatch.

Ren'Py Version: Ren'Py 6.99.14.1.3218
Sun Mar 18 17:27:24 2018
[/code]

code looks like this

Code:
     # This ends the game.
    return
 

knerre

Newbie
Jul 30, 2017
34
42
Are there really a few spaces before # This ends the game.? Because that will trip Ren'Py up. Indendation is very important in Python (on which Ren'Py is based), more so than in other languages where you can use curly braces to denote blocks for example.
 

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
First of all, thx fro helping....

here's from the menu start to end of project... Maybe it makes sense to you..

Code:
    menu:
        "kitchen":
            jump kitchen
        "shower":
            jump shower
             
    label kitchen:
        "You're in the kitchen."
    label shower:
        "You're in the shower."
                    
label kitchen:
        scene jensenkitchen
        j "Mmmmm, love my eggs and bacon"
        scene jensenkitchen2
        j "Shit looks my coffee's done for already."
        j "I still can't believe that dream, I mean nightmare I had."
        j "Those girls sure did look like they were in pain."
        j "But why?"
        j "Ok, no time to dilly dally, I gotta get to the meeting with Mr... erm... whatever."
      
label shower:   
        scene jensenshower
        j "Argh the water is nice. Wish I can stand here the whole day. "
        j "Did not think a dream, I mean a nightmare could rattle my cage so much."
        scene jensenshower2
        j "Wonder if I will ever get to use you for what you really made for and I don't mean peeing..."
        j "It's been a while, hey mister willy"
        j "Fuck listen to me, talking to my penis as if it's a person."
        j "OK enough i'm off to see what this meetings all about, with ... what's his name..."
  
        scene jensengrage1
        j "Ok which will it be today"
        j "Bike, sports car or classic ?"
        scene jensendatsun
        j "Classic it is then."
        j "I remember dad use to take us to school in this, course it was not the same condition."
        j "Took a few years but I got you back to sexiness, hey girl!"
        j "Ok off we go."
    
     # This ends the game.
    return
 

knerre

Newbie
Jul 30, 2017
34
42
Both blocks should have the same level of indentation. So after label start: all code should be at one indent to the right.

Code:
    menu:
        "kitchen":
            "Go to kitchen."
            jump kitchen
        "shower":
            "Go to kitchen."
            jump shower
    
    label kitchen:
        "You're in the kitchen."
    label shower:
        "You're in the shower."

    label kitchen:
        scene jensenkitchen
        j "Mmmmm, love my eggs and bacon"
        scene jensenkitchen2
        j "Shit looks my coffee's done for already."
        j "I still can't believe that dream, I mean nightmare I had."
        j "Those girls sure did look like they were in pain."
        j "But why?"
        j "Ok, no time to dilly dally, I gotta get to the meeting with Mr... erm... whatever."
    
    label shower:  
        scene jensenshower
        j "Argh the water is nice. Wish I can stand here the whole day. "
        j "Did not think a dream, I mean a nightmare could rattle my cage so much."
        scene jensenshower2
        j "Wonder if I will ever get to use you for what you really made for and I don't mean peeing..."
        j "It's been a while, hey mister willy"
        j "Fuck listen to me, talking to my penis as if it's a person."
        j "OK enough i'm off to see what this meetings all about, with ... what's his name..."

        scene jensengrage1
        j "Ok which will it be today"
        j "Bike, sports car or classic ?"
        scene jensendatsun
        j "Classic it is then."
        j "I remember dad use to take us to school in this, course it was not the same condition."
        j "Took a few years but I got you back to sexiness, hey girl!"
        j "Ok off we go."

    # This ends the game.
    return
If you run this code now it will complain about duplicate labels, but the indentation is correct now.
 

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
Thank you... Is this something i will battle with a lot in the future as a beginner?

It works ... Thank you so much. I really appreciate it.
 
  • Like
Reactions: knerre

Studio Errilhl

Member
Game Developer
Oct 16, 2017
315
235
No. This is not a "battle". This is how Python works. Indentation. Each block of code (everything happening after you end a line with a :) will need to be indented with _the same number of spaces_. What you do is use a proper editor (Notepad++, SublimeText, Atom, Editra...) which allows 1. to translate tabs to spaces for you (so you just push tab a couple times, not space 8 or more times), and 2. automatically indents if you press enter after ending a line with :.

This is really not that hard to do/understand.

Code:
label start:
    "This will work"
    menu:
        "First choice":
            $ var = True
        "Second choice":
            $ var = False
    "And this is where we continue"

label second_label:
    "This is another"
However! Labels are not part of the code that needs to be indented. The above code will work, as long as the other indentation rules are followed. Labels are often indented to follow the rest of the code, but it is not _necessary_.
 

knerre

Newbie
Jul 30, 2017
34
42
Good that you got it working! I'm afraid you'll run into this problem more often as a beginner. But in time you'll learn how to spot errors more quickly.

What also helps is using a text editor that has the ability to assist you with code writing. I use professionally and it has many useful plugins. The is relevant, but maybe also a .
 
M

MightyMidnightMop

Guest
Guest
Another feature I have set on in my code editor is to have faint dots to show where spaces/tabs are. I've found that helps show indentation mismatches if you're pulling code from other sources.

Once you have a workflow established, this shouldn't continue to be an issue for you since you'll get into the habit of indenting the way Python expects.
 

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
If I may ask one more question regarding the story branch. When i choose the kitchen scene it then runs over to the shower scene which is not correct i need it to go to the jensengarage1 scene, what will this command be to make it skip or jump over the shower scene to where i need it to go?

Here's the code, you'll see what i mean.

Code:
    label kitchen:
        scene jensenkitchen
        j "Mmmmm, love my eggs and bacon"
        scene jensenkitchen2
        j "Shit looks my coffee's done for already."
        j "I still can't believe that dream, I mean nightmare I had."
        j "Those girls sure did look like they were in pain."
        j "But why?"
        j "Ok, no time to dilly dally, I gotta get to the meeting with Mr... erm... whatever."
    label shower:
        scene jensenshower
        j "Argh the water is nice. Wish I can stand here the whole day. "
        j "Did not think a dream, I mean a nightmare could rattle my cage so much."
        scene jensenshower2
        j "Wonder if I will ever get to use you for what you really made for and I don't mean peeing..."
        j "It's been a while, hey mister willy"
        j "Fuck listen to me, talking to my penis as if it's a person."
        j "OK enough i'm off to see what this meetings all about, with ... what's his name..."

        scene jensengarage1
        j "Ok which will it be today"
        j "Bike, sports car or classic ?"
 

knerre

Newbie
Jul 30, 2017
34
42
Add another label above scene jensengarage1 (something like label garage:), then add a jump to that label after the last line of the kitchen block. So:

Code:
j "Ok, no time to dilly dally, I gotta get to the meeting with Mr... erm... whatever."
jump garage
You can jump in and out blocks at your leisure.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,782
If you plan to "takes [us] to alternative paths but at the end of each path takes [us] back to the main story", then you've many possibilities :

The, "don't branch", way (the official one):
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              [your content]
        "choice 2":
              [your content]
   [common content after the two choices]
It's not a bad approach, but the more the game grow, the less you'll find what you search in it. It also complicate your life if you need choices inside your choices.


The, "I like branching", way:
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              jump myFirstChoice
        "choice 2":
              jump mySecondChoice

label myFirstChoice:
    [your content for the first choice]
    jump itContinueHere

label mySecondChoice:
    [your content for the second choice]
   # this jump is optional if the label is right after it
    jump itContinueHere

label itContinueHere:
   [common content after the two choices]
More easy to find what you search, but you'll end with a ton of labels, way more than really needed.


The, "I like branching and it look pro", way (too often used) :
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              jump myFirstChoice
        "choice 2":
             [your content for the second choice]
             jump itContinueHere

label myFirstChoice:
    [your content for the first choice]

label itContinueHere:
   [common content after the two choices]
It have all the possible cons of the two previous ways, none of their advantage, and it don't look pro.


The, "I've read ", way :
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              call myFirstChoice
        "choice 2":
              call mySecondChoice
   [common content after the two choices]

label myFirstChoice:
    [your content for the first choice]
    return

label mySecondChoice:
    [your content for the second choice]
    return
It's a temporary branching out of the main flow of the code, so you temporarily go out of it. Easy to understand, and easy to find what you search.


The " ", way :
Code:
   [common content before the two choices]
   call partWithChoice
   [common content after the two choices]

label partWithChoice:
    menu:
        "choice 1":
              [your content]
        "choice 2":
              [your content]
   return
Quoting , "prematurate optimization is the root of all evil (or at least most of it) in programming". You don't know what will come behind your choice, just that it will exist and potentially lead you, temporarily or not, outside of the main flow. So you temporarily quit the said, "main flow", and you'll decide later what to do in this part.
It's the easiest approach if you're already a coder, but probably confusing if you aren't one.
 

Deleted member 167032

Alternate Existence
Donor
Game Developer
Aug 16, 2017
2,719
4,929
Thank you for all teh information.

MY game plan is simple... NO STATS or information gathering from the reader. SO the choices or branches in the game will be very easy and very few. I am more after a flowing story than a game that you have to rinse and repeat shit over and over just to get a girl to do things for you. With this in mind what knerre gave me for my game plan is just dandy. Will definitely keep this forum topic in my favourites bar so i can get back to it...

It's a gamble as many players will find it boring, or if the story does not intrigue them. Anyway I've learned so much in just this topic forum alone.


If you plan to "takes [us] to alternative paths but at the end of each path takes [us] back to the main story", then you've many possibilities :

The, "don't branch", way (the official one):
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              [your content]
        "choice 2":
              [your content]
   [common content after the two choices]
It's not a bad approach, but the more the game grow, the less you'll find what you search in it. It also complicate your life if you need choices inside your choices.


The, "I like branching", way:
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              jump myFirstChoice
        "choice 2":
              jump mySecondChoice

label myFirstChoice:
    [your content for the first choice]
    jump itContinueHere

label mySecondChoice:
    [your content for the second choice]
   # this jump is optional if the label is right after it
    jump itContinueHere

label itContinueHere:
   [common content after the two choices]
More easy to find what you search, but you'll end with a ton of labels, way more than really needed.


The, "I like branching and it look pro", way (too often used) :
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              jump myFirstChoice
        "choice 2":
             [your content for the second choice]
             jump itContinueHere

label myFirstChoice:
    [your content for the first choice]

label itContinueHere:
   [common content after the two choices]
It have all the possible cons of the two previous ways, none of their advantage, and it don't look pro.


The, "I've read ", way :
Code:
   [common content before the two choices]
    menu:
        "choice 1":
              call myFirstChoice
        "choice 2":
              call mySecondChoice
   [common content after the two choices]

label myFirstChoice:
    [your content for the first choice]
    return

label mySecondChoice:
    [your content for the second choice]
    return
It's a temporary branching out of the main flow of the code, so you temporarily go out of it. Easy to understand, and easy to find what you search.


The " ", way :
Code:
   [common content before the two choices]
   call partWithChoice
   [common content after the two choices]

label partWithChoice:
    menu:
        "choice 1":
              [your content]
        "choice 2":
              [your content]
   return
Quoting , "prematurate optimization is the root of all evil (or at least most of it) in programming". You don't know what will come behind your choice, just that it will exist and potentially lead you, temporarily or not, outside of the main flow. So you temporarily quit the said, "main flow", and you'll decide later what to do in this part.
It's the easiest approach if you're already a coder, but probably confusing if you aren't one.