The basics
How to make a chatbot with Elizascript
Hi there! Let's make a chatbot!
Elizascript is an online tool for making really simple chatbots. And I mean really simple - this isn't the tool for you if you wanna make convincing human simulations. But if you wanna make simple, easy to write, easily shareable chatbots for fun? Maybe you'll get something out of this!
Let's start with a basic example! Copy this code into the
Elizascript editor:
Hello, is anyone there?
Testing! Can anyone hear me?
Speak up, I can't hear you!
HELLO! HELLO!
|
Click the button above the editor, and you should get a chatbot that sounds something like this:
Testing! Can anyone hear me?
> hey!
Hello, is anyone there?
> hey I'm here!
Speak up, I can't hear you!
> :(
|
Elizascript works by building a list of possible things to say, and choosing one at random. So, in this example, it just picks one of those four phrases to say, regardless of what you type.
Responding to what you type:
Well, that's a start, but it's not much of a chatbot if it can't respond to what you're saying. Let's add a response!
Try copying this code into the editor:
That's interesting.
Tell me more about that.
"feel"{
Why do you feel that way?
}
|
Which will generate a chatbot that looks something like this:
Tell me more about that.
> Sometimes I feel like you're not even listening to me...
Why do you feel that way?
> You keep saying that the things I say are interesting!
That's interesting.
> :(
That's interesting.
|
If Elizascript sees "quotation marks" in a line in the script, that means it's a response from the user. It checks what you typed to see if that word is in it - if it is, it includes everything inside the curly braces ("{" and "}") as a possible thing to say.
In the case above, we typed
"Sometimes I feel like you're not even listening to me...", which contained the word
"feel". Which is why we got the response
"Why do you feel that way?"
A more complicated example:
Here's another example. Try talking to this chatbot:
But are you really sure?
"don't", "can't"{
This is really important!
Take your time, I want you to be sure...
}
"no"{
Oh! Please don't say that!
You can't mean that!
}
"yes", "yep"{
I'm so glad you think so!
Oh, good! Are you absolutely sure?
}
|
Here's what that chatbot sounds like:
But are you really sure?
> I don't know...
Take your time, I want you to be sure...
> Ok...
But are you really sure?
> Ok, I've decided, yes!
Oh, good! Are you absolutely sure?
> Yes!
Oh, good! Are you absolutely sure?
> ...
|
Ok, let's step through that one line at a time. When the chatbot starts, we haven't said anything, so there's nothing to match. That means it goes through the code, and makes this list of things to say, which as it turns out, just contains this one thing:
We responded with
"I don't know...". So, Elizascript goes through the code again, and comes to this bit:
"don't", "can't"{
This is really important!
Take your time, I want you to be sure...
}
|
It matches for
"don't", so it starts reading from here, with an empty list, and adds these two phrases to the list of things to say and picks one.
Alright, let's move on to one last thing: branches.
Conversation branches:
A lot of the time, you'll want your chatbot to ask questions that you directly respond to. You can do this by just grouping things together with curly braces, { and }. For example:
Yep, for sure!
Uh huh!
Hey, how are you?{
"ok", "not bad"{
Cool cool.
}
"not", "bad"{
Oh no :(
}
"good", "great"{
Yay, I'm glad!
}
Ah, ok.
}
|
In this case, after maybe saying
Uh huh! and
Yep, for sure! a few times, the chatbot will eventually ask you how you are. Then, and only then, you can respond directly to the question.
When you have a conversation branch like this, here's what happens:
- Elizascript chooses to say "Hey, how are you?"
- Next time, the script starts from INSIDE that branch.
- If for some reason it can't find something to say, it goes back to the start. In this case, though, it always falls back to Ah, ok..
That's the basics covered! Eliza script has a few more tricks up its sleeve, but this should be enough to get started with!
Fancy Stuff
Fancy Stuff:
There are a few more complicated things you can do with your script, if you like. For example!
Hashtag Settings:
You can customize the way Elizascript looks by using special hashtag statements! Here's an example with a dark background and green text.
#backcol 000000
#playercol 22CC22
#botcol 00FF00
Enter your password to login:{
"banana"{
Password correct. Welcome back, Mr. Kong.
}
Error! Password incorrect!
}
|
You can also use tags to add a splashscreen to your chatbot for when you share it online. For example:
#title Talking to a three year old
#author Daniel Rosenfeld
Why?
|
If you wanna make things feel more like a real chatbot, there are a few settings for that too.
#chatsound 0
#typespeed 4
#botname webdude
#showname
lol
a/s/l?
|
You can find a full list of hashtags on the reference tab.
Flags:
Flags are variables that are either true or false. They work a little differently from conversation branches. This script creates a chatbot who changes what they talk about when you say the secret code phrase:
[!secretagent]{
(whistles)
Ho hum.
Nice day, isn't it?
"the sparrow nests too close to the ground"{
Ah, Agent Wilson. Do you have the documents? [secretagent]
}
}
[secretagent]{
Were you followed?
We need to remain vigilant.
Time is not on our side, Agent Wilson.
}
|
This is a bit confusing, but basically, flags and conversation branches work differently.
- Conversation branches are like functions - they start and end inside their brackets.
- Flags are more like IF statements - if a flag matches, everything inside the brackets is included in the current branch.
To check if a flag is set:
[test]{
The flag TEST is set!
}
|
To check if a flag is NOT set:
[!test]{
The flag TEST is not set!
}
|
To set a flag true or false:
Setting TEST to true! [test]
Setting TEST to false! [!test]
|
There are two special flags:
"start", and
"end".
"start" is true in the first line, and then automatically set to false. When you set the
"end" to true, the chatbot stops taking input.
[start]{
This will appear at the very start only.
}
[!start]{
This will only appear after the first thing was said.
This will be the last thing said. [end]
}
|
Advanced hashtag Settings:
So the
really cool thing about hash tag settings is that they don't just have to be at the top of your script - they can be updated in any branch. For example, this script has two different people taking turns to ask you questions:
[start]{
(your friends approach) [friend1]
}
[friend1]{
#chatsound 27
#botcol FF0000
#typespeed 4
Hey hey! You're back! [friend2] [!friend1]
How was it? [friend2] [!friend1]
Well? What happened? [friend2] [!friend1]
}
[friend2]{
#chatsound 62
#botcol FF88FF
#typespeed 2
Tell us everything! [friend1] [!friend2]
Did everything go well? [friend1] [!friend2]
OMG I'm so excited! [friend1] [!friend2]
}
|
A really useful hashtag is
#next, which skips the player response so that the bot can say two things in a row. Here's the same script as before with your friends not giving you a chance to talk:
[start]{
(your friends approach) [friend1]
}
[friend1]{
#chatsound 27
#botcol FF0000
#typespeed 4
#next
Hey hey! You're back! [friend2] [!friend1]
How was it? [friend2] [!friend1]
Well? What happened? [friend2] [!friend1]
}
[friend2]{
#chatsound 62
#botcol FF88FF
#typespeed 2
#next
Tell us everything! [friend1] [!friend2]
Did everything go well? [friend1] [!friend2]
OMG I'm so excited! [friend1] [!friend2]
}
|
Hashtags need to appear as the only thing on their line - not at the end of a phrase, for example. And each hashtag only runs once per branch - think of them as changing a setting, rather than doing a thing. The only exception to that is the
#break hashtag, which ends a branch early.
#break is really only useful if you're making a very big, very complicated thing. Not recommended!
Other things:
If you like, you can embed Elizascript on your own site! Just
download the .swf file from here (right click, save as). If Elizascript is running from a site other than this one, it tries to load the scripts from a local file instead, "script.txt". You can also run it offline this way if you want.
Elizascript is open source under an MIT licence. Feel free to reimplement it in your own projects!
Talk to Liz:
For more help,
maybe try talking to Liz?
Reference Guide
Reference Guide:
Basic Operation:
Making a list of things to say:
Responding to input:
"music", "games", "movies", "tv"{
Oh, I'm into that stuff too! Cool!
}
|
Branching conversations - branches and responses are like functions: the script starts reading from the start point, and ignores stuff outside the brackets.
Are you sure about this?{
"yes"{
Ok, I trust you.
}
"no"{
Yeah, me either.
}
}
|
Flags work like IF statements. If a flag test is true, then it's included in the CURRENT branch:
[music]{ So what kinda music do you like? }
[games]{ So what kinda games do you like? }
[games], [music]{ Do you have a favourite videogame soundtrack? }
[!games]{
[!music]{
So, what are you into?{
"music"{
Oh, you like music? [music]
}
"game"{
Oh, you like games? [games]
}
I don't know anything about that, sorry :(
}
}
}
|
There are two special flags -
[start] and
[end].
[start] is true for the very first statement only, and then automatically set to false. When you set
[end] to true, the chatbot stops taking input.
Hashtag settings:
You can use hashtags to change settings inside any branch. Here's the full list:
//Add credits to the chatbot.
//If title is set, a splashscreen appears before the chatbot starts.
#title My chatbot
#author Eliza
#website www.elizascript.net
//Set the player text colour.
#playercol FFFFFF
//Set the chatbot text colour. You might want to change this during chat
//if you want to make it seem like you're talking to more than one person!
#botcol FFFFFF
//Set the background colour.
#backcol FFFFFF
//Adds a delay to the chatbot, and writes "is typing" in the corner.
//Lower numbers are faster. 0 is instant. Default is 0.
#typespeed 4
//Names the bot. The name appears while the "is typing" message appears.
#botname Eliza
//If a bot name is set, you can have it be shown in front of their reply.
#showname
#hidename
//Shows a > cursor in front of the player while they're typing. Off by default.
#showcursor
#hidecursor
//Skips the player response. Useful for making the chatbot say a
//series of things all at once.
#next
//Makes the player have to press ENTER to continue. Good for intros, etc.
#presskey
//Clears the screen before printing the reply.
#cls
#clear
//Delays response by X frames. 60 frames is one second.
#delay 60
//Changes the sound that plays when the bot responds.
//The number can be anything from 0 - 67. Full list is below!
//By default, no sound plays.
#chatsound 0
//Plays a sound, for this reponse only.
//The number can be anything from 0 - 67. Full list is below!
//If there's a chatsound set, this plays instead for this single response.
#sound 33
//Stops reading from this point. Useful for simplifying flags!
#break
|
Sound effects:
Elizascript's sound bank is from MSN Messenger and Klik & Play! Here's the full list:
0 MSN Message
1 MSN Online
2 MSN New Email
3 MSN Alert
4 MSN Nudge
5 MSN Alert 2
6 MSN Ring
7 KNP Message
8 BABELEPH.mp3
9 BABYCRY4.mp3
10 BEE.mp3
11 BELCH1.mp3
12 BELCH2.mp3
13 BIRD2.mp3
14 BLAHST.mp3
15 COUGHFEM.mp3
16 CROW2.mp3
17 DOGBARK2.mp3
18 EEK.mp3
19 EXERT1.mp3
20 EXERT2.mp3
21 G'BYE.mp3
22 GAMEON.mp3
23 GOTLUCKY.mp3
24 HEART1.mp3
25 HELP.mp3
26 HICCUP.mp3
27 KISSMACK.mp3
28 KISSMALE.mp3
29 KOFF.mp3
30 LAUGHHI.mp3
31 LAUGHING.mp3
32 NGH.mp3
33 NYAAH.mp3
34 NYUUAH.mp3
35 OH.mp3
36 OH2.mp3
37 OHFEMALE.mp3
38 OHMALE.mp3
39 OOH.mp3
40 OOOH.mp3
41 ORF.mp3
42 OUCH.mp3
43 PARROT.mp3
44 POOT1.mp3
45 PULSE.mp3
46 QUACK1.mp3
47 RASPERRY.mp3
48 RUDE.mp3
49 SCREAMM1.mp3
50 SCREECH.mp3
51 SIGH.mp3
52 SIRENWOW.mp3
53 SNEEZE.mp3
54 SPIT.mp3
55 TSKTSK.mp3
56 UH-OH1.mp3
57 UHOH.mp3
58 VOICEHI.mp3
59 WARBLELO.mp3
60 WHISTLE.mp3
61 WHISTLE1.mp3
62 WHOA.mp3
63 WHOOPS.mp3
64 YEARGH.mp3
65 YO.mp3
66 YOULOSE.mp3
|
(Courtesy of Josh Minor, here's
a handy little script to try them out!)