I’m having trouble with if command when it comes to choices
my code looks like this, it works on male but when I chose the female gender option it says expected at least one line in ‘if’ true block
*if (gender = “male”)
*choice
#Sebastion
*set name “Sebastion”
*goto_scene lastname
#Matt
*set name “Matthew”
*goto_scene lastname
#Andrew
*set name “Andrew”
*goto_scene lastname
#David
*set name “David”
*goto_scene lastname
#Takeru
*set name “Takeru”
*goto_scene lastname
#None of these names
*goto_scene firstnames
*elseif (gender = “female”)
*choice
#Sharon
*set name “Sharon”
*goto_scene lastname
#Patricia
*set name “Patricia”
*goto_scene lastname
#Lea
*set name “Lea”
*goto_scene lastname
#Amber
*set name “Amber”
*goto_scene lastname
#Meiya
*set name “Meiya”
*goto_scene lastname
#None of these names
*goto_scene firstnames
You need an *else choice too if you are going to use *elseif!
If you only have male and female, use only *if and *else.
doesn’t help, still the same result
Can we see the indents for each line? They need to have indents or the choices will not work, for example like this:
*if (gender = "male")
*choice
#Sebastion
*set name "Sebastion"
*goto_scene lastname
*elseif (gender = "female")
*choice
#Sharon
*set name "Sharon"
*goto_scene lastname
Something like this:
*if (gender = “male”)
*choice
#Sebastion
*set name “Sebastion”
*goto_scene lastname
*else
*choice
#Sharon
*set name “Sharon”
*goto_scene lastname
(I changed the elseif to else but the result is the same)
strangely though, the error happened in the choice line for male
Hmm, it looks like the indents got deleted in your post. You need to highlight the code you’ve pasted here and use Ctrl + E in order to keep the indents.
What does the error say? Is it the same as before?
*if (gender = "male")
*choice
#Sebastion
*set name "Sebastion"
*goto_scene lastname
*else
*choice
#Sharon
*set name "Sharon"
*goto_scene lastname
it’s the same error, the error happens at the first *choice line, but if I selected male in the gender selecting choice the error won’t show up
nvm I figured out why, it seems either choicescript is incredibly inconsistent or ChoiceScript IDE is bugged. I deleted the first *choice line and reentered again and it works
Just to comment on the code you showed us: you need to indent any code that depends on an *if
, *elseif
, or *else
command. So the *choice
commands shouldnt be on the same indent level as the if/else.
so that means that space bar actually means level?
You can use either tabs or spaces, but the end result should look something like:
*if (gender = "male")
*choice
#Sebastion
*set name "Sebastion"
*goto_scene lastname
2 Likes