⌘K

Functions

Updated 30 Mar 2026

String functions

All string functions accept a string as the first argument and return a value usable in any expression.

FunctionReturnsDescription
len(str)numberLength of the string
upper(str)stringConvert to upper-case
lower(str)stringConvert to lower-case
trim(str)stringRemove leading/trailing whitespace
substr(str, start)stringSubstring from index
substr(str, start, end)stringSubstring between indices
replace(str, old, new)stringReplace all occurrences
contains(str, search)booleanTrue if str contains search
startswith(str, prefix)booleanTrue if str starts with prefix
endswith(str, suffix)booleanTrue if str ends with suffix
split(str, delim, index)stringSplit by delimiter, return element at index (0-based)
indexof(str, search)numberIndex of search in str, or -1 if not found
set $msg = "Hello, World!"
send len($msg) to player
send upper($msg) to player
set $first = split($msg, ",", 0)
set $pos   = indexof($msg, "World")

Math functions

FunctionReturnsDescription
abs(n)numberAbsolute value
floor(n)integerRound down
ceil(n)integerRound up
round(n)integerRound to nearest
min(a, b)numberSmaller of two values
max(a, b)numberLarger of two values
sqrt(n)numberSquare root
pow(base, exp)numberExponentiation
random(lo, hi)integerRandom integer in range (inclusive)
set $r = random(1, 100)
set $hp = round(player.health)
send "HP: $hp / 20" to player

Utility functions

FunctionReturnsDescription
isnumber(value)booleanTrue if value can be parsed as a number
format(number, decimals)stringFormat number with N decimal places
command /pay:
    if isnumber($arg1) == false:
        send "&cUsage: /pay <amount>" to player
        return
    set $label = format($arg1, 2)
    send "&6Amount: &e$label coins" to player

online()

Return the number of players currently online.

set $count = online()
send "There are $count players online." to player

world()

Return the name of the player's current world.

set $w = world()
send "You are in: $w" to player

hasPermission(node)

Return true if the player has the given permission node, false otherwise.

if hasPermission("myserver.vip") == true:
    send "&6Welcome, VIP!" to player
else:
    send "&7Hello, player." to player

health()

Return the player's current health (0 – 20).

set $hp = health()
send "Your health: $hp / 20" to player

food()

Return the player's current food level (0 – 20).

set $hunger = food()
if $hunger < 10:
    send "&cYou are hungry!" to player

nearby(radius)

Return the count of players within radius blocks.

set $count = nearby(20)
send "Players within 20 blocks: $count" to player

level()

Return the player's current XP level.

set $lv = level()
send "You are level $lv" to player

gamemode()

Return the player's game mode as a lowercase string (survival, creative, etc.).

set $gm = gamemode()
if $gm == "creative":
    send "&bCreative mode active" to player

formattime(seconds)

Convert seconds into a readable string like 1h 5m 30s.

set $pretty = formattime(3750)
send "Time: $pretty" to player

isop()

Return true if the player is a server operator.

if isop() == true:
    send "&c[OP] You have operator privileges." to player

x()

Return the player's current block X coordinate.

set $px = x()
send "Your X position is $px" to player

y()

Return the player's current block Y coordinate.

set $py = y()
if $py < 0:
    send "&cYou are in the deep dark!" to player

z()

Return the player's current block Z coordinate.

command /coords:
    set $cx = x()
    set $cy = y()
    set $cz = z()
    send "&aCoords: X=$cx Y=$cy Z=$cz" to player