In the latest version of ChoiceScript up on github, you can extract the characters (letters/numerals) out of a variable, like this:
*temp word "xyzzy"
*temp first_letter word#1
*temp second_letter word#2
The first letter of the word "${word}" is ${first_letter} and the second letter of the word is ${second_letter}.
(Programmers will note that the character index is 1-based, not 0-based.)
You can count the number of characters in a word like this:
*temp word "plough"
*temp word_length length(word)
*temp last_letter word#word_length
The word ${word} is ${word_length}, and so its last letter is ${last_letter}.
You could also write: ${word#length(word)} to show the last letter.
Hereās a sample piece of code demonstrating how to capitalize the first letter of every word in a variable:
*temp title
*input_text title
*temp i 0
*temp prevWhiteSpace true
*temp recapitalized ""
*label while
*set i +1
*if i <= length(title)
*if (title#i) = " "
*set prevWhiteSpace true
*set recapitalized &(title#i)
*goto while
*if prevWhiteSpace
*set recapitalized &"$!{title#i}"
*set prevWhiteSpace false
*goto while
*else
*set recapitalized &(title#i)
*goto while
*set title recapitalized
The title is: "${title}"
@Fantom Keeping wikis up to date is an awful lot of hard work. Feel free to volunteer to update the wiki yourself. The front page has a list of admins, Iām sure you could contact one of them and ask them for wiki edit permissions.
Also if you make the page yourself chances are youāre less likely to forget about it.
First thing that comes to mind: the beautifully creepy maneuver from Sid Meierās Alpha Centauri where the protagonist (example, Deirdre) is referred to in lower case (earthdeirdre) when addressed telepathically. This would allow the author to do something similar with custom names entered by the player.
Iām wondering if you could do something similar for writing characters in the singular they! Right now Iāve been just including an if statement to check for which block of text to jump to, but this could be handy for determining subject verb agreement.
Note that HV is using a slightly older version that was 0-based. The latest version does this in a subroutine:
*label setWorkArticle
*temp fl "$!{workval#1}"
*if (((((fl = "A") or (fl = "E")) or (fl = "I")) or (fl = "O")) or (fl = "U"))
*set workArt "an"
*return
*set workArt "a"
*return
That code is pretty weird/fancy, so itās worth some explanation.
workval#1 returns the first letter of the global variable workval.
We donāt know whether itās upper case or lower case; we standardize on uppercase by wrapping the whole thing in $!{}
You canāt use $!{} directly in a *temp or *set statement, but you can use $!{} in quotes, and you can use quotes in a a *temp or *set statement.
Thus the line: *temp fl "$!{workval#1}"
OK, so now we have an uppercase letter that may or may not be a vowel. We check to see if itās A, E, I, O, or U, in which case weād *set workArt "an" and *return; otherwise weād *setWorkArt "a" and *return that.
So now workArt will be āanā if workval starts with a vowel, or workArt will be āaā otherwise.
I have a request though, if possible. Namely to use text variables for image links, so you can write something like image ${which_image} left, instead of having to write;
*if (image1)
image image1.jpg left
Thatās just off the top of my head, but if thereās more functionality for images maybe more would use them. Like for instance if one could separate the window into two areas, so maybe the upper part would stay still and the bottom with the next button would be handily frozen in place while the text and the choices scroll inside of a smaller box, like in a visual novel.
I am loving these new programmer features. Just off the top of my head, Iām certain we could program our own text/password save/load features using this functionality.
Iām going to need to find a way to use this, too. I can already imagine something like an NPC saying the MCās name and, if over a certain letter count, making a comment like āthatās a mouthfulā. Or if itās under a certain count, ānice and simple, I like that.ā - Iāll have to consider it when I have time for it and get to such a point.