Constantly getting "Line is indented" error

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.
Message
Author
User avatar
margaretcatter
Regular
Posts: 44
Joined: Fri May 18, 2018 7:16 pm
Projects: Kathelm Princess X Princess | Hurricane Like Me
itch: margaretcatter
Location: New York/LA
Contact:

Constantly getting "Line is indented" error

#1 Post by margaretcatter »

I feel like I'm doing something wrong every time because I keep getting these error. I'm working in atom if that matters.

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 9: Line is indented, but the preceding one-line python statement statement does not expect a block. Please check this line's indentation.
    max = 7
    ^
File "game/script.rpy", line 11: Line is indented, but the preceding one-line python statement statement does not expect a block. Please check this line's indentation.
    max = 4
    ^
File "game/script.rpy", line 40: menu statement expects a non-empty block.
    menu:
        ^
File "game/script.rpy", line 43: Line is indented, but the preceding say statement statement does not expect a block. Please check this line's indentation.
    "Princess Pansy has my backing, she's the most politically sauve of all the sisters":
    ^
Ren'Py Version: Ren'Py 6.99.14.3.3347
Sat May 19 19:16:59 2018

This is my code.

Code: Select all

label start:
$ day = 0:
    max = 7
$ tod = 0:
    max = 4
...


label chapter_oneB:

        menu:
        "Do you have a preference for our future Queen?"

            "Princess Pansy has my backing, she's the most politically sauve of all the sisters":
                $ pansy_points += 1


User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Constantly getting "Line is indented" error

#2 Post by Ocelot »

In Python (and, by extention, in RenPy), a block is a series of statements, logically executed sequentally. They should be written in neat columns:
https://i.imgur.com/rwPOz6P.png
https://i.imgur.com/YbvGMBL.png

A new block is introduced by increasing indentation level (moving start of the line further to the right, aka adding more spaces). It usually denotes statements logically belonging to preceding statement, and introduced by colon
https://i.imgur.com/4f4wOkR.png
< < insert Rick Cook quote here > >

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Constantly getting "Line is indented" error

#3 Post by Imperf3kt »

Additionally, Ren'Py uses four spaces as it's blocks. Some of your code has several more.

In practise, it should look like this:

Code: Select all

label start:
    $ day = 0:
        max = 7
    $ tod = 0:
        max = 4
...


label chapter_oneB:

    menu:
        "Do you have a preference for our future Queen?"

        "Princess Pansy has my backing, she's the most politically sauve of all the sisters":
            $ pansy_points += 1
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Constantly getting "Line is indented" error

#4 Post by Ocelot »

Strictly speaking, four spaces is a style requirement. Only hard limit is that blocks should be consistent (all lines in same block has same indent, new blocks are indented deeper than previous.)

You can have 1-space indent, then next block — 1 space, 3 tabs → next 1 space, 3 tabs, 5 spaces → back to 1 space → indent next block at 4 spaces... And it would be legal, but ugly and strongly discouraged by pep8.
< < insert Rick Cook quote here > >

User avatar
margaretcatter
Regular
Posts: 44
Joined: Fri May 18, 2018 7:16 pm
Projects: Kathelm Princess X Princess | Hurricane Like Me
itch: margaretcatter
Location: New York/LA
Contact:

Re: Constantly getting "Line is indented" error

#5 Post by margaretcatter »

Imperf3kt wrote: Sun May 20, 2018 8:15 am Additionally, Ren'Py uses four spaces as it's blocks. Some of your code has several more.

In practise, it should look like this:

Code: Select all

label start:
    $ day = 0:
        max = 7
    $ tod = 0:
        max = 4
...


label chapter_oneB:

    menu:
        "Do you have a preference for our future Queen?"

        "Princess Pansy has my backing, she's the most politically sauve of all the sisters":
            $ pansy_points += 1
https://imgur.com/e3sbAcp
https://imgur.com/S9a3Ay0

So I tried copy and pasting exactly what you wrote and got the same message. Then I tried instead of pressing tab counting out 4 & 8 spaces respectively and still got the same error.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Constantly getting "Line is indented" error

#6 Post by kivik »

Post your current code (not screenshots of part of it) and the corresponding error messages please

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Constantly getting "Line is indented" error

#7 Post by Ocelot »

Second:

Code: Select all

    $ day = 0:
        max = 7
Is cpimpletely incorrect. Python statements do not introduce block. Correct:

Code: Select all

    $ day = 0
    $ max = 7

# Or
    python:
        day = 0
        max = 7
First:
The dialogue and menu: statement should have same level of identation: there is no new block introduced there.
< < insert Rick Cook quote here > >

User avatar
margaretcatter
Regular
Posts: 44
Joined: Fri May 18, 2018 7:16 pm
Projects: Kathelm Princess X Princess | Hurricane Like Me
itch: margaretcatter
Location: New York/LA
Contact:

Re: Constantly getting "Line is indented" error

#8 Post by margaretcatter »

kivik wrote: Sun May 20, 2018 11:16 am Post your current code (not screenshots of part of it) and the corresponding error messages please
My errors:

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 12: Line is indented, but the preceding one-line python statement statement does not expect a block. Please check this line's indentation.
    max = 7
    ^

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

File "game/script.rpy", line 44: Line is indented, but the preceding say statement statement does not expect a block. Please check this line's indentation.
    menu:
    ^

File "game/script.rpy", line 63: Line is indented, but the preceding say statement statement does not expect a block. Please check this line's indentation.
    jump Chamber_of_War
    ^

Ren'Py Version: Ren'Py 6.99.14.3.3347
Sun May 20 11:46:26 2018
My Code

Line 12 & 14

Code: Select all

label start:
    $ day = 0:
        max = 7
    $ tod = 0:
        max = 4

Line 44

Code: Select all

    menu:
        "Princess Pansy has my backing, she's the most politically sauve of all the sisters":
            $ pansy_points += 1

User avatar
margaretcatter
Regular
Posts: 44
Joined: Fri May 18, 2018 7:16 pm
Projects: Kathelm Princess X Princess | Hurricane Like Me
itch: margaretcatter
Location: New York/LA
Contact:

Re: Constantly getting "Line is indented" error

#9 Post by margaretcatter »

Ocelot wrote: Sun May 20, 2018 11:19 am Second:

Code: Select all

    $ day = 0:
        max = 7
Is cpimpletely incorrect. Python statements do not introduce block. Correct:

Code: Select all

    $ day = 0
    $ max = 7

# Or
    python:
        day = 0
        max = 7
First:
The dialogue and menu: statement should have same level of identation: there is no new block introduced there.
Ah okay that fixed the indentation error, Thanks! I guess then my follow up though is does python/renpy then know that the max points is referring to the line above? Because thats why I was indenting it before. Because what I'm trying to have done is there are 7 day points which once you hit that max it resets to 0 to start the week over.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Constantly getting "Line is indented" error

#10 Post by Ocelot »

What do you mean by "refer" here? YOu cannot just create a block and expect anything to happen. Blocks are introduced only in several cases denoted by language rules. It would help if you explain what should happen here.
< < insert Rick Cook quote here > >

User avatar
margaretcatter
Regular
Posts: 44
Joined: Fri May 18, 2018 7:16 pm
Projects: Kathelm Princess X Princess | Hurricane Like Me
itch: margaretcatter
Location: New York/LA
Contact:

Re: Constantly getting "Line is indented" error

#11 Post by margaretcatter »

Ocelot wrote: Sun May 20, 2018 12:08 pm What do you mean by "refer" here? YOu cannot just create a block and expect anything to happen. Blocks are introduced only in several cases denoted by language rules. It would help if you explain what should happen here.
What I'm trying to do with the first set of code was set a week and time of day system that changes the backgrounds. So for example do event 1, 2 & 3 takes a morning cycle, do 5 events and its the end of the day and a new day starts and so on.

By refer I meant I want to set it so you can't have more than 7 day points at any given time before it resets to 0.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2384
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Constantly getting "Line is indented" error

#12 Post by Ocelot »

Do you mean something like:

Code: Select all

if day > 7:
    $ day = 0
?
< < insert Rick Cook quote here > >

User avatar
margaretcatter
Regular
Posts: 44
Joined: Fri May 18, 2018 7:16 pm
Projects: Kathelm Princess X Princess | Hurricane Like Me
itch: margaretcatter
Location: New York/LA
Contact:

Re: Constantly getting "Line is indented" error

#13 Post by margaretcatter »

Basically yeah but I was trying to write it so I wouldnt have to write that a bunch of times.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Constantly getting "Line is indented" error

#14 Post by kivik »

Just to clarify, when you're writing programming code - unless you explicitly write the code that tells the program to do something specific, it won't automatically know what you want. Your program also won't know what you're trying to do by the name of the variables, because it has no intelligence and it can't translate and interpret meanings from your code - it just compiles the instructions you give it.

With that said, you'll need to write your own function or classes to do what you want: and the simplest way is to use the mod operator %: e.g. 12 % 7 = 5

What the mod operator does is, it returns the remainder of your first value after being divided by the second value. e.g. with 1 % 7, 7 goes into 1 exactly 0 times, with 1 as a remainder. 12 % 7: 7 goes into 12 exactly 1 time, with a remainder 5.

This is what will reset your values to 0, so to speak. In programming, we usually count numbers from 0 - there're lots of benefits in programming terms, this being one of them: 7 % 7 == 0 because 7 goes into 7 once, with a remainder 0. So if you're counting 7 days, you'd actually count from 0 to 6. The cool thing is, since lists start at index 0, you can have:

Code: Select all

define day_of_week = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
default day = 0
default dow = day_of_week[day]

label start:
    "[dow]" # Shows "Sun"
    $ day += 12
    $ dow = day_of_week[day%7]
    "[dow]" # Shows "Fri"
    return
In reality, you'd probably want to create a function or better yet an object to manage that. The benefit of using mod here is that you are now working out the day of the week from a single variable - meaning your day and day of week can't possible fall out of sequence anywhere in your code.

You can use the same principle with time of day, but you'd probably also want to check whether you need to start a new day as well.

Code: Select all

define day_of_week = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
define time_of_day = ["Morning", "Noon", "Afternoon", "Evening", "Night"]

default day = 0
default tod = 0

default dow = day_of_week[day]
default time_now = time_of_day[tod]

init python:
    def advance_time(_time = 1):
        global tod, time_now, time_of_day, day
        new_days = (tod + _time) // 5 # // returns floored divisions, in other ways how many times the divider goes into the value, ignoring remainders

        tod = (tod + _time) % 5
        time_now = time_of_day[tod]

        advance_day(new_days) # add new days


    def advance_day(_day = 1):
        global day, dow, day_of_week
        day += _day
        dow = day_of_week[day%7]

label start:
    "[dow]"
    $ advance_day(12)
    "[dow]"

    "[time_now]"
    $ advance_time(6)
    "[dow] [time_now]"
It may be quite a lot to take in if you're unfamiliar with programming, so please feel free to ask questions. I need to head off for a bit but will try to answer if I'm able to.

User avatar
margaretcatter
Regular
Posts: 44
Joined: Fri May 18, 2018 7:16 pm
Projects: Kathelm Princess X Princess | Hurricane Like Me
itch: margaretcatter
Location: New York/LA
Contact:

Re: Constantly getting "Line is indented" error

#15 Post by margaretcatter »

w00t! Thank you. It now is telling me its Sunday Afternoon. I can't tell if thats coincidence (as it is in fact sunday afternoon) or if it will tell me that this evening when its sunday evening. We shall see.

Post Reply

Who is online

Users browsing this forum: Google [Bot]