I see two possible ways to handle this: First, adding an extra label after each chain of *if
and *else
; or second, using a chain of all *if
without any *elseif
or *else
statements, as *if
can function without a redirect command such as *goto
or *finish
but those two require redirects.
With the first method, you may have code something like this...
*label briefing
You chose
*if race = 0
Bananas.
*goto stat_points
*elseif race = 1
Lollipops.
*goto stat_points
*else
Berries.
*goto stat_points
*label stat_points
Because of this you get stat points based on your choice :
*if race = 0
*set strength +2
*set agility +1
*set persuasion +1
*set perception +1
*goto view_stats
*elseif race = 1
*set intelligence +2
*set agility +1
*set persuasion +1
*set perception +1
*goto view_stats
*else
*set strength +1
*set agility +3
*set perception +1
*goto view_stats
*label view_stats
Strength: ${Strength}
Agility: ${Agility}
Intelligence: ${intelligence}
Persuasion: ${Persuasion}
Perception: ${Perception}
*goto getStats
Fairly simple, though perhaps a little longer than you’d like, due to the extra *label
statements and *goto
commands.
The second method may use code something like this...
*label briefing
You chose
*if race = 0
Bananas.
*if race = 1
Lollipops.
*if (race != 0) and (race != 1)
Berries.
Because of this you get stat points based on your choice :
*if race = 0
*set strength +2
*set agility +1
*set persuasion +1
*set perception +1
*if race = 1
*set intelligence +2
*set agility +1
*set persuasion +1
*set perception +1
*if (race != 0) and (race != 1)
*set strength +1
*set agility +3
*set perception +1
Strength: ${Strength}
Agility: ${Agility}
Intelligence: ${intelligence}
Persuasion: ${Persuasion}
Perception: ${Perception}
*goto getStats
In the second example, I used *if (race != 0) and (race != 1)
to duplicate the effect of an *else
without actually using an *else
. If you’re not going to use *else
, you’ll need something to make sure every possible value for the variable in question can be handled by the code the way you want, and nothing simply “falls out” by accident. It isn’t wrong to write code that “falls out” on purpose, but it should only happen because you’ve chosen to do that.
You could absolutely use *if race > 1
to achieve the same effect… if you’re absolutely certain the race
variable will never be both less than one and not equal to one or zero at the same time. If you use *if race > 1
and some function of math causes the race variable to be something ridiculous like -1 or 0.5, the code won’t be able to handle it (-1 is not greater than 1, but is simultaneously not equal to 0 or equal to 1.) If your variable will only be whole integers, and only 0 or greater, then *if race > 1
will work perfectly!
I did notice one final possibility, at least for this specific sample of code...
*label briefing
You chose
*if race = 0
Bananas.
*set strength +2
*set agility +1
*set persuasion +1
*set perception +1
*if race = 1
Lollipops.
*set intelligence +2
*set agility +1
*set persuasion +1
*set perception +1
*if (race != 0) and (race != 1)
Berries.
*set strength +1
*set agility +3
*set perception +1
Because of this you get stat points based on your choice :
Strength: ${Strength}
Agility: ${Agility}
Intelligence: ${intelligence}
Persuasion: ${Persuasion}
Perception: ${Perception}
*goto getStats
Because both of your *if
chains are looking for the exact same combination of values for the race
variable, you can handle setting stats with the same *if
statements you used to display the Bananas, Lollipops, and Berries text.