Getting Stuck with Indentation

Hey all!

I’m getting very stuck with indentation. I’ve been writing for a long time, and have some published short stories and poems to my name, as well as some produced plays, but I’m an absolute beginner to programming and ChoiceScript.

For a while, I was able to move throughout most of a scene without issue, utilizing goto and choice commands (as well as the # with choices, and of course “finish”), but then everything got stuck.

I’ve been toying around with ChoiceScript for about three days now, but still getting stuck, so figured I’d reach out for help.

I’ve already looked at some articles/posts about indentation, but none seem to address exactly how to understand how indentation needs to be in order to make the game function (unless maybe I’m having more problems than indentation)?

I’ve got screenshots of my code as well as the issues here.

Any help is appreciated!

The last time I tried to fix it, I moved the labels to the bottom.





think of it like playing with buildingblocks just upside-down
for example

*if (var)
...text
...*choice that is meant to show in this scenario
......#first option of that choice
.........*set (var) if appliable
.........text to go with this choice
.........*goto label
......#second option of that choice
.........*set (var) if appliable
.........text to go with this choice
.........*goto otherlabel
*else
...other text
...*choice that is meant to show in this scenario
......#first option of that choice
.........*set (var) if appliable
.........text to go with this choice
.........(this line is empty not mash the text together when it's continued)
.........*goto otherlabel
......#second option of that choice
.........*set (var) if appliable
.........text to go with this choice
.........*page_break (this creates a page_break before the game continues to the next label)
.........*goto label

*label label
text

more text
*fake_choice
...#the first option
......*set stuff
......flavor text that will continue at §
...#second option
......*set other stuff
......more text that will continue at §
...#third option
......*set this stuff
......different text that will NOT continue at § but at &
......*goto fancylabel
§ text is continued here (you don't need the §, that just a marker)

more text

*goto different_label

*label fancylabel
& text continues here

more text

*goto different label

Hope that helps.
A note on gotos and fake_choices that have the text continue like that:

  • An empty line (with the correct indents depending on there it is, see above) prevents follow-up text from being mashed together with any flavour text.

Thus:

*fake_choice
...#option
......We got bananas, apple and (<- there's a space here)
...#option2
......We got strawberries, pears and (<- again a space)
honeycomb.

option 2 for example will show the text as

We got strawberries, pears and honeycomb.

in one line.
where as

*fake_choice
...#option
......You look at them and sigh frustrated.
......
...#option2
......You look at them and grin amused.
......
"Yeah, that's just what I expected," you say.

This will show as either

You look at them and sigh frustrated.

"Yeah, that's just what I expected," you say.

OR

You look at them and grin amused.

"Yeah, that's just what I expected," you say.

Hope this helps

1 Like

If you are referring to the errors regarding the illegal mixing of tabs and spaces then I think I can help.
There are two ways of using indentations in your code.

  • Tabs
  • Spaces

You can only use one type of indentations in a file, so if you began with using tabs then you will have to continue to use tabs only.
If you wish to use spaces then you would need to change all tabs into spaces (vice versa for spaces to tabs)
You can not mix tabs and spaces otherwise you will get this error prompt.

5 Likes

I think I understand the very basics of having a choice and that indents with the options that are flush with one another, but I think I’m having the most problems still with the indentation when goto commands are involved, or nested choices (I’ve looked over what you’ve sent though, and I’ll look over it again a few times here… as a newbie, I think it’ll take a bit for some of it to sink in). Regardless, thank you!

I’ve tried to convert to all tabs and all spaces, but it seems like it’s just led to more of a headache (sometimes even after clicking convert to all tabs, it’s showing up as having spaces… I’m wondering if it’s counting dialogue as including spaces?). Regardless, thank you very much for your help!

*goto go at from where you want them to go, in lack of a better phrase.

e.g.

*choice
...#option
......text
......*goto x

OR
*fake_choice
...#option
......text
...#option2
......text
text
*goto

nested choices are tricky, but it’s something to get used to:

*choice
...#optionA1
......text
......*choice
.........#optionB1
............text
............*goto x
.........#optionB2
............text
............*goto y
...#optionA2
......text
......*choice
.........#optionC1
............text
............*goto x
.........#optionC2
............text
............*goto y

*label

Well that’s easy. You’ve just added spaces until it “feels right”.

Every single time you increase the indent, you must increase it by the same amount. You’re really, really inconsistent. Like, forget everything you’ve done, start over, and build good habits from scratch.

Right now, you do your code like this.
*fake_choice
..........# Option One
............Flavour text one
..........# Option Two
............Flavour text two

*fake_choice
.....# Option Three
..................Flavour text three
.....# Option Four
..................Flavour text four

You see the problem? You’re totally inconsistent. Sometimes it’s like five spaces, sometimes nine, sometimes a dozen – you really don’t see why the program might have trouble figuring out what you mean?

Try to rewrite your code from scratch using exactly two spaces for each indentation.

Your code should look like this.
*fake_choice
..# Option One
....Flavour text one
..# Option Two
....Flavour text two

*fake_choice
..# Option Three
....Flavour text three
..# Option Four
....Flavour text four

You see how sticking to exactly two spaces per level is more consistent and readable? A computer can understand that just fine.

3 Likes

This used to be, and to some extent still is, a reason for debate in the Python community prior to the advent of Black.

Anyway, how many spaces make a good indentation. Each person will have a different opinion. Personally I prefer tabs. It’s clean and straightforward. One indentation level? One tab! That’s it.

If you’re using CSIDE make sure “Smart Indentation” is checked in the settings. That will near enough do this all for you.

But as mentioned above, I’d recommend starting from scratch, or running your scenes through a convertor.