Hey, back at it again with another issue involving ifs and elseifs. This time IâmâŚfairly certain that it shouldnât be an indentation issue because Iâve been using tabs instead of spaces. Iâm still getting an error about falling out of the choice, though. Is it just the values Iâm using and Iâm too bricked to understand basic math?
*if (Discipline >= 40)
Text description.
*goto_scene wild7
*elseif (Discipline < 40) and (Discipline >= 20)
Text description.
*goto_scene wild7
*elseif (Discipline < 20)
Text Description.
*set PCohesion %-10
*goto_scene wild7```
If youâre using elseif, the last command in the list always has to be an else. Itâs kind of an âif none of the things above apply, then do thisâ statement. ChoiceScript gets confused and will throw up errors if it canât find it.
I suspect your error is happening in the broader choice, or maybe in wild7.txt.
Is that something ChoiceScript used to require in the past?
Because I use *if/*elseif without a final *else all the time. I typically donât needâor wantâa catchall.
For a really slapdash example:
This compiles and passes both QT and RT.
*create strength 50
*create charisma 50
*create dragon_regard 1
*rand strength 15 85
*rand charisma 15 85
(Strength is ${strength}, Charisma is ${charisma}.)
You meet a dragon.
*if strength > 65
"I have heard impressive tales of your strength," the dragon says. "I admire that greatly."
*set dragon_regard + 3
*goto gold_pile
*elseif charisma > 75
"People speak highly of your oratory skill," the dragon says. "I'm something of an orator myself."
*set dragon_regard + 2
*goto gold_pile
*elseif (strength > 60) and (charisma > 60)
"People say you are quite a skilled individual," the dragon says.
*set dragon_regard + 1
*goto gold_pile
*label gold_pile
The dragon regards you cautiously, basking languidly atop a pile of gold coins.
*ending
In my opinion:
*if/*if/*if... is for outcomes that arenât mutually exclusive or mandatory. You want to show multiple extra bits to some players.
*if/*elseif(s) is for outcomes that are mutually exclusive but not mandatory. You want to show exactly one of multiple possible extra bits to some players.
(While you could use a series of *ifs, IMO itâs better coding practice to clearly communicate your intent for the outcomes to be mutually exclusive. For yourself and any reviewers.)
*if/*elseif(s) [optional]/*else is for outcomes that are mutually exclusive and mandatory. Everyone needs to get exactly one bit.
Some people also use final *elses to throw *bugs or display error text as a debugging strategy.
Whatever coding method works for you is the one you should use. ChoiceScript is for everyone. Thatâs the first and last thing Iâd say about any of this stuff.
There are advantage to getting comfortable with elseifs. Pull out the if/elseifs from Lanâs example:
If you want to achieve the same results using *ifs alone, I beileve youâd need:
*if (strength > 65)
*if (strength <= 65) and (charisma > 75)
*if ((strength > 60) and (charisma > 60)) and ((strength <= 65) and (charisma <= 75))
Thatâs a lot more fiddly code-typing and at least double the opportunity for typos.
But that doesnât mean elseifs are necessary. Some people will no doubt find it easier to keep track of the conditions when theyâre all written out like that (rather than implicit in the *elseifs), especially if there are long stretches of text and other code in between the conditional commands. Some people hate *gotos so much that theyâd count the extra typing a small price to avoid those three extra *goto nexts. And of course, you can write a perfectly good game that never gives the reader a list of âmutually exclusive but not mandatoryâ options.
Whatever coding method works for you is the one you should use. ChoiceScript is for everyone.
I just used an *else instead of an *elseif and it still threw an error.
#You take aim at the officer and pull the trigger.
*if (Discipline >=30)
You got him.
*goto_scene wild7
*elseif (Discipline < 30)
You missed.
*goto_scene wild7
#You take aim at the machine gunner and pull the trigger.
*if (Discipline >= 40)
You got him but better.
*goto_scene wild7
*elseif (Discipline < 40) and (Discipline >= 20)
You got him.
*goto_scene wild7
*else
You missed.
*set PCohesion %-10
*goto_scene wild7
#You take aim at one of the riflemen and shoot.
Rollin' rollin' rollin' rollin
*goto_scene wild7
#You shoot over the enemyâs head. You donât want to kill anyone.
You escape this time.
*goto_scene wild7```
You need all the #Options to be at the same indent level.
And here:
*if (Discipline >=30)
*elseif (Discipline < 30)
You can just use *else instead of *elseif (Discipline < 30), because that covers all the logical possibilities.
If you do use an *if/*elseif after an #Option, youâve got to make sure thereâs somewhere for the code to go â either an *else or a *goto indented at the same level as the *if/*elseif. Right now you donât have that.
You can use *if to display text without a *goto. This will work:
You went to school, took the exam,
*if (exam_passed)
passed it,
and then went to lunch
If you use *elseif or *else with your *if, though, each bit needs to end with a *goto. You do it correctly in the âtake aim at the machine gunnerâ segment.
For your âshoot the officerâ bit, any of these three ways could work:
#You take aim at the officer and pull the trigger.
*if (Discipline >=30)
You got him.
*goto_scene wild7
*else
You missed.
*goto_scene wild7
#You take aim at the officer and pull the trigger.
*if (Discipline >=30)
You got him.
*goto_scene wild7
*elseif (Discipline < 30)
You missed.
*goto_scene wild7
*goto_scene wild7
#You take aim at the officer and pull the trigger.
*if (Discipline >=30)
You got him.
*if (Discipline < 30)
You missed.
*goto_scene wild7
Yep, just giving you illustrations of what the *gotos need to be doing with the if/else, if/elseif, and if/if approaches when theyâre part of an #Option block.
Quick minor question, how do I set one variable to equal another? Like if I wanted variable1 to be set to variable2, would I not use [*set variable1 = variable2]? It turned up an error when I tried this. I also tried [*set variable1 = â${variable2}â]
(Iâm sure itâs been asked before but I couldnât find the appropriate posts)
Iâve been having an issue on the stats screen where some of the text isnât displayed in the bar. It is an opposed stat, and the text on the left side appears, but the text on the right does not.
Rebelliousness
opposed_pair Merciful
Ruthless```
For context, it is specifically the "Merciful" variable that does not appear. Everything else does.