Posted April 23, 2023 by brushmen
<<set $var5 = "some text">>
$var5
<<unset $var5>> /% removes it from game %/
<<set $var5 = "new text">> /% re-create it again and give it a different value %/
/% alternative ways to output a variable's value, just fyi %/
Some text, now show <<= $var5>> or <<print $var5>>
<<set _next = "c3_chat">>
<<set _same = `Seeing me settling down with my mess of papers, she shifts back a little to give me more space.`>>
<<choice_shown 'I nod, then move my stuff to the small desk. "Thanks for standing up for me."' _next `hasVisited("c3_interrupt")`>>
<<set $text = `"Us bookworms have to stick together," her smile is more natural this time. ` + _same>>
<</choice_shown>>
<<choice_shown 'I nod. "Thanks."' _next>>
<<set $text = _same>>
<</choice_shown>>
After we move to a different passage, the temporary variables will be undefined.
"...$fname could get into any school ?they <<verb 'wants' 'want'>>. I mean, have you seen ?their grades?"
In ChoiceScript, you can do $!{var} to capitalize the first letter easily, but there is no direct equivalent in SugarCube. Because Template words are case sensitive, however, we could make a capitalized template word to return a capitalized version. In the narrative part of the code, this can be more readable at a glance.
To see full definitions of Templates that are set up in this game, see “src/js/templates.js” file for detail, but don’t change anything there without first understanding what the code is doing.
I learned about Template after using a third-party script (see “vendor/chapel/pronouns.js”) for MC’s pronoun template as well as verb conjugation if it’s plural, but it is only usable for the MC, thus I had to learn how to do the simple version for the other gender-variable characters.
See more documentation of this custom pronoun script: https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/docs/pronoun-templates.md
<<pverb $pluralornot "have" "has">>
(I didn’t want to edit Chapel’s <<verb>> macro, and wanted to keep ChoiceScript’s multireplace’s syntax, so unfortunately this results in <<verb>> and <<pverb>> not having a similar parameter order, aka they take in singular and plural verb in different order. Sorry for the confusion.)
I tweaked the code further and now we can define the plural and singular forms in “src/js/pverb.js”, and then in the passage we only need to give it the main form of the verb (ie. “are”, “have”, “say”, etc.). Example syntax:
?They <<pverb $theypronounplural "have">> it.
You can still just explicitly provide the plural and singular forms of the verb, but this method can save you some typing if that verb gets repeated a lot in the story.
To add more verb forms to that list, go to src/js/pverb.js:
setup.pverblist = {
"are" : "is", "aren't" : "isn't",
"have" : "has"
};
for example, you can add “hug” : “hugs” to any point after a comma and before another pair, but if it’s between other pairs, add a comma after it. If you add it to the end of the list, add a comma after “have” : “has”, like:
setup.pverblist = {
"are" : "is", "aren't" : "isn't",
"have" : "has",
"hug" : "hugs"
};
The last pair in the list should not have a comma after it, or Javascript will complain when you try to compile this code.
Note: you can put every pair on the same line, or put them on separate lines; I just put some pairs on the same line because they are similar verbs. As long as the commas are in the right place, the list will be understood by the engine.