Complete example programs

Programming guides

Console program using data and functions

# language: en
let players = [
    {"name": "Ada", "score": 12},
    {"name": "Pip", "score": 18},
    {"name": "Mina", "score": 15},
]

function describe(player):
    return player.name + " scored " + text(player.score)

let bestIndex = 0
let index = 1

while index < length(players):
    if players[index].score > players[bestIndex].score:
        set bestIndex = index
    set index = index + 1

for player in players:
    say describe(player)

say "Winner:", players[bestIndex].name

Typed questionnaire

# language: en
let name = ask("What is your name?")
let level = askNumber("Choose a level from 1 to 5", 1, 5)
let theme = choose("Choose a theme", ["space", "jungle", "racing"])
let confirmed = askYesNo("Start now?")

if confirmed:
    say "Starting", theme, "level", level, "for", name
else:
    say "Setup cancelled."
    exitApp()

Cooperative graphical loop

# language: en
let x = 300
let y = 160
let speed = 4
let running = true

while running:
    if keyDown("left"):
        set x = x - speed
    if keyDown("right"):
        set x = x + speed
    if keyDown("up"):
        set y = y - speed
    if keyDown("down"):
        set y = y + speed
    if keyDown("space"):
        exitApp()

    clearCanvas("#0f172a")
    circle(x, y, 18, "#22d3ee")
    drawText(320, 20, "Arrows move · Space exits", 20, "#ffffff", "sans", "center")
    wait(0.04)

Textured 3D objects and a camera

# language: en
clear3D("#16213e")
box3D("crate", 1.5, 1.5, 1.5)
color3D("crate", "orange")
texture3D("crate", "checker", 2)
turn3D("crate", 25)

cylinder3D("pillar", 0.35, 2)
position3D("pillar", 2, 0, 0)
color3D("pillar", "blauw")
texture3D("pillar", "brick")

sphere3D("ball", 0.5)
position3D("ball", -2, 0, 0)
color3D("ball", "rood")
solid3D("ball", false)

camera3D(0, 2, 6)
lookAt3D(0, 0, 0)
say "Crate touches pillar:", touching3D("crate", "pillar")
say "Aimed object:", aim3D(20)
draw3D()
drawText(320, 20, "My 3D world", 24, "white", "sans", "center")

The pattern strings and mixed English/Dutch color values stay unchanged when
this program is converted to Dutch syntax. More examples are available in
rotating-box.pliro and
laser-maze-3d.pliro.

Syntax and values · Built-ins · Programming guides