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

Yeah, a combination of *if statements with multireplace is possible, but I’d be looking for something more like
@{damage+1 You miss.|You do 1 damage with your @{weapon sword|dagger|mace|carrot}.}

Totally fake example, but yes I’m dealing with a lot of ifs that could be much more elegant with nested (or nested in nested—a girl can dream, right?) mutireplace.

Humm… I can see where’s your question comes from.


When you think about it, I think your code can be like this
@{damage+1 You miss.|You do 1 damage with your ${weapon sword|dagger|mace|carrot}.}

considering @{@{}} is not a possible combination. Not yet, at least.

But I admit, coding *set weapon 123 is much faster and more practical than *set weapon "carrot".

Whilst I agree this would be cool, I get the impression it might be abused and lead to some really hard to read code?

1 Like

You may not be able to do it directly with a single line of code, but you can do it indirectly.

*temp temp1 "@{weapon sword|dagger|mace|carrot}"
@{damage+1 You miss.|You do 1 damage with your ${temp1}.}

I tested, and it seems to work exactly as expected! It’s not quite nested, but it may simplify a mess of *if commands anyway.

6 Likes

Nice idea, I’ll have to check if that would help with any of my code. I’ve mostly ended up either combining with *if statements or separating the multireplaces across multiple variables.

Haha, perhaps too much nesting would get a little out of hand. Seeing how much more compact my code is thanks to multireplace, though, I’d imagine that 1 nested level could actually still make the code clearer. But I could be wrong!

Sure, it’s not at all a necessary feature, but then neither are many of the more programming-heavy features, yet they can be really helpful to people who do choose to utilize them. Anyway, it’s just me dreaming! :sweat_smile:

Question about multireplace:

If I have numerous places where I want to check if a particular variable is over a certain quantity, is code like this acceptable?

@{(languages + 59) the foreign tongue | Deeplandish}

It’s tidier than

*if (languages > 60)
  Deeplandish
*if (languages <= 60)
  the foreign tongue

I hesitate to just use a variable because the checks aren’t all quite the same, and besides, this way I can tweak the text to its surrounding prose.

Is there any reason why this would be a bad idea?

It would be @{(languages <= 59) the foreign tongue | Deeplandish} in this case. You want the first part to be something an *if will see as either true or false, whereas language + 59 is just a number.

2 Likes

@ParrotWatcher But the numbers are 60 and 61, right…and oh, I see. Wooops. XD Thanks so much! I’ll sort that.

Sorry, 60, yes. I missed that part. :stuck_out_tongue_winking_eye:

1 Like

And I missed basically everything logical. ;p This makes this whole passage work so much better, though, yay! Thanks again, very much obliged.

Just a quick-guide to help anyone understand how the syntax works.

*set lamp 1
@{(lamp = 1) on|off}
1 Like

Right, thank you.

I’d been using multireplace properly for variables where, for instance, biting_daisies = 1 (or 2, 3, 4, etc.) but then it occurred to me that multireplace would be really useful for some of my on/off *if flavour text. But I nearly implemented it all wrong, because my way would have only worked if the player had exactly 60 or 61 in languages. I hadn’t thought it through properly; too excited about ending the endless string of *if statements, I suppose.

4 Likes

Actually, it would’ve thrown an error. I drew up a little test file while I was composing my reply (which then got ninja’d to the point I didn’t need to post anymore.) My code looked like this:

*create languages 50
You hear people conversing in @{(languages + 59) the foreign tongue|Deeplandish}.

It gave me the following error:
line 7 of startup: invalid @{} at letter 31; ‘languages + 59’ is equal to 109 but there are only 2 options

2 Likes

Perhaps the following is correct: A girl and her flowers. @{(girl = 1) daisies|sunflowers}

2 Likes

So here 1 means she has daisies and 2 means she has sunflowers, right? If you wanted to replace flowers, you’d use:

A girl and her @{girl daisies|sunflowers}.

At least, if I’m understanding correctly. Then if you wanted her to have other flowers for values of 3 and 4 and what have you, as long as one keeps track of what number equates to what state, it’s possible to just expand into

A girl and her @{girl daisies|sunflowers|nasturtiums|Venus flytraps}.

3 Likes

I’ve mentioned this elsewhere, but if you set a character’s gender variable as numeric instead of a string, you can simplify plural-variant verbs for “they/them” pronouns. For example:

*fake_choice
	#Non-binary.
		*set gender 1
		*set they "they"
	#Female.
		*set gender 2
		*set they "she"
	#Male.
		*set gender 3
		*set they "he"

Then you can insert things like @{gender teach|teaches|teaches} or @{gender go|goes|goes} inline instead of breaking your sentences apart to use structures things like:

*if gender = "non-binary"
	teach
*if gender != "non-binary"
	teaches

*if gender = "non-binary"
	go
*if gender != "non-binary"
	goes

And you can use that in conjunction with (or instead of) pronoun variables:

$!{they} @{gender go|goes|goes} to the market every Saturday morning.
@{gender They go|She goes|He goes} to the market every Saturday morning.

Edit: You can leave an option within the multireplace blank as well. So you could also do:

$!{they} go@{gender |es|es} to the market every Saturday morning.

9 Likes

Great implementations!
As for a name, why not go with what it really is - switch case?

Also, please reflect all of these updates at your page. Would make sense if budding authors would be cognizant of all what ChoiceScript has to offer.

I’ve just added a variation of @Minnow’s suggestion over on the Wiki.

The only difference is that instead of a numeric gender variable (they = 1, she = 2, he = 3), I’m suggesting a Boolean, “plural,” to keep things simpler. In English, I don’t think there are any verbs that conjugate differently for he and she. So it could work like this:

My preferred pronoun is
*fake_choice
	#They.
		*set plural true
		*set they "they"
	#Royal We.
		*set plural true
		*set they "we"
	#She.
		*set they "she"
	#He.
		*set they "he"

and then inside the multireplace brackets, we only need: @{plural go|goes} without the need for a third option.

Feel free to suggest edits to the Wiki. I’m still new to multireplace, and to coding for nonbinary characters. :slight_smile:

6 Likes

Would you also include Minnow’s because I’ve started using numeric variables for the majority of my coding?

The reason I am using numeric variables as much as possible is to reinforce consistency.

Nice, when I created the page I just added some basic explanation but no examples like these; that’s cool.

I noticed there are no pages for *params and for arrays. I can do those later and explain how to use them.

2 Likes