The language
How to write a mini-script: lines, values, statements, conditions, functions and texts in four languages.
Lines and blocks
- Write one statement per line.
#starts a comment. - Spaces and indentation do not matter, so indent as you like.
- Every block ends with
end. - Words are read without case (
Ifisif). Texts keep their case.
A file holds uses and text lines and the blocks that start something, such as command, on and every.
A script pasted from a chat, a forum or an AI answer keeps its meaning even if its spaces change, because end closes the blocks. A missing end is reported on the line that opened the block: "The if opened on line 8 has no end."
Values
- Numbers:
3,2.5. - Texts:
"Hello {name(player)}!". Braces hold any expression,{{and}}write a brace, and\",\\and\nare the escapes. true,falseandnone.- Lists:
[1, 2, "a"]. A list cannot hold a list. - Colour codes such as
&aand&cwork in texts sent to players.
Variables and saved values
xis a variable of this run only. Give it a value before you read it.server.xis saved for the whole server.player.xis saved for that player. So is<variable>.xwhen the variable holds a player.- Saved values stay across reloads and restarts.
- A player or a translated text cannot be saved. Save the name or the text.
Values from events
A block gets values from what started it:
Value | Where | What it holds |
|---|---|---|
| every block except timers | The player. In a command, who typed it (none from the console). |
| commands | Who ran the command. |
| chat | The chat line. |
| break, place, interact | The block and its place. |
| interact | For example |
| world change | The two worlds. |
| arrive | The server the player came from and the text sent with them (or none). |
| move failed | Why the move failed. |
You cannot change these values, and a command argument cannot use their names. A command's arguments are variables with their own names. Model item blocks have their own values.
These words belong to the language and cannot be names: and, or, not, is, has, contains, to, from, in, true, false, none, end, else, if, set, add, remove, delete, repeat, for, each, while, times, wait, stop, cancel, break, continue, server, permission and online.
Statements
Change variables
set x to <value>add <value> to xadds a number, puts an item in a list or extends a text.remove <value> from xsubtracts a number or takes an item from a list.delete x
Choose and repeat
if <condition>,else if <condition>,elseandend.repeat <n> timesruns up to 10,000 times.for each p in <list>runs once per item.players()is every player online.while <condition>runs up to 10,000 rounds.breakleaves a loop,continuegoes to the next round andstopends the block.
Wait and cancel
wait <n> ticks,secondsorminutespauses for up to one hour. The rest of the block runs later.cancelstops the event (chat, break, place or interact). It comes before anywait.
Act in the game
message <text> [to <player>]sends a chat line. Withoutto, it goes to the block's player, or to whoever ran the command.title <text> [subtitle <text>] [to <player>]andactionbar <text> [to <player>]show text on the screen.sound "<key>" [to <player>]plays a game sound, such as"entity.experience_orb.pickup".broadcast <text>sends a line to every player.teleport [<player>] to <location>also works into another world.give [<n>] <item> [to <player>]gives items, for examplegive 3 diamond. What does not fit in the inventory is not given.take [<n>] <item> [from <player>]takes items.gamemode survival,creative,adventureorspectator, optionallyfor <player>.console "<command>"runs a console command that youruses console(...)line names.log <text>writes a line to the server's console.movesends players to a sub-server.
Most of these need a permission.
Conditions and operators
- Compare with
=(oris),!=(oris not),<,<=,>and>=. Text comparisons ignore case. - Join conditions with
and,orandnot. containsfinds a text in a text or an item in a list.- Calculate with
+ - * / %.+also joins texts. <player> has permission "<node>"<player> has [<n>] <item><player> is in world "<name>"<player> is online
In an if, false, none, 0, an empty text and an empty list count as no. Everything else counts as yes.
Functions
- Players:
name(p),online(name)(a player, or none),players([world]),gamemode(p)andcount(p, "item"). - Places:
world(p)(also of a location),location(p),location(x, y, z[, world]),spawn([world]),main_world(),world_exists(name),x(loc),y(loc)andz(loc). - Numbers:
random(a, b),round,floor,ceil,abs,min(a, b),max(a, b)andnumber(text)(none when the text is not a number). - Texts and lists:
length(text or list),lower,upperandtext(x). - Translated texts:
lang("key", values...).
Texts in four languages
A text block holds one message in English (en), Spanish (es) and Turkish (tr). English is required. {0} and {1} stand for the values you hand to lang.
text welcome
en "&eWelcome, {0}!"
es "&e¡Bienvenido, {0}!"
tr "&eHoş geldin, {0}!"
endlang("welcome", name(player)) shows the text in the language of the player who reads it. A language you leave out shows the English text.
Use lang(...) on its own. Joined with other text, it shows the English line.