I am trying to create a topic that handles requests/commands to count. Here is my sample code so far for others to use in their ChatScript chatbots. Please let me know if you have any suggestions for improvements. Is there a function to output numbers as text, such as displaying 1 as one, 2 as two, etc.? Currently the output is in numbers.
concept: ~CountCommands ( count countdown enumerate list tell say )
concept: ~CountMultiples ( zeroes ones twos threes fours fives sixes sevens eights nines tens )
topic: ~CountFromTo keep repeat ( ~CountCommands ~numbers)
u: ( * ) $$countdirection = forwards $$countstep = 1 _0 = null _1 = null
u: ( by _~CountMultiples ) $$countstep = ^find(~CountMultiples ‘_0)
if ( $$countstep = 0 ) { [Really? ][Not happening. ][Tricky. ] You cannot count by zeroes. }
u: ( [ in by ] multiples of _~number ) $$countstep = _0
if ( $$countstep = 0 ) { [Zero is not a multiple.][Right, zero is a multiple, good one.][You first] }
u: ( [backwards descending down countdown] ) $$countdirection = backwards
u: ( << ~CountCommands >> from {the}{number} _~number * to {the}{number} _~number )
^reuse(COUNT_FROM_TO)
u: ( << ~CountCommands >> between * _~number * _~number )
^reuse(COUNT_FROM_TO)
u: ( << ~CountCommands >> _~number * [get reach until to ] * _~number ) ^reuse(COUNT_FROM_TO)
u: ( << ~CountCommands >> to {the}{number} _~number )
^reuse(COUNT_FROM_TO)
u: ( << ~CountCommands >> [start begin] * [at with] _~number and [end stop] [at with] _~number )
^reuse(COUNT_FROM_TO)
s: COUNT_FROM_TO (?)
$$x = _0
$$y = _1
#——- Figure range if only one number supplied——-
if ( _1 == null AND $$x > 0 ) { $$y = $$x $$x = $$countstep }
else if ( _1 == null AND $$x < 0 ) { $$y = $$x $$x = $$countstep * -1 }
#——-swap x an y if count direction is backwards——- if ( $$countdirecti and $$y > $$x and $$y > 0 ) {
$$temp = $$x
$$x = $$y
$$y = $$temp
}
#——- set count direction to backwards if implied by first number being larger than second——-
if ( $$x > $$y ) {
$$countdirection = backwards
$$countstep = $$countstep * -1}
#——- calculate the number of numbers to be output——-
$$CountRange = $$y - $$x / $$countstep
#——- handle output where countrange exceeds maxcount, set maxcount to a reasonable number——-
#——- how many numbers would a human humor a questioner with?——-
$$maxcount = 12
if ( $$CountRange > $$maxcount ) {
$$limit = $$maxcount * $$countstep - $$countstep
if ( $$countstep < 0 ) { $$y = $$x - $$limit } else { $$y = $$x + $$limit }
[I’m not going to count that many numbers!][Give me a break.][Sorry, I don’t have all day. ] The first $$maxcount are:
}
Else {
# ----- generate random response -----
$$EndPunct = .
[][][][][]
[Like $$EndPunct = ? ]
[Like this $$EndPunct = ? ]
[Do you mean like $$EndPunct = ? ]
[Such as $$EndPunct = ? ]
[As in $$EndPunct = ? ]
[Ta da! ]
[You only ask me that because you think I am not human. ]
[Easy. ][Presto ][You want me to count? ]
[Boring. If you want to know if I am human then ask me about my feelings. \n]
}
#——- loop through numbers——-
$countnum = $$x
$countnum
^loop () {
$countnum = $countnum + $$countstep
if ( $$countstep > 0 and $countnum > $$y ) {end(LOOP)}
if ( $$countstep < 0 and $countnum < $$y ) {end(LOOP)}
$countnum
}
$$EndPunct