0 votes
extends Node
var inventory = PoolStringArray()
var count = 0 

func checkItem(neededItem):
    if neededItem in inventory:
            print("I already have one though, 
                    so I guess I'll put this back...")
    else:
        while count < inventory.length():
            if inventory[count] == null:
                inventory.set(count, neededItem)
                break
            count += 1

Tried using double indentations on line 9 so that I could make the code easier to read, but it gives me the error: error(9,10): Parse Error: Unexpected EOL at String.

When I use the print statement normally without indentation however, it compiles just fine.

I read in the formatting section here that I should be able to use double indents, but it doesn't work. Any advice?

asked May 26 in Engine by lyji (33 points)

1 Answer

+1 vote
Best answer

There's an important difference in the example you linked. The lines aren't broken at arbitrary spots, but after a , between arguments. You can't break a string over multiple lines like that.

answered May 26 by kidscancode (16,966 points)
selected May 26 by lyji

Ah, I see. So it can't be used inbetween Strings? I saw some people using a backslash then moving to the next line as well, but that doesn't compile either. I assume that's also for arguments as well.

So is there no way to separate prints for readability? Thank you for responding so quickly :)

It's not that - the \ can work too, but not when you're inside a string.

print() takes multiple arguments, so you can do this:

print("I already have one though ",
        "so I guess I'll put this back...")

Oh cool! Just switched from Java so this is very helpful. Thank you :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.