Join Commands: *if and *selectable_if and *allow_reuse

Cool, heading in the right direction. Post it again please. And is it still the same error you mentioned previously?

Just a thought as well, if you’re deleting any lines from your actual script before posting it, I’d recommend not doing so. It’s hard to help if we can’t see the full picture.

I’ve noticed this section:


*choice
    *selectable_if (military_officer) 
        #MRE's and Canteen
            *goto start

Try doing as I said above with it. and about the choices that use no *if or *selectable_if’s, put them on the same line with the *selectable_if’s and the *if’s, not on the same line with the choices; do this:


*choice
    *selectable_if (military_officer) 
        #MRE's and Canteen
            *goto start
    #Choice2
        *goto start

Instead of this:


*choice
    *selectable_if (military_officer) 
        #MRE's and Canteen
            *goto start
        #Choice2
            *goto start

That’s the only thing I can spot wrong at a first view.

1 Like

Unless they’ve quite recently changed how CS handles *selectable_if, that will probably result in a parsing error.

1 Like

@Vendetta, Well, it works with the *if commands, and I never used the *selectable_if (mainly because of the errors encountered with it) so I don’t really know.

Anyways, why don’t you change the *selectable_ifs into *ifs, which would fix it? Just a suggestion…

Yep, you’re correct on that score–when used within a *choice statement the ordinary *if condition(s) should indeed be placed on their own line, followed on the next line (and indented again accordingly) by any ordinary #option, *hide_reuse or *selectable_if. This makes the *choice statement highly flexible, by allowing a variety of *if conditions to be pre-applied to any of the three types of options.

However, when *selectable_if is the only condition needed (as in this case), then it should simply be written as (and all on one line):

*selectable_if (military_officer) #MRE’s and Canteen

Concerning your last comment; it’s a fair question so I’ll answer in full for any future readers wondering the same thing!

He really doesn’t want to change his *selectable_ifs to ordinary *ifs in this case. Not only is it unnecessary to do so (he just needs to follow the example above), he has also chosen the correct option type for what he wants to achieve here, which is to “gray out” a *selectable option if the player does not qualify. By this means the player knows that when they play again and choose different options at an earlier stage, different options would then become available at this point (e.g. Military Officers get a canteen). He doesn’t want to hide the information in this case (which is what an ordinary *if would do) as it encourages replays to try those unselectable options.

1 Like

@Vendetta, I get it now. Well, in that case, *selectable_if shouldn’t have a problem when placed the way you said it should be placed…

To help explain what I meant in my previous post, I’ve knocked up the following example to demonstrate how the the different #options of a *choice statement should be laid out. Bear in mind that this is just a bit of nonsense as an example of the different things you can do, different ways you can use these elements together, and some things to bear in mind when doing so–such as the required indentation for each style, and where & when you need double parentheses, etc.

I’ve included the *temps so you can just copy & paste this into a current project and play around with it by changing the values, just to see what effect it has on the options displayed.


*temp shadowwalk
*set shadowwalk 30
*temp infravision
*set infravision 30
*temp lit_torch_held
*set lit_torch_held false
*temp agility
*set agility 50

*label throne_room
*choice
    #Cross the throne room and exit through the doorway at the far side
        *if shadowwalk > 20
            You tip-toe across the throne room and head into a damp passageway.
            *goto damp_passage
        *else
            You clumsily trip over the dragon's tail and promptly get eaten.
            *ending
    *if (shadowwalk > 30) and ((infravision > 30) or (lit_torch_held = true))
        *hide_reuse #Search every nook and cranny of the throne room.
            You search every nook and cranny . . . pointlessly.
            *goto throne_room
    *if (shadowwalk < 31) and ((infravision < 31) and (lit_torch_held = false))
        #Search the throne room, avoiding the sleeping dragon.
            You trip over the dragon's tail. She awakens and gobbles you up . . . Burp!
            *ending
    *selectable_if ((agility > 50) and (shadowwalk < 31)) #Leap for the balcony.
        You reach the balcony, grab the treasure, and leave via an open window.
        *goto castle_grounds
    *if shadowwalk > 30
        *selectable_if (agility < 50) #Quietly leap up to the crumbling balcony
            You fail to reach the balcony but land softly, without awakening the dragon.
            *goto throne_room
    *hide_reuse #Dance a jig around the sleeping dragon . . . quietly!
        You (somewhat pointlessly) dance a silent jig around the dragon. Zzzzzzz.
        *goto throne_room
    #Hack the head off the slumbering dragon.
        Nice try . . . You succeed only in annoying her. Charred adventurer! Yummy!
        *ending

*label damp_passage
Damp passageway blah blah blah
*ending

*label castle_grounds
Castle grounds blah blah blah
*ending

1 Like

One thing, if you are using the above as an inventory, you need to change the item variable to true in each block.


\*selectable_if (police_officer) #riot gear(15 lbs)
  \*set riot_gear true
  \*goto start
\*selectable_if (camping_and_hiking) #rope(5 lbs)
  \*set rope true
  \*goto start 

etc.

@Cristoph, I’ve tested your code, and it works just fine with the following edits:

  1. all referenced variables are created and given initial values.
  2. all *selectable_if’s and #SelectableOptions are placed on the same line.
  3. millitary_officer is changed to military_officer

My version of firefox errors out with “Couldn’t parse the line after *selectable_if: (var_name)” where var name is something like “military_officer” whenever *selectable_if and #SelectableOptions are on separate lines. That’s the only serious issue I noticed.

Of course to really make it useful you’ll have to set item variables to true as @JimD has mentioned, and add some additional logic that will exit the loop once you equip 6 items. Currently it doesn’t end until the player selects “Done”.

1 Like

Neat. I was looking up a problem I was having and found my own thread. :slight_smile:

Here’s my trouble. Combining the *if with *hide_reuse or *allow_reuse works just fine:


*choice
     *if (whatever=1)
          *allow_reuse #Pick this option
               Blah blah

But, *selectable_if doesn’t. This gives an error:


*choice
     *selectable_if (whatever=1)
          *allow_reuse #Pick this option
               Blah blah

Is this true, that *selectable_if doesn’t work with *hide_reuse or *allow_reuse?

I generalized this from memory. If this isn’t the case, let me know and I’ll dig up the exact sequence that didn’t work.

Thanks!

Have you tried putting the *allow_reuse first?


*choice
  *allow_reuse
    *selectable_if (whatever=1) #Pick this option
      Blah, blah...

That would make sense to me, but I haven’t tried it.

I tried it, doesn’t work.



*choice
	*selectable_if (variable>4)
		*allow_reuse #This work?
			Hope so.
			*goto Start

This gives me a:
Error: line 58: Couldn’t parse the line after *selectable_if: {variable>4)


This also gives the same error:


*choice
     *allow_reuse
	     *selectable_if (variable>4) #This work?
		     Hope so.
		     *goto Start


And yet, this works:


*choice
	*if (charm>4)
		*allow_reuse #This work?
			Hope so.
			*goto Start


But this way doesn’t, giving Error: line 58: Expected option starting with #


*choice
	*allow_reuse
		*if (variable>4) #This work?
			Hope so.
			*goto Start

I’m fairly sure selectable_if will only work inline, so you’d want something like this:


*choice
  #Option 1
  *allow_reuse *selectable_if (condition) #Option 2

I’m pretty sure that (or the other way around) works, but can’t check it right at now as I’m on my phone.

2 Likes

Wow, I wouldn’t have expected that. This one works on the quicktest. Thanks!


*choice
	*allow_reuse *selectable_if (charm>4) #This work?
		Hope so.
		*goto Start

@Lucid
Awesome, glad to hear it.
Memo to self: Make a note of this on the wiki :stuck_out_tongue:

I wonder why this wouldn’t follow the same style as all the others, using its own indent? Seems like a needlessly confusing quirk.

I also wonder why the order matters for all of these indentable commands? (Although I suspect that it’s just easier to code it that way)

Either way, I’m happy. I can do what I want now. :slight_smile:

I actually always tend to use commands like *if, *allow_reuse and the like inline, I personally think it’s confusing/untidy to add extra (unnecessary?) levels of indentation - but it’s all just a matter of personal preference.

I think the reason *selectable_if only works inline is because that you can only ever use that command on a *choice option (whereas even allow_reuse and hide_reuse can be used standalone), and this makes it harder to use it in the wrong context? I couldn’t say for certain though.

Yes, inline makes sense, since it all works at once giving one block of result.

It happened again! :slight_smile:

Aug 2012 was when I had this problem the first time, and wow, I was making some simple errors back then. It happened again in June 2014, although a lot more complicated. And now, 8 years since the first time, I ran into the problem yet again… and again, I found my own thread!

I edited the first post so when I need to fix this problem again in 2025, I won’t have to read through all of these responses. :smiley:

This is the correct order, in case you’re curious:

*if (this_thing)
	*allow_reuse *selectable_if (that_thing) #Choose something.
		The choice occurs.
		*goto the_next_part
3 Likes

Yes, that’s exactly right. When you have multiple conditions on options like this, CS requires the *if on its own line, the toggle flag first on the #option line, and the *selectable_if in the middle, immediately before the #option text.