Double indentation on continuous lines doesn't compile

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lyji
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?

:bust_in_silhouette: Reply From: kidscancode

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.

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 :slight_smile:

lyji | 2020-05-26 17:50

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...")

kidscancode | 2020-05-26 17:54

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

lyji | 2020-05-26 17:58