So i want to display variables for hunger in my stats screen, but *if statements seem to be getting in my way. I managed to make it work out and display what I wanted it to [image attached], but surely there’s a more elegant way to do this than using a *goto leading to an empty label to get it to work, right?
I also cannot use *finish in place of *goto here, as that makes it only read the first part of the hunger sequence (The MC’s) and not the siblings as well.
Here’s my example code (in choicescriptstats_txt):
*stat_chart
percent Health
HUNGER
*line_break
*if (hunger=1)
$!{h1}
*goto h
*elseif (hunger=2)
$!{h2}
*goto h
*elseif (hunger=3)
$!{h3}
*goto h
*else (hunger =4)
$!{h4}
*goto h
*label h
SIBLING HUNGER
*line_break
*if (shunger=1)
$!{sh1}
*goto s
Well first of all, you don’t actually need to use *elseif here at all. There’s no possible situation where “hunger” equals more than one value at once, so you can just replace every single one of them with a normal *if and there will be no need for *goto anymore.
Alternatively, if you already feel comfortable with ChoiceScript, you can just put *create implicit_control_flow true at the start of your story and eliminate the need for all these pesky *goto commands altogether. I know it’s not recommended for new writers, but I personally consider the default setting a bit of a pain, so maybe consider that eventually.
Annnnd that worked! silly me, i originally had them all as simple *if statements but decided to change them all to *elseif…just because? This is what happens when you code all day kids
Ill look into the implicit control flow thing, ive always hated having to create extra labels because of *if statements
Not necessarily. CS is built to lean on labels. Any if/elseif/else block requires a label at the end (unless you switch on Implicit Control Flow, which I wouldn’t recommend for anyone still getting their heads around the coding). Thinking of your *label h as an “empty label,” reasonable as that may be, isn’t a perspective that fits with CS’s design as a language.
But if hunger only has four possible values-- from when you create it through the whole game, not just when you want to check it – you can use multireplace like this:
@{hunger $!{h1}|$!{h2}|$!{h3}|$!{h4}}
to yield the same outcome as your *if hunger block.
Note that when you’re using if/elseif/else, the last option should just be
*else
not
*else (variable = "value")
and also not
*elseif (shunger =4)
If you want to remind yourself of what that *else means, you can do it with a comment: