problem with indent mismatch

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
carnis_anubis
Newbie
Posts: 2
Joined: Sun Jan 17, 2021 9:59 pm
Contact:

problem with indent mismatch

#1 Post by carnis_anubis »

Hey I'm new to ren'py and coding in general and I keep on getting this message!

Code: Select all

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


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

Ren'Py Version: Ren'Py 7.4.0.1167
Sun Jan 17 20:53:03 2021
And this is my code!

Code: Select all

    menu:
$ player_name = renpy.input("YOUR NAME?"):
$ player_name = player_name.strip()
        if player_name == "":
            $ player_name = "Aerrox"

        elif player_name == "Aerrox":
            $ player_name="Aerrox"
            s "... So your name is Aerrox. Stop wasting time."

        if player_name == "The Rot" or player.name == "the rot":
            s "..."
            $ persistent.worthless = True
            $ renpy.quit()
        if player_name[:4].lower() == "rot":
            $ persistent.worthless = True
            $ renpy.quit()
        if persistent.worthless == True:
            p "LEAVE ME ALONE."
            $ renpy.quit()
        define persistent.worthless = False
    return
The problem is when I indent 'return' it comes up with a new error message?

Code: Select all

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


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

File "game/script.rpy", line 17: Line is indented, but the preceding one-line python statement statement does not expect a block. Please check this line's indentation.
    if player_name == "":
    ^

Ren'Py Version: Ren'Py 7.4.0.1167
Sun Jan 17 21:04:58 2021
What am I doing wrong? Thanks!

User avatar
Alex
Lemma-Class Veteran
Posts: 3095
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: problem with indent mismatch

#2 Post by Alex »

Indentation (some spaces at the beginning of a line of code) realy matters for Ren'Py.
Check an old, but useful explanaition (the other answers on that page are mostly out of date, so don't read them) - https://www.renpy.org/wiki/renpy/doc/FAQ (search for 'How does indentation work? What are blocks?').

The rule is simple - if you have a block of code the first line should ends with colon (:), other lines in that block should be extra indented and all that lines inside a block must have the same indentation (equal number of spaces at the beginning of the line).

Then, you'll be able to correct your code.

It looks like you don't need the line 'menu' at all, so just delete it.
Delete colon at the end of line with input - it doesn't need a block of code.
Make the same indentation for lines in blocks, like

Code: Select all

default persistent.worthless = False

label start:
    $ player_name = renpy.input("YOUR NAME?")
    $ player_name = player_name.strip()
    if player_name == "":
        $ player_name = "Aerrox"

    elif player_name == "Aerrox":
        $ player_name="Aerrox"
        s "... So your name is Aerrox. Stop wasting time."

    if player_name == "The Rot" or player.name == "the rot":
        s "..."
        $ persistent.worthless = True
        $ renpy.quit()
    if player_name[:4].lower() == "rot":
        $ persistent.worthless = True
        $ renpy.quit()
    if persistent.worthless == True:
        p "LEAVE ME ALONE."
        $ renpy.quit()
        
    return
https://www.renpy.org/doc/html/index.html

https://www.renpy.org/doc/html/python.h ... -statement
https://www.renpy.org/doc/html/python.h ... -statement

carnis_anubis
Newbie
Posts: 2
Joined: Sun Jan 17, 2021 9:59 pm
Contact:

Re: problem with indent mismatch

#3 Post by carnis_anubis »

Alex wrote: Mon Jan 18, 2021 2:55 pm Indentation (some spaces at the beginning of a line of code) realy matters for Ren'Py.
Check an old, but useful explanaition (the other answers on that page are mostly out of date, so don't read them) - https://www.renpy.org/wiki/renpy/doc/FAQ (search for 'How does indentation work? What are blocks?').

The rule is simple - if you have a block of code the first line should ends with colon (:), other lines in that block should be extra indented and all that lines inside a block must have the same indentation (equal number of spaces at the beginning of the line).

Then, you'll be able to correct your code.

It looks like you don't need the line 'menu' at all, so just delete it.
Delete colon at the end of line with input - it doesn't need a block of code.
Make the same indentation for lines in blocks, like

Code: Select all

default persistent.worthless = False

label start:
    $ player_name = renpy.input("YOUR NAME?")
    $ player_name = player_name.strip()
    if player_name == "":
        $ player_name = "Aerrox"

    elif player_name == "Aerrox":
        $ player_name="Aerrox"
        s "... So your name is Aerrox. Stop wasting time."

    if player_name == "The Rot" or player.name == "the rot":
        s "..."
        $ persistent.worthless = True
        $ renpy.quit()
    if player_name[:4].lower() == "rot":
        $ persistent.worthless = True
        $ renpy.quit()
    if persistent.worthless == True:
        p "LEAVE ME ALONE."
        $ renpy.quit()
        
    return
https://www.renpy.org/doc/html/index.html

https://www.renpy.org/doc/html/python.h ... -statement
https://www.renpy.org/doc/html/python.h ... -statement
Oh okay! I understand now! Thank you for the explanation and help! I appreciate it!

Post Reply

Who is online

Users browsing this forum: decocloud, Google [Bot]