Scripting help
Using @variables to remember
Remember numbers, words, yes and no in @variables, ask the hero a question, and build a quest across two villagers.
A @variable remembers a number, some words, yes or no, or a thing, like a character or a door. Its name starts with @, then letters, numbers and _, like @count, @answer or @met_the_wizard.
Every character in the game shares the same variables, in every world, so one villager can check what another remembered. Variables last through doors, worlds, the hero being beaten and Try again. They are only forgotten when a new game starts, or with From start.
| To do this | Write |
|---|---|
| Remember something | @count is 0@name is "Bob"@door_open is yes |
| Copy another variable | @best is @count |
| Change a number | @count goes up by 1@count goes down by 1 |
| Check yes or no | if @door_open is yesOr just if @door_open. |
| Check words | if @name is "Bob"Big or small letters don't matter. |
| Check a number | if @count is at least 3You can also use under, over and at most. |
| Do math | @total is (@count + 1) * 2See Doing math. |
| Show a variable | Put it in say, show or ask words:say "You have helped @count times!" |
is both sets a variable and checks one. Where the line is tells you which:
| Line | What is does |
|---|---|
@count is 0 | Sets it, as a step of its own. |
if @count is 0 | Checks it. So does a when line, or whether. |
my size is 150% | Sets a setting. Settings work the same way. |
To check, put if in front. @count is at least 3 on its own isn't a step, so the script says to write if @count is at least 3. equals only ever checks, so @count equals 3 on its own isn't a step either.
A variable that nothing has set yet holds nothing. Next to a number it counts as 0, so if @count is 0 is true before anything sets it.
A game can have up to 100 variables, each holding up to 60 letters.
Yes, no and nothing
yes and no are values of their own, for things that are true or not, like whether a door is open. Write them without quotes. nothing is what a variable holds before anything sets it.
| To do this | Write |
|---|---|
| Remember yes or no | @door_open is yes |
| Check it | if @door_open is yes |
| Check it, the short way | if @door_open |
| Check the opposite | if not @door_open |
| Remember a check | @seen is whether I see the {Hero} |
| Clear a variable | @key is nothing |
| Check it was never set | if @key is nothing |
if @door_open on its own is true only when it holds yes. So if not @door_open is true when it holds no, nothing, or anything else.
whether works with any check an if can make. The check is made when the line runs, and the variable keeps the answer, yes or no, until something sets it again.
| Good to know | What happens |
|---|---|
yes and "yes" | Not the same. yes is the value; "yes" is words in quotes. |
0 and nothing | Not the same. if @count is nothing is false when @count is 0. |
Yes or no in say | Shows as yes or no. Nothing shows as no words at all. |
Lists
A @variable can hold a list: lots of words, or lots of numbers, in order. Write the values with commas between them. You can put and before the last one, like you would in a sentence.
This script makes a list of three months, adds a fourth, and goes through them one at a time. Press Run to see what it logs.
Writing a list
| Write | What the variable holds |
|---|---|
@months is "Jan", "Feb", "Mar" | A list of words. |
@months is "Jan", "Feb" and "Mar" | The same list. and before the last value is fine. |
@scores is 10, 20, 30 | A list of numbers. |
@names is @first, @second | A list of what each @variable holds now. |
@pets is {Cat}, {Dog} | A list of things. See Remembering things. |
@months starts at "Jan", "Feb" | A list the game starts with, at the top of the game script. |
my @lines is "Hi", "Bye" | A list of a character's own, at the top of its script. |
A list keeps one kind of value: all words, all numbers, or all things. Once a list has a value in it, add and set item won't put in another kind. Yes, no and nothing can't go in a list. A list at the top of a script is written out in full, so it can't have @variables in it.
say "@months" shows a list as you'd write it in a sentence, like "Jan, Feb and Mar".
Starting with an empty list
Sometimes a list starts with nothing in it, and fills up as the game goes on. Write a list for a list with no values yet. Say what it will hold, like a list of words, and you'll get a yellow note if something else goes in.
| Write | What the variable holds |
|---|---|
@picked is a list | A list with nothing in it. What you add first says its kind. |
@picked is an empty list | The same. |
@picked is a list of words | A list of words with nothing in it yet. |
@scores is a list of numbers | A list of numbers with nothing in it yet. |
@pets is a list of things | A list of things. characters, objects, blocks, levels, worlds and places work too. |
my @lines is a list of words | A character's own empty list, at the top of its script. |
@found starts at a list of numbers | An empty list the game starts with, at the top of the game script. |
An empty list is not the same as nothing. if @picked is empty is true for both, so that's the check to use. Inside words, like say "You have @picked", an empty list shows as nothing at all.
Using a list
| Write | What it does |
|---|---|
repeat for @month in @months | Goes through the list, one value at a time, as @month. |
repeat for @number, @month in @months | The same, with @number as the value's place: 1, then 2, and so on. |
@month is item 2 of @months | The second value. item 1 is the first. |
@size is the number of @months | How many values the list has. |
@pick is a random one of @months | One of the values, picked at random. |
add "Apr" to @months | Puts a value on the end of the list. |
remove "Jan" from @months | Takes the first value that matches out of the list. |
set item 2 of @months to "Feb" | Changes the second value to "Feb". The place can be a @variable. |
Repeating has more about going through a list.
Checking a list
| Check | It's true when |
|---|---|
if "Feb" is in @months | The list has "Feb" in it. Capitals don't matter. |
if "May" is not in @months | The list doesn't have "May" in it. |
if @months is empty | The list has nothing in it, or the variable holds nothing. |
if the number of @months is 3 | The list has 3 values. |
Random lines for a character
A list is a good way to give a character lots of things to say. Pick one at random, and then say it.
Each time this character sees the hero, it says one of its jokes.
Good to know
| When | What happens |
|---|---|
| You add to a @variable that holds nothing | It becomes a list with that one value. |
| You add a list | Every value in it goes on the end. |
| The list has 200 values | That's as many as a list holds. Adding more does nothing, and the script log says so. |
| You ask for an item past the end | You get nothing, and the script log says so. |
| You set an item past the end | Nothing changes, and the script log says so. Use add to put a value on the end. |
| You remove a value that isn't there | Nothing changes, and the script log says so. |
| Words in a list are long | Each one is cut to 60 letters, like any words a @variable holds. |
| A list is shared | Like any @variable, every character uses the same list, until a new game starts. |
Remembering things
A @variable can remember a thing too: a character, a door, a block, a level, or the game. Write the thing's ID after is, and the variable holds that thing. A family's name gives a list of everything in the family.
| Write | What the variable holds |
|---|---|
@boss is {Slime King} | The thing with that ID. |
@ghosts is {Ghosts} | A list of the family in the hero's level, top row first, then left to right. |
@who is me | The character whose script it is. In the hero script, the hero. |
@last is {this one} | The one a `repeat all` is on. |
@sender is {trigger id} | The thing that sent the trigger. |
@game is {Game} | The game itself. |
say "@ghosts" shows the things by their IDs, like "Slimy, Boo and Slimy". A thing with no ID shows what it is, like "Enemy".
Using a thing you remembered
A @variable that holds a thing goes where its ID would go, in steps and checks. It can't go in a when line.
| Write | What it does |
|---|---|
hide @boss | Hides the thing the variable holds. |
@boss attack | Tells it what to do, as {Slime King} attack would. |
all @ghosts attack | Tells every thing in the list. The script waits until they're done. |
open all @doors | Does the step to every thing in the list. |
repeat all @ghosts | Goes through the list, one at a time. |
To tell every thing in a list to do a step, put all in front, like a family's name. hide @ghosts gets a red note that offers hide all @ghosts. all works on one thing too. Going through a list with repeat for @ghost in @ghosts needs no all.
Checking things
| Check | It's true when |
|---|---|
if @target is {Baker} | The variable holds the Baker. |
if @door is locked | The door it holds is locked. |
if all @doors are locked | Every door in the list is locked. |
if any @guards is near me | At least one guard in the list is near. |
if @slimy is in @ghosts | The list holds that thing. is in {Ghosts} checks a family. |
A list with nothing in it is never "all", and never "any". not all @doors are locked is true when at least one isn't locked. all @doors are not locked is true when none of them are.
One kind of value
A @variable keeps one kind of value, wherever in the game it's set. If one line sets @door to a door and another sets it to words, both lines get a warning that says where the other one is. @coins starts at 0 in the game script says what kind it is for the whole game.
| Kind | Like |
|---|---|
| A number | @count is 3 |
| Words | @name is "Bob" |
| Yes or no | @door_open is yes |
| A thing | @boss is {Slime King} |
| A list of things | @ghosts is {Ghosts} |
| A list of words | @months is "Jan", "Feb" |
| A list of numbers | @scores is 10, 20 |
| Anything | An ask whose answers mix yes, no and words. |
Setting a variable to nothing never changes its kind. A thing can't go in math, and a step a thing can't do gets a red note, like open @baker when the Baker is a villager.
Good to know
| When | What happens |
|---|---|
| The thing is beaten, or in another level | Steps skip it. The variable keeps it, for when the hero goes back. |
| The thing was taken off the map in the builder | The variable holds nothing, and the thing drops out of a list. |
| Try again, or the hero loses a life | The variable still holds the same thing, as it was placed on the map. |
| A family's list | It's the family as it was when the line ran: one that turns up later isn't in it. |
Doing math
A value can be worked out with math. Use +, -, * for times and / for divide, with brackets round the part to do first.
when the {Hero} talks to me
@total is (@apples + @pears) * 2
say "That's @total coins."Times and divide are worked out before plus and minus, so 1 + 2 * 3 is 7. Brackets change that: (1 + 2) * 3 is 9.
Try it here. Press Run, and the log beside the script shows the answers. Change the numbers and run it again.
| Where math can go | Write it like |
|---|---|
| Setting a variable | @total is @price * 2 |
| Going up and down | @score goes up by @bonus * 2 |
| A character's own | my @range is 2 + 3 |
| A starting value | @goal starts at 5 * 2 |
| A function's values | dash with @far + 1, 2 |
| Giving back | give back @a + @b |
| Checking | if @score + 1 is over @best |
| Where things are | @next is my row + 1 |
| A step's numbers | move left @far + 1 blocks |
| A setting | my opacity is my opacity - 10 |
| How many times | repeat @rounds * 2 times |
| Good to know | What happens |
|---|---|
| Dividing by 0 | Gives 0. The script log says so. |
| Words in math | Math is for numbers. Words that are a number, like "12", count as that number. Other words, yes, no and nothing count as 0. |
| Joining words | Math can't. Use code in words: @both is "(@first) (@second)". |
| A minus sign | @a - 3, @a-3 and @a -3 all take 3 away. @a * -3 is times minus 3. |
| Long sums | The answer is rounded to 6 places after the dot. |
Writing @ and quote marks in words
To write a plain @, a quote mark or a backslash in words, put a \ before it.
| You write | The game shows |
|---|---|
say "Mail me \@ the castle" | Mail me @ the castle |
say "She said \"hi\"" | She said "hi" |
say "I \shared @pie" | I shared apple, when @pie is "apple" |
A plain shared needs the \ only right before a @variable: see the game's @variable with the same name.
A random number
@roll is a random number from 1 to 100 picks a whole number from 1 to 100, both ends included, and remembers it in @roll. Either end can be a @variable, like from 1 to @sides.
The number stays the same until something sets @roll again. So you can roll once and check it more than once, which separate chances can't do:
when the {Hero} talks to me
@roll is a random number from 1 to 100
if @roll is under 50
say "Hello!"
else if @roll is under 80
say "Hi there."
else
say "Go away!"
endEvery player in an online game gets the same number.
Built-in functions
Splat Script has some functions of its own. Each one works out a value, like today's date or the bigger of two numbers. Use one where a value goes, like after @total is.
Press Run to see what each one gives back.
| Write it like | What you get |
|---|---|
@today is the date | Today's date in words, like 16 November 2026 |
@day is the day | The day of the month, from 1 to 31 |
@month is the month | The month as a number: 1 is January, 12 is December |
@year is the year | The year, like 2026 |
@day is the day of the week | 1 is Monday, 7 is Sunday |
@hour is the hour | The hour of the day, from 0 (midnight) to 23 |
@word is a random one of "a", "b", "c" | One of them, picked at random |
@word is a random one of @words | One of a list, picked at random |
@ghost is a random one of {Ghosts} | One of a family, picked at random |
@month is item 2 of @months | The second value in a list |
@size is the number of @months | How many values a list has |
@x is replace "cat" with "dog" in @words | The words with every "cat" swapped for "dog" |
@length is the number of letters in @name | How many letters, spaces too |
@best is the bigger of @score, @best | The biggest of two or more numbers |
@least is the smaller of @a, @b | The smallest of two or more numbers |
@left is the remainder of @count / 3 | What's left over after dividing |
| Good to know | What happens |
|---|---|
| In checks | On either side: if the day of the week is 6, if @best is the bigger of @a, @b. |
| In brackets | Put one in brackets to use it in math: @x is (the bigger of @a, @b) + 1. |
| Commas and "and" | Values go with commas between them, and and before the last one is fine: the bigger of 3, 9 and 4. |
| "and" in a check | if the bigger of 3, 9 and 4 is 9 works. After is, an and with a @variable after it joins a second check, so write if @n is the bigger of 3, 9, @a there. |
| Replacing | Capitals don't matter when it looks, so "cat" finds "Cat" too. |
| Odd and even | the remainder of @n / 2 is 0 for an even number and 1 for an odd one. |
| Online | Every player gets the same random pick, and the date and hour where the host is. |
| Your own functions | A function you make can't start with these words, like learn to replace. |
Filters
A filter changes a value. Write then after the value, and then the filter. You can add more than one, and they run in order, from left to right.
| Filter | Example | Gives |
|---|---|---|
then upper case | "hello" then upper case | HELLO |
then lower case | "HELLO" then lower case | hello |
then capitalize | "hELLO world" then capitalize | Hello World |
then reverse | "hello" then reverse | olleh |
then rounded | 7 / 2 then rounded | 4 |
then rounded up | 3.1 then rounded up | 4 |
then rounded down | 3.9 then rounded down | 3 |
Filters and math
A filter changes everything before it. So @a + @b then rounded rounds the whole sum. To change just one part, put that part in brackets: @a + (@b then rounded).
You can make filters of your own too. See Making your own filters.
Code in words
Words in quotes can have code in brackets. The code is worked out, and its answer goes in its place. The code can be a value, math, a function or a filter.
Only a bracket with @ or { right after it starts code. Any other bracket is a plain bracket, like in the second line.
| You write | You get |
|---|---|
"Hi (@name then upper case)" | Hi COOPER |
"(@apples + 1) apples" | 3 apples |
"A plain \(@name)" | A plain (cooper) |
To show a plain bracket before a @variable, put a \ in front of it, as in the last row.
Starting values
At the top of the game script, before any when line, @coins_needed starts at 10 gives a variable its value when a new game starts. If the game already has a value for it, that value is kept.
A character's own @variables
A character can have @variables of its own, and so can a level. Write them at the top of its script, before any when line, with my in front. Then use them anywhere in the script without the my.
my @range is 5
my @nap is 2
my @greeting is "Hi there!"
when I see the {Hero} within @range blocks
chase the {Hero}
say @greeting
when I lose the {Hero}
wait @nap seconds
patrol @range blocksThis is handy for a character you use in more than one game. Change a number at the top, and every line that uses it changes too.
How they work
| What | How it works |
|---|---|
| Who has them | Only that character or level. Five goblins with the same script each have their own. |
| When they're set | Each time the character starts, in the order written. They start over when it starts again. |
| Changing them | Like any variable: @range is 6, @range goes up by 1. |
Numbers in steps and when | within @range blocks and wait @nap seconds read the variable when the line runs. Shared variables work too. |
Writing my | Reading my @range anywhere else in the script means the same as @range. To change it, leave out the my. |
The game's @variable with the same name
Once a script has my @greeting, @greeting in that script means the character's own. To use the game's @greeting, write shared @greeting. It works for reading, changing and checking, and in words too: say "The game says shared @greeting".
A my line reads the game's variable if an earlier my line hasn't set one of its own. So my @original is @greeting, written above my @greeting, keeps a copy of the game's @greeting.
Another character's @variables
Another script can use a character's own @variables too. Write the character's ID, then the @variable. The 's is up to you: the {Guard} @blocks and the {Guard}'s @blocks mean the same.
when the {Hero} is near the {Old well}
if the {Guard} @blocks is 5
the {Guard}'s @blocks is 6
show "The guard can see the {Guard} @blocks blocks now"A level's own @variables work the same way, with the level's name as the ID: {Meadow} @gates. Reading or changing a character's @variable never stops what it's doing.
| What you want | Write it like |
|---|---|
| Check it | if the {Guard} @blocks is 5 |
| Change it | the {Guard} @blocks is 6 |
| Add to it | the {Guard} @blocks goes up by 1 |
| Use it in math | @total is the {Guard} @blocks + 1 |
| Show it in words | say "the {Guard} @blocks blocks" |
| A level's @variable | {Meadow} @gates |
Secret @variables
Write secret in front of my, and no other script can read or change that @variable. The character's own script uses it like any other.
my @blocks is 5
secret my @mood is "grumpy"Good to know
| When | What happens |
|---|---|
| The character is beaten, or in another level | Reading gives nothing, and changing is skipped. |
| The level isn't the one being played | The same: reading gives nothing, and changing is skipped. |
| A Platformer enemy is far from the hero | It is asleep. Until it first wakes up, it has no @variables yet. |
| More than one character has the ID | Only the first one is used. With the Script log on, it warns you once. |
| The character starts again | Its my lines run again, so its @variables go back to how they're written. |
| You name the character's own ID in its script | A tip says to write the plain @variable instead. |
Asking the hero
A villager can ask the hero who is talking to them a question. A window shows the question with a button for each answer, and play waits until the hero picks one. The answer goes into a variable.
List 2 to 6 answers, with or or commas between them. Both with yes or no and with "red", "green", "blue" work. An answer of yes or no without quotes shows as a Yes or No button and puts the yes or no value in the variable. An answer in quotes puts its words in. The villager waits for the answer before their next line.
The hero picks an answer with the arrows or the d-pad, then Enter or A. Closing the window without picking, with Escape or B, leaves nothing in the variable.
A villager can only ask the hero who is talking to them, so their question goes in when the {Hero} talks to me. In another rule, like when the {Hero} comes near, it gets a red note. A deal with offer works the same way, and so does a function of yours that asks or offers.
Game and level scripts can ask too, wherever the hero is. Their question shows with no one's picture. In a Platformer, it shows in the hint's window.
Answers from a list
The answers can come from a list. Put the list's @variable after with, on its own. Each value in the list becomes a button, and the answer is the value the hero picks.
The list can hold words or numbers. With numbers, the answer is a number, so you can do math with it.
| When | What happens |
|---|---|
| The list has more than 6 values | The first 6 are the answers. With the Script log on, it says so. |
| The list has fewer than 2 values | Nothing is asked, and the answer is nothing. With the Script log on, it says so. |
| A list is written with other answers | A red note. Write the answers in quotes, or give one list on its own. |
| The @variable holds one word or number | A red note: that's one answer, and asking needs at least 2. |
| The @variable holds a list of things | A red note: answers are words or numbers. |
Typed answers
A question can also be answered by typing, like a name or the answer to a riddle. Write the typed answer to and leave out the answers. The window shows a box to type in, and the variable gets what the hero typed.
An answer can be up to 20 letters long. To change that, give the number after with, on its own or by its name, @letters. It can be from 1 to 40.
| Written like | How many letters |
|---|---|
@name is the typed answer to "Name?" | Up to 20 |
@name is the typed answer to "Name?" with 30 | Up to 30 |
@name is the typed answer to "Name?" with @letters is 30 | Up to 30, by name |
@name is the typed answer to "Name?" with @limit | What @limit holds |
The hero types on the keyboard and presses Enter. With a gamepad, an on-screen keyboard shows under the box: move over the letters with the d-pad and press A to type one. B deletes a letter, and Done answers.
Closing the window with Escape, or with B when the box is empty, leaves nothing in the variable.
An answer to start with
@default gives the box an answer to start with. The hero can press Enter to keep it, or change it first. Closing the window, or nobody answering, keeps the default too. So the variable is never empty, as long as the default isn't empty words.
After with, the number of letters comes first and the default second. Give them in that order, or each by its name in any order.
| Written like | What it means |
|---|---|
with @default is "Hero" | Starts with "Hero", up to 20 |
with 30, "Hero" | Up to 30, starts with "Hero" |
with @letters is 30, @default is "Hero" | The same, by name |
with @default is @name | Starts with what @name holds |
A default can be a @variable, so the hero can change an answer they gave before. A default with more letters than the answer can have is cut short.
Checking a typed answer
Checks with is don't mind capitals or spaces at the ends, so "cooper " is the same as "Cooper". A number that was typed still counts as a number, so if @guess is at least 10 works.
Bad words in a typed answer are hidden with stars before the script keeps it.
Example: a quest across two villagers
The baker asks for help, and the farmer, in another world, gives the apples. Two variables carry the quest between them: @baker_asked and @baker_done.
# The baker
when the {Hero} talks to me
if @baker_done
say "Thanks for the apples!"
else if @baker_asked
say "Did you find the farmer yet?"
else
@baker_asked is the answer to "Can you fetch apples from the farmer?" with yes or no
end# The farmer
when the {Hero} talks to me
if @baker_asked and not @baker_done
give a "Sack of apples" to the {Hero}
@baker_done is yes
say "Take these to the baker!"
else
say "Lovely day for it."
end
