Diese Seite auf Deutsch

Types and values ​

c0de is statically typed: every variable, constant, parameter and result has exactly one type, written as a type block after its name. There is no null, no implicit conversion from text to numbers and only two widenings. This lesson goes through the types, their literals and default values, the conversions between them and the constants every program knows without declaring them.

What you need

A creative world with cheats on (see Tutorials), a trigger block, a wrench, a button and ten uninitialized variable items. For the conversions: a STRING variable item named input.

The types ​

c0deLikeLiteralDefault value
BOOLEANbooleanTRUE, FALSEfalse
INTEGERJava long (signed 64 bit)42, -70
FLOATJava double3.14, 1.0E200.0
CHARone Unicode code point'a'a space
TIMEUnix time in milliseconds@2026-10-19T12:05:09Z1970-01-01T00:00:00Z
STRINGJava String"Hello"""
ARRAY Ta list of T, from index 0–empty
HASH Ta map from STRING keys to T–empty
STRUCT namea record with named elements–defaults of all elements
ERRORa struct with code, message, context, line–code 0

The first five are the simple types, the others the complex ones:

  • STRING may have a length limit: STRING 16. A longer value raises STRING_TOO_LONG. name[0] reads one character as a CHAR.
  • ARRAY and HASH are always followed by the type of their content, like ARRAY INTEGER or HASH ARRAY STRING. They grow and shrink by themselves, up to 8 dimensions.
  • STRUCT is followed by the name of a struct declared above, like STRUCT point. Its elements are reached with spot.x.
  • ERROR is the type of errors (see the lesson "Errors"); your own codes start at 1000.
  • TIME is a point in time, not a duration. TIME + INTEGER adds milliseconds, TIME - TIME gives the milliseconds between them.

Literals exist only for the simple types and STRING. Arrays, hashes and structs get their start values from an initializer: a code block after the VARIABLE or CONSTANT line, with literals only, no expressions.

The program ​

A function that returns one value of every type:

c0de
PROGRAM typetour
NOOP
NOOP
STRUCT point
BEGIN
    x INTEGER
    y INTEGER
    z INTEGER
END STRUCT
NOOP
FUNCTION values
    RESULT flag BOOLEAN
    RESULT count INTEGER
    RESULT ratio FLOAT
    RESULT letter CHAR
    RESULT moment TIME
    RESULT name STRING 16
    RESULT list ARRAY INTEGER
    RESULT stock HASH INTEGER
    RESULT spot STRUCT point
    RESULT problem ERROR
BEGIN
    VARIABLE primes ARRAY INTEGER
    BEGIN
        2 3 5 7
    END VARIABLE
    VARIABLE chest HASH INTEGER
    BEGIN
        gold 12
        diamond 3
    END VARIABLE
    VARIABLE home STRUCT point
    BEGIN
        x 100
        z -250
    END VARIABLE
    ASSIGN flag 3 > 2 ;
    ASSIGN count 64 * 27 ;
    ASSIGN ratio 7 / 2 ;
    ASSIGN letter 'é' ;
    ASSIGN moment @2026-10-19T12:05:09Z + 250 ;
    ASSIGN name "Steve" ;
    ASSIGN list primes ;
    ASSIGN stock chest ;
    ASSIGN spot home ;
    ASSIGN problem.code 1000 ;
    ASSIGN problem.message "Just a value" ;
END FUNCTION

Running it ​

Set the trigger block to the program typetour and the function values. The function has ten results and no parameters, so put ten uninitialized variable items into its input inventory, and press the button.

The output inventory then holds ten variable items. Hold one in your main hand and right-click it: the dialog shows its name, type and value.

ItemTypeValue
flagBOOLEANtrue
countINTEGER1728
ratioFLOAT3.5
letterCHARé
momentTIME2026-10-19T12:05:09.250Z
nameSTRINGSteve
listARRAY INTEGER[2, 3, 5, 7]
stockHASH INTEGER
spotSTRUCT point
problemERRORcode 1000, message "Just a value"

How it works ​

  • STRUCT point declares a type above the function that uses it. A name is only known below its declaration.
  • The initializer of primes lists literals, those of chest and home one key or element and one literal per line. The element y of home isn't listed, so it keeps its default 0.
  • ASSIGN ratio 7 / 2 ; gives 3.5: / always gives a FLOAT, also for two integers.
  • @2026-10-19T12:05:09Z + 250 is a TIME 250 milliseconds later.
  • ASSIGN list primes ; copies the array. Complex values are always copied, never shared: changing list afterwards doesn't change primes.
  • problem is an ordinary variable of type ERROR. Returning it as a result doesn't raise anything; only RETURN with it or RAISE does.

Conversions ​

c0de converts only in two directions by itself: an INTEGER fits into a FLOAT, and a CHAR into a STRING (in ASSIGN, initializers and literals). Everything else is a function call:

From → toHowExample
anything → STRING⊕ or c0de/strings/STR"n=" ⊕ 2.5 is "n=2.5"
STRING → numberc0de/strings/VAL"42" gives the FLOAT 42.0 and isInteger true
FLOAT → INTEGERc0de/math/INT (down), FIX (cut), ROUND (to even)-12.85 → -13, -12, -13
INTEGER → FLOATc0de/math/TO_FLOAT, or just assign it7 → 7.0
c0de
PROGRAM typeconvert
NOOP
INCLUDE c0de/math
INCLUDE c0de/strings
NOOP
FUNCTION convert
    PARAMETER input STRING "-12.85"
    RESULT number FLOAT
    RESULT whole BOOLEAN
    RESULT down INTEGER
    RESULT cut INTEGER
    RESULT back FLOAT
    RESULT shown STRING
    RESULT joined STRING
BEGIN
    CALL c0de/strings/VAL
        PARAMETER text input ;
        RESULT value number
        RESULT isInteger whole
    CALL c0de/math/INT
        PARAMETER value number ;
        RESULT result down
    CALL c0de/math/FIX
        PARAMETER value number ;
        RESULT result cut
    CALL c0de/math/TO_FLOAT
        PARAMETER value cut ;
        RESULT result back
    CALL c0de/strings/STR
        PARAMETER value back ;
        RESULT result shown
    ASSIGN joined "cut " ⊕ cut ⊕ ", whole " ⊕ whole ;
END FUNCTION

Set the trigger block to the program typeconvert and the function convert. Put in seven uninitialized items, press the button and right-click the result items. With the default "-12.85", the results are number -12.85, whole false, down -13, cut -12, back -12.0, shown "-12.0" and joined "cut -12, whole false". Now put in the STRING variable item input with the value " 42 " and six uninitialized items: input takes the place of one result. VAL ignores the spaces and returns 42.0 with isInteger true. With "forty-two", VAL raises INVALID_ARGUMENT, and the process crashes with exit code 15: the trigger block shows the error, and the items come out unchanged.

Library functions are called with CALL, never inside an expression; the next lesson explains why.

Built-in constants ​

Every program knows these constants without an INCLUDE:

ConstantTypeContent
SHEETSTRUCT SHEET_INFOthe sheet of the program: number, program, owner, x, y, z
PIDSTRUCT PID_INFOthe process: pid, program, function, owner, activator (who started it), x, y, z and dimension of the trigger block, debug, started
CURSORSTRUCT CURSOR_INFOthe cursor right now: line, function, depth, stack_used, stack_size
C0DE_VERSIONSTRINGthe version of c0de, e.g. "0.5.0"
COLOR_BLACK … COLOR_WHITEINTEGERthe 16 colors 0 to 15 of COLOR
DIVISION_BY_ZERO, TYPE_MISMATCH …INTEGERthe codes of the errors of the language

SHEET and PID are filled when the process starts. CURSOR is different each time you read it.

Differences you'll trip over ​

  • Types are checked when the program runs, not while you write it: a line with ASSIGN count 7 / 2 ; for an INTEGER count is green on the sheet and raises TYPE_MISMATCH when it runs.
  • There is no null. A variable without a start value holds the default of its type, a result too.
  • An INTEGER doesn't wrap around like a Java long: 9223372036854775807 + 1 raises NUMERIC_OVERFLOW.
  • A FLOAT divided by 0.0 raises DIVISION_BY_ZERO, unlike IEEE floats in Java, C or JavaScript. A FLOAT that gets too big still becomes Infinity.
  • "1" + 1 is a TYPE_MISMATCH, not "11" or 2. Text is joined with ⊕, and numbers are read from text with VAL.
  • VAL always returns a FLOAT. FIX turns it into an INTEGER.
  • A TIME literal without an offset, like @2026-10-19T12:05:09, is read in the time zone of the server. Write Z or +02:00 to be sure.
  • Arrays and hashes are values, not references: assigning or passing them copies them.

Try it yourself ​

  1. Change the type of the result name to STRING 3 and run it again. What happens?
Solution

"Steve" has 5 characters, so the ASSIGN raises STRING_TOO_LONG. The process crashes with exit code 15, and no result items are created: the items you put in come back unchanged in the output inventory.

  1. Write a function that returns the number of its sheet, the player who started it, the line and depth of the cursor, the number of the color red and the code of DIVISION_BY_ZERO.
Solution
c0de
PROGRAM typeconstants
NOOP
NOOP
FUNCTION where
    RESULT sheet INTEGER
    RESULT starter STRING
    RESULT line INTEGER
    RESULT depth INTEGER
    RESULT red INTEGER
    RESULT failure INTEGER
BEGIN
    ASSIGN sheet SHEET.number ;
    ASSIGN starter PID.activator ;
    ASSIGN line CURSOR.line ;
    ASSIGN depth CURSOR.depth ;
    ASSIGN red COLOR_RED ;
    ASSIGN failure DIVISION_BY_ZERO ;
END FUNCTION

Started with a button, starter is your name. line is 13, the line of the ASSIGN that reads CURSOR, depth is 1 in the entry function, red is 12 and failure is 303. sheet is the number of the sheet you built it on.

Read more ​