Join Commands: *if and *selectable_if and *allow_reuse

Or: *hide_reuse and *if

Also, does *if have to use a *goto ?

For example,

*if (Raining)
     It's raining!

Instead of:

*if (Raining)
    It's raining!
    *goto nextpart

*label nextpart

Edit from March, 2020. This is the correct format:

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

you can use *commands if on separate lines

*if (holding_pistol)
*hide_reuse #Shoot him in the face

*if does not have to use a *goto if you just want to include some conditional phrase or check.

Thanks, that’s handy.

I guess my *if problem happened when I followed up with an *else

Eg)
*If (raining)
It’s raining.
*else
It’s not raining.

That fell out of the if and into an else, giving me an error.

@Lucid - yep, that’ll do it.

ran into a little trouble with this section, I am creating inventory as follows and getting error must have *goto or *finish maybe missing something here but I believe I have that…

ie:
Not knowing how long the virus will last, nor what is really happening outside what will you take? (you can only take 6 items

choose carefully)
*hide_reuse
*label start
*choice
#food and water(10 lbs)
*goto start
*selectable_if (military_officer)
#MRE’s and Canteen
*goto start
#Flashlight(4 lbs)
*goto start
*selectable_if (paramedic)
#Emergancy Kit(7 lbs)
*goto start
#fire starters(2 lbs)
*goto start
*selectable_if (camping_and_hiking)
#Survival back packs and gear(20 lbs)
*goto start
*selectable_if (police_officer)
#riot gear(15 lbs)
*goto start
*selectable_if (camping_and_hiking)
#rope(5 lbs)
*goto start
*selectable_if (hunting)
#hunting knife(7 lbs)
*goto start
#M9 Pistol(6 lbs)
*goto start
*selectable_if (millitary_officer)
#M16 rifle(8 lbs)
*goto start
#Winchester 800 shotgun(8 lbs)
*goto start
#extra ammunition(15 lbs)
*goto start
#night vision goggles(3 lbs)
*goto start
#small first-aid kit(3 lbs)
*goto start
#rain gear(3 lbs)
*goto start
#emergancy radio(5 lbs)
*goto start
#extra batteries(2 lbs)
*goto start
#multi-purpose tool(2 lbs)
*goto start
*selectable_if (gardening)
#garden supplies to grow food(12 lbs)
*goto start
#two way radios(6 lbs)
*goto start
*selectable_if (woodworking)
#building supplies(20 lbs)
*goto start
#emergancy small generator(15 lbs)
*goto start
#Done
*finish

It might have something to do with that *hide_reuse near the beginning, which is intended to be used within a *choice list in much the same way as *selectable_if, e.g.

*hide_reuse #Food and water (10lbs)

Unless of course you do want all the #options to be *hide_reuse, in which case you do want to leave that as it is.

Note also that *selectable_if should itself generally be used as follows (i.e. not a separate line):

*selectable_if (military_officer) #MREs and Canteen

I do want it to be all choices hide_reuse, but as for the selectable_if I have tried on the same line and still getting the error

Hmm. Best would be to post your code again but put < pre> before it and < /pre> after it (without those spaces), which will retain the indentation in the forum. It should then be much easier to spot what’s causing the problem.


Not knowing how long the virus will last, nor what is really happening outside what will you take? (you can only take 6 items choose carefully)
\*hide_reuse
\*label start
\*choice
  #food and water(10 lbs)
    \*goto start
  \*selectable_if (military_officer) 
  #MRE's and Canteen
    \*goto start
  #Flashlight(4 lbs)
    \*goto start
  \*selectable_if (paramedic) 
  #Emergancy Kit(7 lbs)
    \*goto start
  #fire starters(2 lbs)
    \*goto start
  \*selectable_if (camping_and_hiking) 
  #Survival back packs and gear(20 lbs)
    \*goto start
  \*selectable_if (police_officer) 
  #riot gear(15 lbs)
    \*goto start
  \*selectable_if (camping_and_hiking) 
  #rope(5 lbs)
    \*goto start
  \*selectable_if (hunting) 
  #hunting knife(7 lbs) 
    \*goto start
  #M9 Pistol(6 lbs)
    \*goto start
  \*selectable_if (millitary_officer) 
  #M16 rifle(8 lbs)
    \*goto start
  #Winchester 800 shotgun(8 lbs)
    \*goto start
  #extra ammunition(15 lbs)
    \*goto start
  #night vision goggles(3 lbs)
    \*goto start
  #small first-aid kit(3 lbs)
    \*goto start
  #rain gear(3 lbs)
    \*goto start
  #emergancy radio(5 lbs)
    \*goto start
  #extra batteries(2 lbs)
    \*goto start
  #multi-purpose tool(2 lbs)
    \*goto start
  \*selectable_if (gardening) 
  #garden supplies to grow food(12 lbs)
    \*goto start
  #two way radios(6 lbs)
    \*goto start
  \*selectable_if (woodworking) 
  #building supplies(20 lbs)
    \*goto start
  #emergancy small generator(15 lbs)
    \*goto start
  #Done
    \*finish
< /pre>

Can’t spot anything there other than the fact that those #options using *selectable_if are not on the same line. You should correct those, if only because it makes bug-hunting something like this easier (i.e. easier to make sure you have all the *gotos in the right place).

There’s also an instance where you spell “millitary_officer” like so, and another case where you spell it correctly with a single L. One of those must be different to the spelling used in mygame.js so will need correcting.

I have actually added them all on the same line after posting it here but I still get the error

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