Problem with *choice statement

So, I’m working on a game. When I ran it via browser, it was jumping unexpectedly after a choice to the end of the game (the page with restart button, etc.)

I downloaded CSIDE and put my code into it. I ran it and saw the same problem. I then stepped through it and saw that no matter which #choice I picked, it jumped to the end page when I reached the *finish statement for that choice. I never get to the “I should see this text” line. Here is my code (note, there is a *create gender “none” statement in the setup file):

*comment set gender
*choice
    #Hello, son
        *set gender "male"
        *finish
    #Hello, daughter
        *set gender "female"
        *finish
    #Hello, my child (use "they" pronouns)
        *set gender "nonbinary"
        *finish

I should see this text
...

No wonder! The purpose of the *finish command is to move the game to the next scene, so if there is none, it’ll just end the game. What you’re looking for instead is a *goto. Place a *label before the “I should see this text” line and then have your choices end in *goto [label name]. Or, if all the options are meant to lead to the same place, just use a *fake_choice instead.

4 Likes

So, each choice that doesn’t move to a new scene or jump around should have a goto to a label immediately following the choice statement? I thought *finish meant “*finish the choice”. The example in the tutorial is not clear about that. Thanks!

That’s right (except, apparently, for the last choice option, you can skip the goto for that one?). See this example by the Choicescript devs:

*choice
    #Be very naughty.
        Santa refuses to give you a present.
        *goto present    
    #Be mostly nice.
        Santa gives you a present reluctantly.
        *goto present
    #Be as nice as can be.
        Santa gives you a present enthusiastically.

*label present
Inside the gift box is a video game!

That example, incidentally, is from a page on implicit control flow. If you activate it, you can skip the label and the goto for every choice option that doesn’t jump around or finish.

2 Likes

You might as well use a fake_choice instead if all the choices lead to the same outcome afterwards.

*comment set gender
*fake_choice
    #Hello, son
        *set gender "male"
    #Hello, daughter
        *set gender "female"
    #Hello, my child (use "they" pronouns)
        *set gender "nonbinary"

I should see this text

A fake_choice does not need a *goto command to end. It just executes the *set commands, displays the text, then continues with whatever comes directly after the *fake_choice in the scene you are in.

If you want a *choice tree to lead to different labels, then you use *choice. If every choice continues with the same text following the choice, you can use a *fake_choice instead.

1 Like

Implicit control flow allows you to skip using *goto on every single *choice and you will never need to use *fake_choice. Please don’t use *fake_choice if you’re using ICF, it’s completely redundant.

2 Likes

I thought the fake_choice only allows text for each choice – no commands like *set allowed.

Sure it does allow. I use it a lot myself, matter of fact i almost constantly use FC instead of C.

Look.

image

:man_shrugging:

Interesting. So the online tutorial is wrong, because it says:

*fake_choice : This convenience command behaves exactly like *choice , but no commands are allowed in the body of the choice; thus no *goto / *finish is required.

What color do you prefer?

  *fake_choice`
    #Red
      Red is the color of roses.
    #Blue
      Blue is the color of the sea.
    #Green
      Green is the color of spring.

Might just be a CSIDE feature that allows *fake_choice to have commands inside. I’ve always utilized it.

No, it’s not CSIDE. Before it was not possible to use fake_choice for some stuff, but its since been updated, that tutorial is simply old and not taken the updated changes into account.

You can do whatever you want inside fake_choice.

1 Like

Okay, then I guess I should ask – where is the best reference for ChoiceScript? This is not the first error in the online tutorial that has caused me problems.

Which one are you following? I guess the wiki would be the most updated.

Most, if not all, the tutorials are outdated. Your best resource is simply the wiki.

1 Like