Exploration choice loops

I just wondered what the best way of doing a looped choice where the options are reduced each time is? Particularly where you have, say, 3 places to explore, so you explore place A , but then it returns you to the same choice MINUS choice A until all the choices are exhausted?

1 Like

Get it!

I adivice you into use the choicescript “*hide_reuse” feature.

Ceate a temp variable for the numer of repetitions you code will do (for example 3 places to explore) and an increment for each choice you player pick, so, after all the (3) places were explored the loop will end and the game will go on.

1 Like
*label gosomewhere Where would you like to go now? *fake_choice .*disable_reuse ..#location 1 ...*gosub location1 .*disable_reuse ..#location 2 ...*gosub location2 .*disable_reuse ..#location 3 ...*gosub location3 *goto gosomewhere

Sorry my phone is refusing to cooperate. Periods are used in place of spaces/tabs.

4 Likes

uh… How do you end the loop without a counter?

@Nahim
I haven’t been home so I can’t test it. I thought fake choices end when all choices are disabled. If you do this does it work or does an error pop up?

A simple loop could go like this:

*temp counter 0
*label runningerrands
*choice
    *hide_reuse #I want to go to the library.
        *set counter +1
        You check out ten books and shove them into your bag. Ouf, heavy!
        *if counter <3
            *goto runningerrands
        *else
            *goto outoftime
    *hide_reuse #I'll stop by the bakery for some bread.
        *set counter +1
        You buy a loaf of raisin-sunflower-pumpernickel, fresh out of the oven. Delicious!
        *if counter <3
            *goto runningerrands
        *else
            *goto outoftime
    *hide_reuse #I should put my mail in the post.
        *set counter +1
        You drop off the three letters in the mail slot. The postal worker waves hello.
        *if counter <3
            *goto runningerrands
        *else
            *goto outoftime
    *hide_reuse #I'm going to watch the cardinals in the park.
        *set counter +1
        The birds are happy to see you, as always.
        *if counter <3
            *goto runningerrands
        *else
            *goto outoftime
*label outoftime
*line_break
*line_break
You need to be moving along now, or you'll be late for your appointment! The rest of your errands will have to wait till later.

Is that at all what you had in mind?

4 Likes

An error pop up after i pick the three choices:

line 3: No selectable options

1 Like

If you have fake_choice instead of choice you could have all the lines that start with *else *if and *goto after the fake_choice. Also why would you have two line_breaks? It makes it look like you are trying to boost your word count.

@Nahim looks like you would have to follow @Fiogan’s way then.

I try to use *choice whenever possible (I believe that’s recommended by CoG in one of the blog posts, as well?) because it’s less likely to cause continuity errors, since you always MUST send every option to somewhere specific.

Also *choice doesn’t have potential problems if you need to nest within a loop, but *fake_choice sometimes does.

@Kelvin: Er, I’m not exactly sure what your meaning is with the ‘trying to boost your word count’ portion.

I always use *line_break when I want to make sure I have a paragraph break but there’s something besides text (meaning, code lines) around the required paragraph break. That way it’s easier for me to tell, at a glance, where my paragraph breaks are.

I had noticed, especially in complex scenes, that sometimes I would think a blank line meant I’d have a paragraph break, but because of the way I did the coding (whether it was when I using *if, or *goto, or *fake_choice, or whatever else) the paragraph didn’t always end up where I wanted it to be.

So I use blank lines for paragraph breaks in the middle of my text blocks, but I always use *line_break when code is directly on either side. Does that answer what you were asking?

And one *line_break doesn’t add an empty line, it just moves the text one line down, so it’s no good for paragraph breaks.

@Fiogan it seems like we are getting off topic, which is probably my fault. I always seem to get off topic. If you want to keep talking about this though I would be happy to pm you.

1 Like

All right! I thought, since it was a coding-related issue, explaining my reasoning for using *choice and *line_break might be helpful. Apologies if it was off-topic or otherwise irrelevant.

1 Like

We prefer that you not use two *line_breaks in a row.

Instead, you should use *comment endif to assert the existence of blank lines.

Look at published Choice of Games’ code to see its use.

4 Likes

Thanks! That’s very helpful to know.

As another writer whose WiP is littered with double *line_breaks… why the preference?

4 Likes

Doesn’t just hitting return twice in the midst of text give you a blank line without actually coding a line_break? The way I grokked it, hard line breaks are when you don’t want an double-line paragraph break as in single-spaced stanzas in a poem.

Yes. I had been using the double *line_break for places where several threads of code converged, not in the midst of text blocks, mostly so I could tell for sure what ‘level’ the paragraph break would be.

Not reliably at the end of a conditional text block.

The paragraph came to an end.
*if not(over_yet)
  After a few more words.

And a new paragraph began.

will render as a single para if over_yet is true.

In cases where you want the paragraph to end regardless of a conditional block – which in my game happens dozens of times – you need some way of hard-coding the para break.

1 Like

Does it do that if you align the tab of the second line under the first?

You mean, as in the example I just posted? (Where the 2nd line starts “*if not…”, and is aligned with the 1st, starting “The paragraph…”?) Yes, it renders as a single paragraph.

That’s actually a great example. The traditional way of fixing this is just with a different hack, but one that preserves the blank line.

The paragraph came to an end.
*if not(over_yet)
  After a few more words.
*comment endif

And a new paragraph began.

The *comment asserts the level of indentation of the following blank line.

That said, six or more months ago, Dan took a crack at this, and in theory, if you download the latest version of ChoiceScript from GitHub, my hack isn’t necessary anymore. But I still prefer my hack, because it tells a code-reader what the author’s intention is. (Also, I have the suspicion that Dan’s “fix” might introduce a different set of problems, but I haven’t demonstrated that yet.)

3 Likes