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!

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:

But are you really sure?

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:

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:

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.

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: