Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Functions

DEQUEUE · ERROR · ISERROR · POP · PUSH · QUEUE · RESOLVE · SCOPE · TYPEOF · asc · chr · count · date · exists · fps · hex · instr · join · lcase · left · len · ltrim · match · mid · oct · regex · replace · reverse · right · rtrim · space · split · str · string · time · timer · trim · ucase · uuid · val · version


DEQUEUE

Takes the first item off an array and gives it to you — the one that has waited longest. The array itself gets shorter, and nothing has to shuffle down. From an empty array I give you NULL.

DEQUEUE(list AS ARRAY)

Parameters

  • list AS ARRAY

Gives back: the item that was first, or NULL

Example

next = DEQUEUE(orders)

ERROR

Makes an error value for a function to hand back. code picks the message, and values is a map I use to fill in its {placeholders}.

ERROR(code, values = NULL)

Parameters

  • code
  • values = NULL

ISERROR

Tells you whether a value is an error: 1 if it is, 0 if not. Checking this way is safe, and it never stops the script.

ISERROR(value)

Parameters

  • value

POP

Takes the last item off an array and gives it to you. The array itself gets shorter. From an empty array I give you NULL.

POP(list AS ARRAY)

Parameters

  • list AS ARRAY

Gives back: the item that was last, or NULL

Example

last = POP(stack)

PUSH

Adds an item to the end of an array. This changes the array itself — nothing is copied, and everyone holding the array sees the new item. Gives the array back.

PUSH(list AS ARRAY, item)

Parameters

  • list AS ARRAY
  • item

Example

PUSH inventory, "rope"

QUEUE

Adds an item to the back of a line, ready to come out after everything already waiting. It’s PUSH under the name that goes with DEQUEUE. Gives the array back.

QUEUE(list AS ARRAY, item)

Parameters

  • list AS ARRAY
  • item

Example

QUEUE orders, "soup"

RESOLVE

Waits for futures and gives you their results: one value for one future, an array for several. Anything that isn’t a future I pass straight through.

RESOLVE(futures...)

Parameters

  • futures…

SCOPE

Gives you the value of the block this line is inside: what the opening function of a SCOPEBIND keyword returned. Name the keyword as a string, like SCOPE("BEHAVIOR"). I look for the innermost open block of that keyword, even from a function the block calls.

SCOPE(keyword AS STRING)

Parameters

  • keyword AS STRING

Gives back: the block’s value

TYPEOF

Tells you what type a value is, as the name you’d write after AS: "INTEGER", "STRING", "MAP", or a TYPE of yours like "Monster". NULL gives "NULL". Errors and futures are fine to ask about: I don’t stop the script for them.

TYPEOF(value)

Parameters

  • value

Gives back: the type’s name, as a string

Example

IF TYPEOF(loot) = "ARRAY" THEN PUSH loot, "gold"

asc

Returns ASCII code of first character.

asc(string_expression)

Parameters

  • string_expression - String with at least one character

Example

SCREEN 320, 240
PRINT asc("A"), asc("abc")

chr

Converts ASCII code to character.

chr(ascii_code)

Parameters

  • ascii_code - ASCII value (0-255)

Example

SCREEN 320, 240
PRINT chr(72) + chr(105)

count

Counts the number of non-overlapping occurrences of a substring within a string.

count(string, search_for)

Parameters

  • string - String to search in
  • search_for - Substring to count

Example

SCREEN 320, 240
PRINT count("banana", "a"), count("aaaa", "aa")

date

Returns the current system date as a string in MM/DD/YYYY format.

date

Example

SCREEN 320, 240
today = date
PRINT "Today is", today, LEN(today)

exists

Checks if a resource exists in the resource manager. Returns 1 if the resource exists, 0 if it does not.

exists(resource_name)

Parameters

  • resource_name - Name of the resource to check (image, sound, music, data, or text)

Example

SCREEN 320, 240
PRINT exists("hero")
LOADIMG "hero.png", "hero"
PRINT exists("hero")

fps

Returns the current frames per second as a floating-point number. Uses a smoothed average to avoid frame-to-frame jitter. Useful for adaptive performance tuning — games can check FPS and reduce visual complexity on slower devices.

fps

Example

SCREEN 320, 240
FOR i = 1 ... 5
    YIELD
END FOR
particles = 200
IF fps > 0 AND fps < 30 THEN particles = 50
PRINT "fps", round(fps), "particles", particles

hex

Converts a number to its hexadecimal string representation.

hex(number)

Parameters

  • number - Numeric value to convert (integer part used)

Example

SCREEN 320, 240
PRINT hex(255), hex(4096)

instr

Finds the 1-based position of the first occurrence of a substring within a string, in characters (not bytes), so the position can be passed straight to mid, left or right. Returns 0 if not found.

instr(string1, string2)

Parameters

  • string1 - String to search in
  • string2 - Substring to find

Example

SCREEN 320, 240
s = "hello world"
at = instr(s, "world")
PRINT at, mid(s, at), instr(s, "xyz")

join

Joins an array of strings into a single string using a delimiter.

join(array, delimiter)

Parameters

  • array - Array of strings to join
  • delimiter - Character or string to join with

Example

SCREEN 320, 240
PRINT join(["red", "green", "blue"], ", ")

lcase

Converts a string to lowercase letters.

lcase(string)

Parameters

  • string - Input string to convert

Example

SCREEN 320, 240
PRINT lcase("Hello World")

left

Returns the leftmost characters from a string.

left(string_expression, count)

Parameters

  • string_expression - Source string
  • count - Number of characters to return

Example

SCREEN 320, 240
PRINT left("Crash BASIC", 5)

len

How many items an array or a map holds, or how many characters a string has.

len(value)

Parameters

  • value

Example

SCREEN 320, 240
PRINT len("hello"), len([1, 2, 3]), len({hp: 3, mp: 5})

ltrim

Removes leading spaces from the left side of a string.

ltrim(string)

Parameters

  • string - Input string to trim

Example

SCREEN 320, 240
PRINT "[" + ltrim("   hi  ") + "]"

match

Pattern matching with wildcards. Returns 1 if match, 0 if not.

match(string, pattern)

Parameters

  • string - String to test
  • pattern - Pattern with wildcards (* = any sequence, ? = any single character)

Example

SCREEN 320, 240
PRINT match("level3.map", "level?.map"), match("hero.png", "*.wav")

mid

Returns a substring from the middle of a string.

mid(string_expression, start, length = NULL)

Parameters

  • string_expression - Source string
  • start - Starting position (1-based)
  • length = NULL - Number of characters (optional, defaults to rest of string)

Example

SCREEN 320, 240
s = "Crash BASIC"
PRINT mid(s, 7, 3), mid(s, 7)

oct

Converts a number to its octal string representation.

oct(number)

Parameters

  • number - Numeric value to convert (integer part used)

Example

SCREEN 320, 240
PRINT oct(8), oct(64)

regex

Advanced regular expression pattern matching. Returns 1 if the pattern matches, 0 if not. Matching is case-sensitive; embed an inline flag such as (?i) at the start of the pattern for case-insensitive matching. A pattern that is not a valid regular expression is a runtime error, not a 0: an answer of 0 always means the pattern is valid and did not match.

regex(string, pattern)

Parameters

  • string - String to test
  • pattern - Regular expression pattern

Example

SCREEN 320, 240
PRINT regex("player42", "^[a-z]+[0-9]+$"), regex("HELLO", "(?i)hello")

replace

Replaces all occurrences of a substring with another string.

replace(string, search_for, replace_with)

Parameters

  • string - Source string
  • search_for - Substring to find
  • replace_with - Replacement string

Example

SCREEN 320, 240
PRINT replace("I like cats and cats", "cats", "dogs")

reverse

Reverses the order of characters in a string.

reverse(string)

Parameters

  • string - String to reverse

Example

SCREEN 320, 240
PRINT reverse("stressed")

Returns the rightmost characters from a string.

right(string_expression, count)

Parameters

  • string_expression - Source string
  • count - Number of characters to return

Example

SCREEN 320, 240
PRINT right("Crash BASIC", 5)

rtrim

Removes trailing spaces from the right side of a string.

rtrim(string)

Parameters

  • string - Input string to trim

Example

SCREEN 320, 240
PRINT "[" + rtrim("  hi   ") + "]"

space

Creates a string of spaces.

space(count)

Parameters

  • count - Number of spaces to create

Example

SCREEN 320, 240
PRINT "[" + space(5) + "]"

split

Splits a string into an array using a delimiter. Returns array of strings.

split(string, delimiter)

Parameters

  • string - String to split
  • delimiter - Character or string to split on

Example

SCREEN 320, 240
parts = split("red,green,blue", ",")
PRINT LEN(parts), parts(1)

str

Converts a number to its string representation. No leading space is added for positive numbers.

str(number)

Parameters

  • number - Numeric value to convert

Example

SCREEN 320, 240
score = 42
PRINT "Score: " + str(score)

string

Creates a string by repeating a character or ASCII code.

string(count, character)

Parameters

  • count - Number of repetitions
  • character - String character or ASCII code number

Example

SCREEN 320, 240
PRINT string(5, "*"), string(3, 65)

time

Returns the current system time as a string in HH:MM:SS format.

time

Example

SCREEN 320, 240
now = time
PRINT "The time is", now, LEN(now)

timer

Returns the number of seconds since midnight as a floating-point number. Includes fractional seconds for high-precision timing. Useful for performance measurement, animation timing, and seeding random numbers. Range is 0.0 to 86399.999…

timer

Example

SCREEN 320, 240
start = timer
FOR i = 1 ... 3
    YIELD
END FOR
PRINT "three frames took", fixed_str(timer - start, 3), "seconds"

trim

Removes leading and trailing spaces from a string.

trim(string)

Parameters

  • string - Input string to trim

Example

SCREEN 320, 240
PRINT "[" + trim("   hi   ") + "]"

ucase

Converts a string to uppercase letters.

ucase(string)

Parameters

  • string - Input string to convert

Example

SCREEN 320, 240
PRINT ucase("Hello World")

uuid

Returns a new random universally unique identifier (version 4) as a string, such as "3f2b8c1e-9d4a-4e7b-a6c5-1b2d3e4f5a6b": 36 lower-case characters, a different one every time it is read. Use it to name something that must not clash with anything else, such as a save slot or a player’s record.

uuid

Example

SCREEN 320, 240
slot = uuid
PRINT "Save slot", slot
PRINT LEN(slot)

val

Converts a string to a number. The whole string must be one — surrounding spaces are fine, anything else is not.

val(string_expression)

Parameters

  • string_expression - A string that is entirely a number, such as “42”, “-3.14” or “ 7 “. Anything else is a runtime error.

Example

SCREEN 320, 240
PRINT val("42") + 1, val("  -3.14  ")

version

Returns the CrashCore engine version as a string (e.g., “1.10.0”). Useful for displaying engine information or checking compatibility.

version

Example

SCREEN 320, 240
PRINT "CrashCore", version