Need help with solving the error "Expected choice body"

Hello everyone,

It’s been a while, and I am trying my hand at ChoiceScript to (hopefully) produce a piece of interactive fiction. Amidst my studying of the code in ChoiceScript, I have come across an error that I can’t seem to shake off.

I am receiving the error “Expected choice body”, and it is an error that I am getting from this code:

What was the name that the universe first assigned you?
*choice
    #This is your name...
        *label input_name
        That which could never be ripped from you.
        *input_text name

        This is your name? ${name}?
        *choice
            #"Yes."
             Remember, and do not forget it.
             *goto past

            #"I have misremembered. Allow me to try again..."
             *goto input_name

*label past
*page_break

I do not know how to solve this issue, and any help would be greatly appreciated!

EDIT: The error occurrs whenever I try to select the “Yes.” option, while everything else seems to be working fine…

In your pasted code, the indent is not showing, while in my quote it is. Checking to make sure the command is indented properly would be my first attempt to trouble-shoot the issue

I am sorry for not specifying, but the *goto input_name actually works just fine, it is when I choose the “Yes” option that I receive the error. I will edit the post to include this information.

1 Like

Same deal here. The *goto command is not indented properly in your pasted code.

1 Like

I have tried pasting the code as you have mentioned, and I received the error “startup line 80: increasing indent not allowed, expected 0 was 8”, with the line 80 referring to the “*choice”…

Yes, the line call out is sometimes a bit off with nesting involved. The error is pointing to improper spacing somewhere within the nesting, though.

I’m just throwing this out there to cover all the basics, but you are using uniform indents or spacing on all your choices, yes?

That is correct. Every line of code follows the same indention as the previous choices, unless I have multiple choices one after the other, in which case the consequent choice has more indentation. For this particular case, the indention is the same as previous choices in the code, such as selecting a gender, which I had no problems with.

I assume you grabbed the zip file from github? That should include a file called run-quicktest. If you haven’t, I would put your game files through the quicktest, and it should then return the exact line causing the issue, and what the issue is.

If I was going to take a stab at what’s wrong, I would guess you have a misalignment in your spacing, or a mix of tabs and manual spacing. I’ll paste an attempt to fix it below, but if it is a mixture of tabs/spaces, or a misalignment, it could be sourcing from somewhere above this.

What was the name that the universe first assigned you?
*choice
    #This is your name...
        *label input_name
        That which could never be ripped from you.
        *input_text name

        This is your name? ${name}?
        *choice
            #"Yes."
             Remember, and do not forget it.
             *goto past
            #"I have misremembered. Allow me to try again..."
             *goto input_name

*label past
*page_break

It’s also a bit odd to have a label nested inside your choice. It convolutes the code. Maybe try changing the operation there? I’m honestly not sure you need to do the nested choice here at all, and simplifying that might clean up the code enough to make it tick forward.

Something more like this:

What was the name that the universe first assigned you? That which could never be ripped from you.

*label input_name
*input_text name

This is your name? ${name}?
*choice
    #"Yes."
        Remember, and do not forget it.
        *goto past
    #"I have misremembered. Allow me to try again…"
        *goto input_name

*label past
*page_break

I haven’t tested that code, and using spaces instead of tabs gives me hives. But hopefully the idea is clear/makes sense.

2 Likes

Thank you! That seemed to have done the trick! I will also begin referring to the quick test function and try to keep labels out of choices, to less complicate the code.

Again, thank you very much!

1 Like

No problem. God knows how many times I’ve broken the code over the course of two games. You learn how to put it back together as a matter of necessity lol.

2 Likes

Not really, I do it all the time. :slight_smile:

I think the issue was an inconsistency in the number of spaces used in indents. You’re using four-space indents everywhere else, @Kirumototep , and then suddenly switch to a one-space indent deep in your choice block. ChoiceScript isn’t recognizing that one space as an attempt to indent – it’s just seeing it as a space – and so it’s telling you that it can’t find a “choice body” after #Yes, it’s just finding unindented text at the same level.

The key thing Raven did to fix your code wasn’t pulling the label out of the choice. It was putting the same four-space indent after #Yes that was used elsewhere in the code:

    #"Yes."
        Remember, and do not forget it.
        *goto past
    #"I have misremembered. Allow me to try again…"
        *goto input_name

If you don’t have consistent indentation – i.e. using either tabs or spaces (not both) and if spaces, using the same number of spaces every time – your code will keep throwing errors.

If you use consistent indents, you can use labels in choices all you like. :slight_smile:

4 Likes