FANDOM


    Choicescript has another handy feature called multireplace; it can be used to avoid long sections of *if for moments that would only contain different text. It can also keep it all in one line, improving code readability.

Usage Edit

Let's say we have a variable var1 with a numerical value of 3. We can make ChoiceScript display different text based on the value of var1.

*temp var1 3

@{var1 "The dragon is blue"|"The dragon is red."|"The dragon is green."}

The text displayed will depend on the value that was set to var1. Each section separated by a | will be displayed if the value of the variable used is in that order.

In the example above, the displayed text would be "The dragon is green.". If var1 was 1, it would display "The dragon is blue."; while if it was 2 it would display "The dragon is red.".

 Variables can also be used inside multireplace. Like the following example:

*temp var1 3

*temp var2 "tall."

@{var1 "The dragon is blue and ${var2}"|"The dragon is red and ${var2}"|"The dragon is green and ${var2}"}

This will display "The dragon is green and tall."

Boolean variables can also be used. With the first section being true and the second false.

temp var1 false

@{var1 "The dragon is blue."|"The dragon is red."}

In this case, since 'var1 is 'false,, the displayed result will be '"The dragon is red."..

IMPORTANT: Beware that multireplaces cannot be nested together.

Managing Verbs for Singular They Edit

In April 2016, ChoiceScript author Lynnea Glasser wrote here about the challenge of coding for a character who might prefer either a traditional singular pronoun or the pronoun "they." The differences in verb conjugations can be tricky to manage with a typical ${variable} code; compare "he flies," with "they fly"; "she is," with "they are"; "xe doesn't," with "they don't." In some cases, managing it took multiple lines of code:

$!{pronoun}
*if plural = true
  are
 *if plural = false
  is
 happy.

The multireplace function, introduced a year or so after Glasser's blog post, now makes it possible to code this more efficiently.

Here's one way to do it. In startup.txt, create a string variable for the character's pronoun (which may later be set to e.g. "he," "she," "they," or a neopronoun) as well as a Boolean variable for whether the pronoun is plural.

*create pronoun ""
*create plural false

When the character's gender is set, if the character uses the pronoun "they," (or for that matter any other plural pronoun--maybe they prefer the royal we?) the variable plural should be set to true.

*set pronoun "they"
*set plural true

From that point on, multireplace can be used to select the right verb conjugation:

$!{pronoun} @{plural don't|doesn't} want to go.

This could display as "They don't want to go." or "She doesn't want to go." depending on the pronoun.


More commands
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
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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.