Choice Scripting and Clean Coding

I can vaguely recall reading that in certain situations *choice would work correctly while *fake_choice would throw an error, though I’ve never run into those situations myself and can’t remember the details I read.

I do know one use of *choice where *fake_choice can’t stand in — putting multiple semi-independent choices on a single page, so the player can select all of them at once. For example, choosing your MC’s hair color, hair length, and hair style. I believe @Fiogan is using one in The Beastie Watch to set the MC’s philosophy and outlook on life. The code itself is a little complicated, and ends up looking something like this:

*choice color shape
  #red
    #square
      *goto next
    #circle
      *goto next
  #blue
    #square
      *goto next
    #circle
      *goto next

When run, this will appear to produce two separate choices. Before the first, it will say *"Select a (first word following choice, “color” in this example)," then it will display a choice between red and blue. Before the second, it will say *"Select a (second word following choice, in this case “shape”)," then it will display a choice between square and circle.

There are a lot of tricks to making it function — those words that follow *choice are mandatory, and you can only use one word per tier of choices. Every deeper tier of #options must be completely and exactly copied under each higher-tier #option. Variables you *set must only be set under the final tier of #options, right above your *goto commands. There are probably some other tricks I’m forgetting at the moment.

It gets messy. It gets messy frighteningly quickly.

I suspect it’s close to the exact opposite of clean coding.

As an example, several months ago I wrote, purely for practice, a three-tier *choice for choosing a character’s hair length, color, and texture all on the same page. It worked! And from a play perspective was beautifully simple. And it could only be done with *choice, not *fake_choice.

But with six hair lengths (bald, very short, etc,) five colors (blonde, red, etc,) four textures (straight, wavy, etc,) and a variable for each thing to be chosen, the whole abomination ended up as nearly 640 lines of code.

If you really want to see that mess I wrote to style an MC's hair, it looks like this...
*choice length color texture
  #bald
    #blonde
      #straight
        *set hair_length "bald"
        *set hair_color "blonde"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "bald"
        *set hair_color "blonde"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "bald"
        *set hair_color "blonde"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "bald"
        *set hair_color "blonde"
        *set hair_texture "kinky"
        *goto eyes
    #red
      #straight
        *set hair_length "bald"
        *set hair_color "red"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "bald"
        *set hair_color "red"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "bald"
        *set hair_color "red"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "bald"
        *set hair_color "red"
        *set hair_texture "kinky"
        *goto eyes
    #auburn
      #straight
        *set hair_length "bald"
        *set hair_color "auburn"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "bald"
        *set hair_color "auburn"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "bald"
        *set hair_color "auburn"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "bald"
        *set hair_color "auburn"
        *set hair_texture "kinky"
        *goto eyes
    #brown
      #straight
        *set hair_length "bald"
        *set hair_color "brown"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "bald"
        *set hair_color "brown"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "bald"
        *set hair_color "brown"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "bald"
        *set hair_color "brown"
        *set hair_texture "kinky"
        *goto eyes
    #black
      #straight
        *set hair_length "bald"
        *set hair_color "black"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "bald"
        *set hair_color "black"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "bald"
        *set hair_color "black"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "bald"
        *set hair_color "black"
        *set hair_texture "kinky"
        *goto eyes
  #very short
    #blonde
      #straight
        *set hair_length "very short"
        *set hair_color "blonde"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *goto eyes
        *set hair_length "very short"
        *set hair_color "blonde"
        *set hair_texture "wavy"
      #curly
        *set hair_length "very short"
        *set hair_color "blonde"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very short"
        *set hair_color "blonde"
        *set hair_texture "kinky"
        *goto eyes
    #red
      #straight
        *set hair_length "very short"
        *set hair_color "red"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very short"
        *set hair_color "red"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very short"
        *set hair_color "red"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very short"
        *set hair_color "red"
        *set hair_texture "kinky"
        *goto eyes
    #auburn
      #straight
        *set hair_length "very short"
        *set hair_color "auburn"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very short"
        *set hair_color "auburn"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very short"
        *set hair_color "auburn"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very short"
        *set hair_color "auburn"
        *set hair_texture "kinky"
        *goto eyes
    #brown
      #straight
        *set hair_length "very short"
        *set hair_color "brown"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very short"
        *set hair_color "brown"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very short"
        *set hair_color "brown"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very short"
        *set hair_color "brown"
        *set hair_texture "kinky"
        *goto eyes
    #black
      #straight
        *set hair_length "very short"
        *set hair_color "black"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very short"
        *set hair_color "black"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very short"
        *set hair_color "black"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very short"
        *set hair_color "black"
        *set hair_texture "kinky"
        *goto eyes
  #short
    #blonde
      #straight
        *set hair_length "short"
        *set hair_color "blonde"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "short"
        *set hair_color "blonde"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "short"
        *set hair_color "blonde"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "short"
        *set hair_color "blonde"
        *set hair_texture "kinky"
        *goto eyes
    #red
      #straight
        *set hair_length "short"
        *set hair_color "red"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "short"
        *set hair_color "red"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "short"
        *set hair_color "red"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "short"
        *set hair_color "red"
        *set hair_texture "kinky"
        *goto eyes
    #auburn
      #straight
        *set hair_length "short"
        *set hair_color "auburn"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "short"
        *set hair_color "auburn"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "short"
        *set hair_color "auburn"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "short"
        *set hair_color "auburn"
        *set hair_texture "kinky"
        *goto eyes
    #brown
      #straight
        *set hair_length "short"
        *set hair_color "brown"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "short"
        *set hair_color "brown"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "short"
        *set hair_color "brown"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "short"
        *set hair_color "brown"
        *set hair_texture "kinky"
        *goto eyes
    #black
      #straight
        *set hair_length "short"
        *set hair_color "black"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "short"
        *set hair_color "black"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "short"
        *set hair_color "black"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "short"
        *set hair_color "black"
        *set hair_texture "kinky"
        *goto eyes
  #medium
    #blonde
      #straight
        *set hair_length "medium"
        *set hair_color "blonde"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "medium"
        *set hair_color "blonde"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "medium"
        *set hair_color "blonde"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "medium"
        *set hair_color "blonde"
        *set hair_texture "kinky"
        *goto eyes
    #red
      #straight
        *set hair_length "medium"
        *set hair_color "red"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "medium"
        *set hair_color "red"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "medium"
        *set hair_color "red"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "medium"
        *set hair_color "red"
        *set hair_texture "kinky"
        *goto eyes
    #auburn
      #straight
        *set hair_length "medium"
        *set hair_color "auburn"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "medium"
        *set hair_color "auburn"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "medium"
        *set hair_color "auburn"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "medium"
        *set hair_color "auburn"
        *set hair_texture "kinky"
        *goto eyes
    #brown
      #straight
        *set hair_length "medium"
        *set hair_color "brown"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "medium"
        *set hair_color "brown"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "medium"
        *set hair_color "brown"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "medium"
        *set hair_color "brown"
        *set hair_texture "kinky"
        *goto eyes
    #black
      #straight
        *set hair_length "medium"
        *set hair_color "black"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "medium"
        *set hair_color "black"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "medium"
        *set hair_color "black"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "medium"
        *set hair_color "black"
        *set hair_texture "kinky"
        *goto eyes
  #long
    #blonde
      #straight
        *set hair_length "long"
        *set hair_color "blonde"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "long"
        *set hair_color "blonde"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "long"
        *set hair_color "blonde"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "long"
        *set hair_color "blonde"
        *set hair_texture "kinky"
        *goto eyes
    #red
      #straight
        *set hair_length "long"
        *set hair_color "red"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "long"
        *set hair_color "red"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "long"
        *set hair_color "red"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "long"
        *set hair_color "red"
        *set hair_texture "kinky"
        *goto eyes
    #auburn
      #straight
        *set hair_length "long"
        *set hair_color "auburn"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "long"
        *set hair_color "auburn"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "long"
        *set hair_color "auburn"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "long"
        *set hair_color "auburn"
        *set hair_texture "kinky"
        *goto eyes
    #brown
      #straight
        *set hair_length "long"
        *set hair_color "brown"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "long"
        *set hair_color "brown"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "long"
        *set hair_color "brown"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "long"
        *set hair_color "brown"
        *set hair_texture "kinky"
        *goto eyes
    #black
      #straight
        *set hair_length "long"
        *set hair_color "black"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "long"
        *set hair_color "black"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "long"
        *set hair_color "black"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "long"
        *set hair_color "black"
        *set hair_texture "kinky"
        *goto eyes
  #very long
    #blonde
      #straight
        *set hair_length "very long"
        *set hair_color "blonde"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very long"
        *set hair_color "blonde"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very long"
        *set hair_color "blonde"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very long"
        *set hair_color "blonde"
        *set hair_texture "kinky"
        *goto eyes
    #red
      #straight
        *set hair_length "very long"
        *set hair_color "red"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very long"
        *set hair_color "red"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very long"
        *set hair_color "red"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very long"
        *set hair_color "red"
        *set hair_texture "kinky"
        *goto eyes
    #auburn
      #straight
        *set hair_length "very long"
        *set hair_color "auburn"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very long"
        *set hair_color "auburn"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very long"
        *set hair_color "auburn"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very long"
        *set hair_color "auburn"
        *set hair_texture "kinky"
        *goto eyes
    #brown
      #straight
        *set hair_length "very long"
        *set hair_color "brown"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very long"
        *set hair_color "brown"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very long"
        *set hair_color "brown"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very long"
        *set hair_color "brown"
        *set hair_texture "kinky"
        *goto eyes
    #black
      #straight
        *set hair_length "very long"
        *set hair_color "black"
        *set hair_texture "straight"
        *goto eyes
      #wavy
        *set hair_length "very long"
        *set hair_color "black"
        *set hair_texture "wavy"
        *goto eyes
      #curly
        *set hair_length "very long"
        *set hair_color "black"
        *set hair_texture "curly"
        *goto eyes
      #kinky
        *set hair_length "very long"
        *set hair_color "black"
        *set hair_texture "kinky"
        *goto eyes

Edit on 04 Dec. 2016:
I should have included a screenshot of how that hair-selection code looks when implemented. Omitting that was a mistake.

Here's a correction for that mistake.

Also, probably I should have linked to The Beastie Watch’s discussion topic, rather than directly to the game itself. That should be corrected as well now.

2 Likes