some quirks with wrapping strings inside quotation marks
<<choice_shown '"You know what, I\'m just going to write something vague. Ten bucks."' _next>>
You may notice in some choice text that I had to add in backslash (\
) to “escape” a single quote, because I need to wrap the full string inside a single quote, and thus need to clarify to the engine that the single quotes inside the string should be kept.
In cases where there is no need to preserve the double quote in a string, example:
<<choice_shown "There's no point." _next>>
I can in those situations wrap the whole string in double quote, and don’t need to use backslash to escape the single quote inside the string, since there’s no confusion about which quote is doing the wrapping of the string.
In other context, like setting a string value to a variable, which can be done using either double or single quotes, for example:
<<set $fname = "Ellie">>
or
<<set $fname = 'Ellie'>>
both will work. But if you want to keep both types of quotation marks without needing to escape either of them, you can use backtick (`) marks to wrap the entire string. For example, you’ll see most $text being assigned a string value like this:
<<set $text = `"I have a name, you know." I frown at him.<br><br>"Uh, it's ` + $guess + `, right?" He scratches his head.<br><br>`>>
This is only feasible for assigning a value to a variable. Also replace blank lines with <br><br>, which behaves similarly to [n/][n/] in ChoiceScript. Since long text are hard to read for code review when squished together, you can instead make each choice go to a different passage with different flavor text, then at the end of each of those passages, include the shared content. For example:
:: choicepassage
Some text
<<choice_shown "first choice" "firstchoice">><</choice_shown>>
<<choice_shown "second choice" "secondchoice">><</choice_shown>>
:: firstchoice
flavor 1
<br><br>
<<include "nextpassage">>
:: secondchoice
flavor 2
<<include "nextpassage">>
:: nextpassage
same content can be shared
<br><br>
<<choice_shown "more choices" "morechoices">><</choice_shown>>
...
The advantage of this method is that illume will count the words in passages firstchoice and secondchoice (when normally it might skip the words in variables like $text), it’s clearer for you to read when debugging, and you don’t need to use a flag variable to remember which choice was made, because in this code context, hasVisited(“firstchoice”) checks whether player had chosen “first choice”, and hasVisited(“secondchoice”) checks whether player had chosen “second choice.” The downside is that this method creates more passages (if you look at the project visually, it will appear more crowded than before), and leads to more typing (it’s also harder to share same flavor text content across different passages without using global variables that you have to manage carefully).
Get SugarCube code collection to emulate the look of ChoiceScript
SugarCube code collection to emulate the look of ChoiceScript
(for intermediate user) template code for use in Twine 2 with SugarCube 2 story format
Status | In development |
Category | Other |
Author | brushmen |
Tags | sugarcube, Project template, Twine |
Languages | English |
Accessibility | Color-blind friendly, High-contrast, Blind friendly |
More posts
- variable types and string TemplateApr 23, 2023
- storyinit.twApr 23, 2023
- storydata.twApr 23, 2023
- config.jsApr 23, 2023
- "compile.bat", task automation for compilingApr 23, 2023
- Preparation StepsApr 23, 2023
Leave a comment
Log in with itch.io to leave a comment.