Simplest Way of Printing Numbers as Text?


#1

Is there any built-in functionality for rendering numbers as text?

For instance, in this simple example:

*temp dice 1
*rand dice 1 6

You rolled ${dice} on the dice.

It would display something like, “You rolled 6 on the dice.” when, preferably, it would say “You rolled six on the dice.”


Now, of course I could do something fiddly with gosub_scene, like:

startup
*create number 0

First Chapter

*temp dice 1
*rand dice 1 6
*set number dice
*gosub_scene numberconversion

numberconversion
*if number = 1
one
*elseif number = 2
two
*elseif number = 3
three
*elseif number = 4
four
*elseif number = 5
five
*elseif number = 6
six
*else
${number}
*return


Of course, that would work but would be a hassle if I wanted to print larger numbers like “seventeen” or “forty-five”. Short of writing a complete number-rendering subroutine, is there an inbuilt or easier way of doing this?


#2

Pretty sure there’s not – but that would also be something I’d warmly support in a future ChoiceScript version, as a writer who gets stylistically offended when numerals pop up in the wrong places.


#3

Not that I know of, either. One of those things that manually takes way more code than it feels like it should, but there is a functional work around, it’s just a pain. Honestly, it looks like your example handles it pretty much the same way I would if I were looking to put a similar feature in one of my games. :smirk:


#4

I thought we could use fake arrays now wound not this work?

*create_array die 6
*set die[1] “one”
*set die[2] “two”
*set die[3] “three”
*set die[4] “four”
*set die[5] “five”
*set die[6] “six”

Of course I am still not to clear on the whole array thing so if not helpful sorry.


#5

An array would work but it would have to go up to 20, after 20 though you would have to use JoJo’s format so that you could combine the words from the 1st and 2nd number to get 2 = Twenty, 1 = One

That would make 21 = Twenty-One

This would still only work up to 99 though and after that you would have to add even more to the code. Your code for 1-19 seems like it would work (if a little lengthy) and if you wanted to do 1-99 you could manage that with a little extra code but its a lot of effort for something that is purely aesthetic. Is it worth the time?


#6

As an added bonus here is a shortened experiment of what it would look like:

*temp dice 0
*temp number_word1 ""
*temp number_word2 ""
*rand dice 1 99
*set number dice
*temp number_length length(number)
*if number_length = 1
	*set number_word1 ""
*if number_length = 2
	*temp number1 word#1
	*if word#1 = 1
		*goto teens
	*if word#1 = 2
		*set number_word "twenty"
		*set number_length -1
		*set number -20
		*goto next
	*if word#1 = 3
		*set number_word "thirty"
		*set number_length -1
		*set number -30
		*goto next
	.
	.
	.
	*if word#1 = 9
		*set number_word "ninety"
		*set number_length -1
		*set number -90
		*goto next

label next

*if number_length = 1
	*if number = 1
		*set number_word2 "one"
		*goto words
	*if number = 2
		*set number_word2 "two"
		*goto words
	.
	.
	.
	*if number = 9
		*set number_word2 "nine"
		*goto words

label teens
*set number_word1 ""
*if number = 10
	*set number_word2 "ten"
	*goto words
.
.
.
*if number = 19
	*set number_word2 "nineteen"
	*goto words

label words
*temp number_word3 "${number_word1}-${number_word2}