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?
*choice #I don’t have one.
I am too poor to get a spear
*finish
*selectable_if (weapon) = 20 #I have a good spear. //This breaks!
A good spear is more than enough.
*finish
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.
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
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.
*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.
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?
*choice
*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
*finish
`
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.
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.
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.)