New features in ChoiceScript: change text size/color, hyphen spacing, @{} variable replacement

In the latest version of ChoiceScript available on github, there are new features for you to try.

  1. Change text size/color. You can now change the size and color of text, as we announced a few days ago. There’s a new “Settings” button which exposes the new options.

  2. Multireplace. There’s a new way to insert text based on variables, @{}. (I’m calling it “multireplace” for now, but maybe somebody else will come up with a better name for it.)

It’s a little bit like ${} replacement, but you give it a variable and a list of options. The variable must be either a number or “true”/“false” (true=1, false=2). @{} will insert the option corresponding to the number.

There @{count is one thing|are two things|are three things} here.
You are on the @{is_evil Dark|Light} Side of the Force.
Behold the dragon@{plural s|}!
Behold the dragon@{(dragons > 1) s|}!
Behold the dragon@{(dragons = 1) |s}!

The first word should be a variable name, followed by a space, and then a number of options separated by vertical pipes |. Empty options are allowed. You can also use more complex expressions by wrapping them in parentheses.

Note that the first option is numbered #1. If you want the first option to be zero, add 1 to the variable in parentheses, like this:

There @{(count+1) are no things|is one thing|are two things} here.

You can nest ${} replacements in @{} but you can’t nest @{} inside another @{}.

  1. Hyphen spacing. Now, ending a line with a hyphen or a longer dash “—” will not insert an extra space at the end of the line.

So if you write code like this:

All
one
line,
separate
words.

This-
is-
all-
one-
word.

ChoiceScript will display it like this:

All one line, separate words.

This-is-all-one-word.

Note that our Style Guide explains that dashes between words should have no spaces before and after, e.g. “There’s a dragon behind you—you should run.” The new hyphen spacing will make it easier to follow that rule.

Enjoy!

18 Likes

A link, for the lazy people like me:

http://github.com/dfabulich/choicescript/zipball/master

As of April 30, 2017 the latest version seems to be:
dfabulich-choicescript-a46f474

3 Likes

Other, obscure usage:

*create count 3
*create mytest "There @{count is one thing|are two things|are three things} here."

Testing

There @{count is one thing|are two things|are three things} here.

mytest = ${mytest}

Results of the above:

Testing

There are three things here.

mytest = There are three things here.

Oops! That’s a bug. *create really won’t work with ${} or @{}. I’ve added an error message so using @{} in *create will now fail with a clear error.

1 Like

So if one were to do what Carlos.R suggested, but with *set instead of *create (having previously created the variable), would that be supposed to work?

Yes, it’s fine in a *set command. *create is special because it defines your “starting values.” Your stats can change throughout the game, but the starting values are never supposed to change.

1 Like

So just to clarify… in my example where @{ } is stored in the mytest variable as part of a string… is that working as intended?

So as far as usage goes, it’s looking like @{ would mostly serve as a streamlined replacement for clunky sets of *if clauses, correct? I could see this coming in handy for flavor text, especially.

I suppose you could even get it to work for longer ranges of numbers with judicious use of division. For example, a typical percentage relationship score, modified to give a range of 1-5…
@{((round(sandy/25))+1) Sandy hates me.|Sandy doesn’t like me much.|Sandy and I are neutral acquaintances.|Sandy and I get along well.|Sandy and I are best friends.}

This suggests to me that it could have interesting uses in a stats screen as well.

3 Likes

Yeah; just convert your *creates into *temps and it’ll work as designed.

2 Likes
*temp count 3
*temp mytest "There @{count is one thing|are two things|are three things} here."
*temp mytest2 "?"

Testing

There @{count is one thing|are two things|are three things} here.

mytest = ${mytest}

*set mytest2 {mytest}

mytest2 = ${mytest2}

Produces this error:

1 Like

I think the issue is here… ${mytest} would become “there are three things here” so it is checking whether the variable “mytest” matches the theoretical variable “there are three things here,” which doesn’t exist.

Aha! Ok… more sorcery…

*temp count 3
*temp mytest "@{count one|two|three}"
*temp mytest2 "?"
*temp three 3

Testing

@{count one|two|three}

mytest = ${mytest}

*set mytest2 {mytest}

mytest2 = ${mytest2}

Produces this:

Testing

three

mytest = three

mytest2 = 3
1 Like

Or wait, no, that line wasn’t the issue, because it wasn’t an *if clause… it was just text displaying…

Let’s see, line 11 was here…

And that’s where it would be trying to set mytest2 to match “there are three things here.” So that’s where it was.
I’m not sure about the brackets here :confused: I think I’d be used to something like *set mytest2 “${mytest}”

But then that same line appears to work in your new version :confused:
I guess it’s working because you’d set mytest to become “three” rather than “there are three things here,” and it also worked because you’d created "three as a temporary variable. So that’s the difference here.
I’m just not sure why it works with plain brackets, which I don’t think I generally see in code… is there a change in how coding works with brackets for variables, or is this unintended behavior?

Edit: Wait, I see, this bracket use is a feature described here: New ChoiceScript features for programmers
That does make things smoother :thinking:
(And is indeed in the Advanced Choicescript Commands page under “Curly parens” and “Set by reference”… there we go. I think I’ve just been used to seeing it the other way around :sweat_smile:)

1 Like

And here is a very rough random “name” generator to play with.
(It works!)
Feel free to edit, improve, and use this in your own projects:

*temp count 1
*temp number 1
*temp name ""
*temp holder ""

*label myname
*if count < 8
 *rand number 1 26
 *set holder "@{number a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z}"
 *set name &holder
 *set count +1
 *goto myname
*if count = 8
 *set count 0
 *goto helloworld

*label helloworld

My randomized name is: ${name}

2 Likes

I haven’t tested this, but how’s this for a random name generator to fit a fairly generic language. Could be modified to fit whatever sound system is desired… using the same principle, but separated into separate labels should allow for more structured and prettier words :smile:
Also modified to allow variable word lengths.
A further possible modification would be to make certain letters more common by repeating them.

*temp count 1
*temp number 1
*temp name ""
*temp holder ""

*rand count 1 6

*label myname
*label onset
*if count < 10
 *rand number 1 13
 *set holder "@{number m|n|p|t|k|b|d|g|s|h|w|l|y}"
 *set name &holder
 *set count +1
 *goto vowel
*if count = 10
 *set count 0
 *goto helloworld
*label vowel
*rand number 1 5
*set holder "@{number a|e|i|o|u}"
*set name &holder
*set count +1
*rand number 1 4
*if number < 4
 *goto onset
*if number = 4
 *goto coda
*label coda
*if count < 10
 *rand number 1 4
 *set holder "@{number n|l|i|u}"
 *set name &holder
 *set count +1
 *goto onset
*if count = 10
 *set count 0
 *goto helloworld

*label helloworld

My randomized name is: ${name}
2 Likes

“…limited only by the vast, unstoppable power of your imagination…!”

Here’s a vast improvement to my original:

Code
*temp count 0
*temp number 1
*temp name ""
*temp holder ""
*temp limit 0

*label mainmenu
How long do you want your name to be (in letters)?

*choice
 #3
  *set limit 3
  *goto myname
 #4
  *set limit 4
  *goto myname
 #5
  *set limit 5
  *goto myname
 #6
  *set limit 6
  *goto myname
 #7
  *set limit 7
  *goto myname
 #8
  *set limit 8
  *goto myname
 #9
  *set limit 9
  *goto myname
 #10
  *set limit 10
  *goto myname

*label myname
*if count < limit
 *rand number 1 21
 *if count = 0
  *set holder "@{number B|C|D|F|G|H|J|K|L|M|N|P|Q|R|S|T|V|W|X|Y|Z}"
 *if count > 0
  *set holder "@{number b|c|d|f|g|h|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z}"
 *set name &holder
 *set count +1
 *if count < limit
  *goto myname2
*if count = limit
 *set count 0
 *goto helloworld

*label myname2
*if count < limit
 *rand number 1 5
 *set holder "@{number a|e|i|o|u}"
 *set name &holder
 *set count +1
 *goto myname

*label helloworld
My randomized name is: ${name}

Do you want to keep this name, or pick another?

*choice
 #Pick Again
  *set name ""
  *set count 0
  *goto myname
 #Change the Length
  *set name ""
  *set count 0
  *goto mainmenu
 #Keep It
  *goto success

*label success
You have chosen to keep the name: ${name}

(Link to your code here.)
1 Like

And now for something Englishy…
It wouldn’t quite fit English exactly, but it should come close to giving the right vibe, assuming I coded it correctly.

*temp count 0
*temp number 1
*temp name ""
*temp holder ""
*temp limit 0

*label mainmenu
How long do you want your name to be (in syllables)?

*choice
 #1
  *set limit 1
  *goto myname
 #2
  *set limit 2
  *goto myname
 #3
  *set limit 3
  *goto myname
 #4
  *set limit 4
  *goto myname

*label myname
*rand number 1 4
*if number = 4
 *set name &"s"
*rand number 1 16
*set holder "@{number m|n|p|t|c|k|qu|ch|j|f|th|sh|h|v|z|}"
*set name &holder
*if holder = "qu"
 *goto qskip
*rand number 1 10
*if number < 5
 *set holder "@{number w|r|l|y}"
 *set name &holder
*rand number 1 9
*label qskip
*set holder "@{number a|e|i|o|u|ai|ee|oa|oo}"
*set name &holder
*rand number 1 15
*if number < 8
 *set holder "@{number m|n|ng|r|w|l|y}"
 *set name &holder
*rand number 1 20
*if number  < 12
 *set holder "@{number p|t|c|k|ch|j|f|th|sh|v|z}"
 *set name &holder
*rand number 1 4
*if number = 4
 *set name &"s"
*set count +1
*if count < limit
 *goto myname

*set name "$!{name}"

My randomized name is: ${name}.



Do you want to keep this name, or pick another?

*choice
 #Pick Again
  *set name ""
  *set count 0
  *goto myname
 #Change the Length
  *set name ""
  *set count 0
  *goto mainmenu
 #Keep It
  *goto success

*label success
You have chosen to keep the name: ${name}

Error messages on all options :cold_sweat:

What message? I’m on phone so I can’t check just now :worried:

1 Like