ChoiceScript Wiki
Advertisement

   The *elseif command (also spelled *elsif) is only used after an *if command to specify an alternative if the initial *if condition fails.


Usage

While *elseif is only used following an *if command, it can be used either with or without a subsequent *else command.

Without a concluding *else, the *elseif command produces outcomes that are mutually exclusive, but not mandatory. So in the following example:

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

The three different options for dragon dialogue/stat change are mutually exclusive -- no reader will see more than one of them -- but they're not mandatory. A protagonist with low strength and low charisma will see none of them.

By contrast, with an *else command at the end, an *if/*elseif/*else block will produce outcomes that are mutually exclusive and mandatory. Each reader will see one and only one bit.

You wake up in the morning, feeling

*if happiness <= 10

    very sad.

    *goto next

*elseif (happiness <= 50)

    sad.

    *goto next

*elseif (happiness <= 70)

    moderately happy.

    *goto next

*elseif (happiness <= 90)

    happy!

    *goto next

*else

    deliriously happy!

    *goto next

*label next

ChoiceScript has top-down prioritization, so in this block it will check if happiness is 10 or less, then for happiness 11~50, happiness 51~70, happiness 71~90, and at the end a general catch condition for all values that don't fall into the conditions above — which, in this case, covers happiness of 91 and greater.

If the first condition isn't true (if happiness is equal to 30 for example), the code will check if the next block fits the specified condition. In this example, if all the blocks fail, the output will default to "You're very happy!" because of the general catch condition *else statement at the end.

Using *elseifs for code like this is more efficient and less bug-prone than a string of *ifs -- you don't have to type out "*if (happiness > 10) and (happiness <= 50)" to display text for a "happiness" score in the 11-50 range.


More commands / functions
Choice *choice, *fake_choice, *disable_reuse, *hide_reuse, *allow_reuse, *selectable_if
Variable *create, *temp, *set, Arithmetic operators, *delete, *input_number, *input_text, *print, *rand
Conditional *if, *elseif, *else, Multireplace
Goto *label, *goto, *goto_scene, *goto_random_scene, *gosub, *gosub_scene, *finish
Formatting Bold text, Italic text, *image, *line_break, *page_break, *link, *stat_chart
Miscellaneous *comment, *scene_list, *title, *author, *achieve, *achievement, *check_achievements, *bug, *ending, *more_games, *share_this_game, *show_password, *script, Implicit Control Flow
Advertisement