How to use selectable_if on numerical variables?


Here’s the details,

At mygame.js, I have a variable “Weapon” with numerical value. As this:

weapon: 0

Then on my choicescript_stats, I turn these numbers into text. As this:

*temp weapon_text
*if weapon = 0
*set weapon_text “None”
*goto wchart
*elseif weapon = 10
*set weapon_text “Normal Spear”
*goto wchart
*elseif weapon = 20
*set weapon_text “Good Spear”
*goto wchart
*set weapon_text “Best Spear”
*label wchart

The thing is that I wanted to use the selectable_if code to create a selectable option if the player has a “Good Spear”

Here’s what I tried, but didn’t work.

What is your spear?
#I don’t have one.
I am too poor to get a spear
*selectable_if (weapon) = 20 #I have a good spear. //This breaks!
A good spear is more than enough.

The above code breaks. I tried also:

*selectable_if (weapon = 20) #I have a good spear. //This breaks!

*selectable_if (weapon)=20 #I have a good spear. //This breaks!

*selectable_if (weapon=20) #I have a good spear. //This breaks!

The end objective to is make the choice unselectable, unless the player has a “Good Spear”, which is weapon=20.

Any advice?


From my experience, selectable_if only works for true or false (I couldn’t get it to work, anyway).

Instead, what you can do is make a temp variable for the spear like this:

*temp good_spear *if weapon=20 *set good_spear true What is your spear? *choice #I don't have one. I am too poor to get a spear *finish *selectable_if (good_spear) #I have a good spear. A good spear is more than enough. *finish


Try this (sorry I’m trying to type this on my phone)

What is your spear?

*if (weapon = 1) #i have a good spear

I don’t think you need the selectable_if statement just a simple if should work I hope this is what you were looking for


Rob, while a simple if statement will present the option if you have the spear, if you don’t then you won’t know that the option exists (won’t see it at all).
With selectable_if, if you don’t have the spear, you will still see the option, you just won’t be able to select it.

This can be used to show the reader that had they done things differently earlier in the game, then they could have taken this path. It increases replayability.


Here is working code from my game:

*selectable_if (strength > 19) #Carry the soldier up the stairs

I notice that you have to play around a bit with spaces between the condition and the # or sometimes carry it to a new line:
*selectable_if (strength > 19) #Carry the soldier up the stairs

Indents should be the same as you use for any other formatting. I use two spaces throughout my game so I use 2 spaces before the #.


@zenfero First, can you say why it’s breaking? (Use Internet Explorer to get the full and proper error, then copy and paste it.) It may be some other small error that’s causing it. The first alternate option:
(*selectable_if (weapon = 20) #I have a good spear.)
should work fine. As JimD said, you may also carry the choice to a new line (Indented).


@JimD, @Reaperoa, What version of choicescript are you using?

It’s a long time since I tried but I couldn’t get *selectable_if to work for anything but true/false variables. (I’m pretty sure, but not certain, that I wrote the code as JimD did).

I downloaded the latest version for Blackraven… I’ll have to try this again to see if it works.


@andymwhy I used a version from a year ago. I had trouble with making it work but as I played with indents and breaking the code into two lines, I got it working.


Nice! I learned something new today thanks for clarifying andy


I did manage to use selectable if for something other that true/false
First I tried using a timer and did selectable if ticker >3 and that worked, then i switched to this:


*label looking
Alright, now you take a look around you. You are facing inland and the beach extends to your left and right as far as you can see.
There are tall palm trees on the beach up until the sands edge. A giant jungle looking area filled with palm fronds and other plants
extends in front of you. Behind you is the ocean.
*label pick2
What is your next course of action?
*hide_reuse#I need to find shelter.
*goto shelter
*hide_reuse#I need to get something to eat.
*goto food
*hide_reuse#I need to find some fresh water.
*goto water
#I don’t feel like doing anything right now.
*goto lazy
*selectable_if ((shelter != “unknown”) and ((findf = “true”) and (river = “gentle”))) #I will explore the island.
*goto go

*label go

It’s pretty much to make sure the player can’t move on until they have competed 3 tasks.
I also had trouble with the ( ) for a while but eventually figured out the formatting because it’s tricky if you have more than one.


Yep, you have to group every two conditions in parentheses. Little known trick :slight_smile:


I learned a lot from this thread. Good work all around! :slight_smile:


I have to second that emotion–thanks indeed, very useful stuff. :slight_smile:


Hi thanks all, but still have problems. Tried Andy’s method. Here’s my code.

*temp good_spear
*if weapon = 10
*set good_spear true *comment: 2 spaces here

#I have no spear. *comment: 2 spaces here

Too bad.                 \*comment: 4 spaces here

*selectable_if (good_spear) #I have good spear

*comment: 2 spaces with 1 space between the selectable and choice

 Great!                                                               \*comment: 4 spaces here

The strange thing is that autotest tells me that the code is passed the test.

But when I tried to see it on firefox, there is an error.

I also notice that for the line

*fake_choice and


the autotest result is 2, instead of the usual 1s and 0s.

I hope I explained clear enough. Any advice?


The code and spacing looks okay. It could be a problem with using a fake_choice with selectable_if. Generally a fake_choice has no impact on the outcome so maybe adding a condition (selectable_if) isn’t catered for.


May not be required in the coding but try writing:
*set good_spear “true”

And then write:
*selectable_if (good_spear = “true”)

Finally like andy said make it a real choice not a fake one.


That’s a good point monkey, but the wrong way around.
After creating the temp variable:
*temp good_spear

You should give it a value
*set good_spear false
Then have the if statement.

So it would be like this:

*temp good_spear *set good_spear false *if weapon = 10 *set good_spear true

Otherwise if you don’t have the good spear, it will give an undefined error message.


Oops I don’t think I was clear. Sorry. What I was pointing out was to put the true/false in quotation marks. For some reason my computer seemed to like that better.


If you wrap quotes around true false, it changes the expression to alphanumeric from boolean. I doubt *if (good_spear) will work then since good_spear is no longer boolean.

I realize it will still work if you say *if good_spear = “false” because it is matching exact text but that may cause headaches later for complex statements.


@JimD Actually, you need to decide on having a stat be either alphanumeric or a boolean. Mixing and matching can cause the game to crash. (At the very least I know that *if (variable) will cause a crash if {variable} is not a boolean.)

Essentially, while “2” = 2, “true” != true.