Dictionary of Plotscripting Commands

For the next WIP OHRRPGCE version (nightly build 2024-11-11)

This is the documentation for all plotscripting commands. In addition to reading this document, we also recommend you check out the Plotscripting Tutorial and the Plotscripting article on the wiki.
If you're reading this on the OHRRPGCE website then make sure you're looking at the page for the latest stable release (here) or latest nightly version (here). This documentation is also included as an HTML file with downloads of the engine.

Commands by Category

  • Declarations
  • Math, Comparison, and Logic Operators
  • Flow Control
  • Wait Commands
  • Working with Tags
  • Suspend and Resume
  • Moving Heroes
  • Doors
  • NPCs
  • The Camera
  • Text Boxes
  • Triggering Stuff
  • Basic Display Commands
  • Opening Built-in Menus
  • The Party
  • Money
  • Items
  • Effects
  • User Interface Colors and Box Styles
  • Hero Data
  • Attack Data
  • Enemy and Formation Functions
  • Getting Player Input
  • String Functions
  • Extra Data Array Functions
  • Shop Functions
  • Menu Functions
  • Slices
  • Time Functions
  • Tweaking Maps
  • Timers
  • Script Triggers
  • General Game Settings
  • Saved Games
  • Advanced Functions
  • Platform Specific
  • Types and Handles
  • Glossary
  • Predefined Constants

  • Alphabetical Index

    $id+"some text"
    $id="some text"
    abs (number)
    number + number
    add enemy to formation (formation, enemy id, x, y, slot)
    add hero (who)
    add menu item(menu handle)
    advance text box
    allocate timers (number)
    allow minimap (setting)
    allow save anywhere (setting)
    alter NPC (who, NPCstat, value, pool)
    ancestor (of a slice)
    value,and,value
    animation start tile (tile number, layer)
    any key
    append ascii (ID, char)
    append extra (handle, value)
    append number (ID, number, min length, pad with zeros)
    ascii from string (ID, position)
    assert (expression)
    autonumber
    autosave
    auto virtual gamepad
    base stat
    begin, other commands, end
    Blendable slice handles
    Boolean Constants
    bottom menu
    box advance is suspended
    break (levels)
    breakpoint
    bring menu forward(menu handle)
    camera follows hero (who)
    camera follows NPC (who)
    camera follows slice (slice)
    camera pixel X
    camera pixel Y
    cancel dissolve (handle)
    cancel hero walk (who)
    cancel key
    cancel map name display
    cancel NPC walk (who)
    cancel override tick milliseconds (ms)
    can learn spell (hero, attack)
    case(value)
    caterpillar is suspended
    center slice (handle)
    center string at (ID, x, y)
    change NPC ID (reference, new ID, pool)
    change tileset (tileset, layer)
    check equipment (hero, slot)
    check game exists (file string id)
    check hero wall (who,direction)
    check NPC wall (who, direction)
    check onetime (onetime)
    check parentage (handle, ancestor handle)
    check tag (tag)
    check wall collision x (x, y, width, height, relative x, relative y, friction%)
    child count (handle)
    clamp slice (slice, within slice)
    clear string(ID)
    clone slice (handle, recurse)
    clone sprite (handle)
    close menu(menu handle, run close script)
    color:blue
    Color codes
    Color Constants
    color:green
    color:red
    concatenate strings (dest, source)
    continue (levels)
    Control Codes
    copy string (dest, source)
    create container (width, height)
    create ellipse (width, height, border color, fill color)
    create global NPC (ID, X, Y, direction)
    create grid (width, height, rows, columns)
    create line (width, height, color)
    create menu
    create NPC (ID, X, Y, direction, pool)
    create panel (width, height)
    create rect (width, height, style)
    create scroll (width, height)
    create select (width, height)
    create sprite
    create text
    crop
    current display tile (tile number, layer)
    current map
    current music
    current song
    current stat
    current text box
    current vehicle id
    current vehicle npc
    days of play
    debug menu
    decrement (variable,amount)
    default tile
    define constant (number,name)
    delete char (ID, position)
    delete enemy from formation (formation, slot)
    delete extra (handle, index)
    delete extra range (handle, from index, to index)
    delete hero (who)
    delete hero by slot (slot)
    delete item (item, number)
    delete map state (whichdata, custom id)
    delete menu item(menu item handle)
    delete NPC (reference)
    delete save (slot)
    descendent (of a slice)
    destroy NPC (reference)
    Directions
    dir X (direction)
    dir Y (direction)
    dismount vehicle
    dissolve sprite (handle, dissolve type, total ticks, start tick, backwards, automatic)
    number / number
    do
    door at spot (x, y)
    door exists (number, map)
    doors are suspended
    down
    down key
    draw NPCs above heroes (setting)
    dump slice tree (slice)
    east
    east wall
    else
    ... else if(condition) then(commands) ...
    enable input text (enable)
    end
    enemy elemental resist as int (enemy, element)
    number == number
    equip menu (who, allow switching)
    equip where (hero, item)
    exit
    exit returning(value)
    exit script
    expand string(ID, saveslot)
    expand strings in slices(handle, saveslot)
    experience to level (level, hero slot)
    experience to next level (who)
    number ^ power
    export globals (slot, first, last)
    expression
    extended scancodes enabled
    extract color (color, component)
    Extra data array index
    extra length (handle)
    fade screen in
    fade screen out (red, green, blue)
    false
    fight formation (number)
    fill parent (handle, true_or_false)
    find colliding slice (parent, slice, number, check descendants, visible only)
    find color (r, g, b, searchstart)
    find enemy in formation (formation, enemy id, copy number)
    find extra (handle, value, start index)
    find hero (who)
    find menu ID(menu ID)
    find menu item caption(menu handle, string ID, search after handle, visible only)
    first child (handle)
    first child of type(handle, type)
    first container child (handle)
    first ellipse child (handle)
    first grid child (handle)
    first line child (handle)
    first menu item(menu handle)
    first panel child (handle)
    first rect child (handle)
    first scroll child (handle)
    first select child (handle)
    first sprite child (handle)
    first text child (handle)
    flee key
    focus camera (x,y,speed)
    for(counter,start,finish,step) do(commands)
    force equip (hero, slot, item)
    force mount vehicle (npc)
    forget spell (hero, attack)
    formation probability (formation set, formation)
    formation set frequency (formation set)
    formation slot enemy (formation, slot)
    formation slot x (formation, slot)
    formation slot y (formation, slot)
    forward X (who)
    forward Y (who)
    free slice (handle)
    free slice children (handle)
    free sprite (handle)
    gain hero stat (who, stat, amount, reset to max)
    game over
    gently realign slice (handle, horiz align, vert align, horiz anchor, vert anchor)
    gently reparent (handle, parent handle)
    get active battle pause on all menus
    get active time battle mode
    get ambient music
    get attack caption (str ID, attack)
    get attack extra (attack, extra num)
    get attack name
    get battle countdown
    get blending enabled (handle)
    get blend mode (handle)
    get bottom padding (handle)
    get box style border (box style)
    get box style color (box style)
    get box style edge color (box style)
    get calling script id (depth)
    get child autosort (handle)
    get color (index)
    get count
    get current map autorun script
    get current map autorun script argument
    get damage cap
    get death script
    get default hero hand x (who, frame)
    get default hero hand y (who, frame)
    get default weapon (hero)
    get door destination id (number, map)
    get door destination map (number, map)
    get door x (number, map)
    get door y (number, map)
    get each step script
    get ellipse border col (handle)
    get ellipse fill col (handle)
    get enemy appearance (enemyid, appearance)
    get enemy name (enemyid, stringid)
    get enemy stat(enemy, stat)
    get extra (handle, extra)
    get foot offset
    get formation background (formation)
    get formation song (formation)
    get global sound volume
    get grid columns (handle)
    get grid rows (handle)
    get hero auto battle (who)
    get hero hand x (who, frame)
    get hero hand y (who, frame)
    get hero level (who)
    get hero name (ID, hero)
    get hero palette (who, type)
    get hero picture (who, type)
    get hero slice (rank)
    get hero slice by slot (slot)
    get hero speed (who)
    get hero sprite (rank)
    get hero sprite by slot (slot)
    get hero stat (who, stat, type)
    get hero stat cap (stat)
    get horiz align (handle)
    get horiz anchor (handle)
    get input text (string id)
    get instead of battle script
    get inventory size
    get item (item, number)
    get item description (ID, item)
    get item maximum stack size (item)
    get item name (ID, item)
    get left padding (handle)
    get level cap
    get level MP (who, mp level slot, type)
    get line color (handle)
    get load script
    get map edge mode
    get map name (ID, map)
    get map tileset
    get menu anchor x(menu handle)
    get menu anchor y(menu handle)
    get menu bit(menu handle, bit)
    get menu border(menu handle)
    get menu boxstyle(menu handle)
    get menu cancel button menu(menu handle)
    get menu disabled textcolor(menu handle)
    get menu ID(menu handle)
    get menu item bit(menu item handle, bit)
    get menu item caption(menu item handle, string ID)
    get menu item color(menu item handle)
    get menu item disabled color(menu item handle)
    get menu item extra(menu item handle, extra)
    get menu item settag(menu item handle)
    get menu item spacing(menu handle)
    get menu item subtype(menu item handle)
    get menu item tag(menu item handle, whichtag)
    get menu item togtag(menu item handle)
    get menu item type(menu item handle)
    get menu max chars(menu handle)
    get menu max rows(menu handle)
    get menu min chars(menu handle)
    get menu offset x(menu handle)
    get menu offset y(menu handle)
    get menu on close script(menu handle)
    get menu text align(menu handle)
    get menu textcolor(menu handle)
    get money (amount)
    get music volume
    get NPC ID (reference)
    get NPC ignores walls (who)
    get NPC moves (who)
    get NPC obstructs (who)
    get NPC pool (reference)
    get npc slice (npc)
    get NPC speed (who)
    get npc sprite (npc)
    get NPC usable (who)
    get on keypress script
    get opacity (handle)
    get outline(handle)
    get panel is vertical (handle)
    get panel padding (handle)
    get panel percent as int (handle)
    get panel pixels (handle)
    get panel primary index (handle)
    get rect bgcol (handle)
    get rect border (handle)
    get rect fgcol (handle)
    get rect fuzziness (handle)
    get rect fuzzy zoom (handle)
    get rect opacity (handle)
    get rect raw border (handle)
    get rect stationary pattern (handle)
    get rect style (handle)
    get rect trans (handle)
    get right padding (handle)
    get scancode name(string id, scancode, long name)
    get screen height
    get screen width
    get script name (string id, script id)
    get scroll bar style (handle)
    get scroll check depth (handle)
    get selected child (handle)
    get select slice index (handle)
    get slice clipping (handle)
    get slice extra (handle, extra)
    get slice lookup (handle)
    get slice lookup name (string id, code, use default name)
    get slice text(string id, slice handle)
    get slice velocity x (handle)
    get slice velocity y (handle)
    get slice visible (handle)
    get song name (ID, song)
    get sort order (handle)
    get sprite default pal (handle)
    get sprite frame (handle)
    get sprite palette (handle)
    get sprite set number (handle)
    get sprite trans (handle)
    get sprite type (handle)
    get stat name (ID, stat)
    get text bg(handle)
    get text color(handle)
    get tile animation offset (animation pattern, layer)
    get top padding (handle)
    get turn based battle mode
    get ui color (color, autotoggle)
    get vert align (handle)
    get vert anchor (handle)
    get victory music
    get wrap(handle)
    get zone (zone id)
    get zone extra (zone id, extra num)
    get zone name (string id, zone id)
    give experience (hero, amount)
    global NPC (ID, copy, allow disabled?)
    global NPC reference (ID, copy, allow disabled?)
    globals to string(ID, starting global, length)
    global variable (id,name)
    gracefully dismount vehicle
    number > number
    number >= number
    greyscale palette (first, last)
    grid is shown (handle)
    harm tile
    heal party (revive dead heroes)
    hero base elemental resist as int (who, element)
    hero by rank (where)
    hero by slot (where)
    hero chases npc (who, npc, stop when reached, stuck ticks)
    hero direction (who)
    hero frame (who)
    hero is chasing (who)
    hero is walking (who)
    hero levelled (who)
    hero pixel X (who)
    hero pixel Y (who)
    hero portrait
    hero rank from slice (handle)
    hero slot from slice (handle)
    hero total elemental resist as int (who, element)
    hero uses level MP (who)
    hero walls are suspended
    hero X (who)
    hero Y (who)
    hero Z (who)
    hide mouse cursor
    hide string (ID)
    hide virtual gamepad
    horiz flip sprite (handle, flip)
    hours of play
    if(condition) then(commands) else(commands)
    import globals (slot, first, last)
    include, filename
    increment (variable,amount)
    init mouse
    inn screen (price, skip fade)
    input string (ID, maxlength, use current, center, position x, position y)
    input string with mouse keyboard (ID, maxlength)
    input string with virtual keyboard (ID, maxlength, onlyplayer)
    insert extra (handle, index, value)
    inside battle
    inventory (item)
    is filling parent (handle)
    is shop buy menu empty (shop id)
    is shop hire menu empty (shop id)
    item count in slot (slot)
    item in slot (slot)
    items menu
    joystick axis (axis, multiplier, player)
    joystick button (button, player)
    Key Constants
    key is pressed (scancode, player)
    keypress (scancode, player)
    keypress time (scancode, player)
    keyval (scancode, player)
    knows spell (hero, attack)
    last ascii
    last child (handle)
    last formation
    last layer id
    last menu item(menu handle, visible only)
    last save slot
    layer id under walkabouts
    layer tileset (layer)
    leader
    left
    left button
    left key
    number < number
    number <= number
    load attack sprite (num, palette)
    load backdrop sprite (num)
    load border sprite (num, palette)
    load from slot (slot, args...)
    load hero sprite (num, palette)
    load large enemy sprite (num, palette)
    load map state (whichdata, customid)
    load medium enemy sprite (num, palette)
    load menu (reallyload, show new game)
    load palette (palette number)
    load portrait sprite (num, palette)
    load slice collection (id)
    load small enemy sprite (num, palette)
    load sprite (sprite type, num, palette)
    load tileset (tileset, layer)
    load walkabout sprite (num, palette)
    load weapon sprite (num, palette)
    lock hero (who)
    value && value
    value || value
    value ^^ value
    lookup ancestor (lookup code, slice)
    Slice lookup codes
    lookup next slice (lookup code, current slice, root slice)
    lookup slice (lookup code, root slice)
    lose money (amount)
    main menu
    map cure (attack, target, attacker)
    map height (map)
    map music is suspended
    map width (map)
    maximum stat
    max map id
    me
    Menu handles
    menu is open(menu handle)
    menu item at pixel(x, y)
    menu item by slot(menu handle, slot, visible only)
    menu item by true slot(menu handle, slot)
    menu item count(menu handle)
    menu item disabled(menu item handle)
    Menu item handles
    menu item selectable(menu item handle)
    menu item slot(menu item handle)
    menu item true slot(menu item handle)
    menu item visible(menu item handle)
    menu key
    microseconds
    middle button
    milliseconds
    minutes of play
    number,mod,number
    mouse button (which)
    mouse click (which)
    Mouse Constants
    mouse pixel X
    mouse pixel Y
    mouse region (x min, x max, y min, y max)
    mouse release (which)
    move slice above (handle, above what handle)
    move slice below (handle, below what handle)
    move slice by (handle, relative x, relative y, ticks)
    move slice to (handle, x, y, ticks)
    move slice to screen pos (handle, x, y, ticks)
    move slice with wallchecking (sl, relative x, relative y, friction%)
    multdiv (a, b, c)
    number * number
    new keypress (scancode, player)
    next container sibling (handle)
    next ellipse sibling (handle)
    next grid sibling (handle)
    next line sibling (handle)
    next menu(menu handle)
    next menu item(menu item handle, visible only)
    next NPC reference (npcref)
    next panel sibling (handle)
    next rect sibling (handle)
    next scroll sibling (handle)
    next select sibling (handle)
    next sibling (handle)
    next sibling of type (handle, type)
    next slice in tree (current slice, root slice, visit children)
    next sprite sibling (handle)
    next text sibling (handle)
    none
    north
    north wall
    not (value)
    number <> number
    NPC at pixel (x, y, number)
    NPC at spot (x, y, number)
    NPC chases NPC (who, other who, stop when reached, stuck ticks)
    NPC copy count (ID, pool)
    NPC copy number (reference)
    NPC direction (who)
    NPC extra (who, which)
    NPC frame (who)
    NPC IDs
    NPC is chasing (who)
    NPC is disabled (reference)
    NPC is walking (who)
    NPC pixel X (who)
    NPC pixel Y (who)
    NPC pool numbers
    NPC references
    NPC reference (ID, copy, allow disabled?, pool)
    npc reference from slice (handle)
    npcs are suspended
    npc walls are suspended
    NPC X (who)
    NPC Y (who)
    NPC Z (who)
    number from string (ID, default)
    Numeric Constants
    Object handles
    obstruction is suspended
    off
    on
    open menu (ID, allow duplicate)
    value,or,value
    order menu
    outside battle
    outside battle cure (attack minus 1, target, attacker)
    overhead tile
    overlay is suspended
    override tick milliseconds (ms)
    pan camera (direction,distance,pixelstep)
    parent menu(menu item handle)
    parent slice (handle)
    party
    party money
    pathfind hero to (who, x, y, stuck ticks)
    pathfind into extra as hero (extra, start x, start y, dest x, dest y, maxdepth, append, skip first)
    pathfind into extra as npc (extra, npc ref, start x, start y, dest x, dest y, maxdepth, append, skip first)
    pathfind NPC to (who, x, y, stuck ticks)
    pause sound (num)
    pay money (amount)
    pick hero (message, skip if alone)
    pixel focus camera (x,y,speed)
    place sprite
    player is suspended
    Player number
    play music
    play song (song)
    play sound (num, loop, preempt)
    plotscript, name, argumentnames (statements)
    positionstring (ID, x, y)
    previous menu(menu handle)
    previous menu item(menu item handle, visible only)
    previous sibling (handle)
    put camera (x,y)
    put hero (who, x, y)
    put mouse (X, Y)
    put NPC (who,x,y)
    put slice (handle, X, Y)
    put slice screen (handle, x, y)
    put sprite (handle, x, y)
    random (lownumber, highnumber)
    random choice (values...)
    random enemies are suspended
    random formation (formation set)
    rank in caterpillar (who)
    read attack name (str ID, attack)
    read color (index, element)
    read enemy data (enemyid, data)
    read foemap (x, y)
    read global (id)
    read map block (x, y, layer)
    read NPC (who, NPCstat, pool)
    read pass block (x, y)
    read preference bit (bitnum)
    read spell (hero, list, slot)
    read timer (id)
    read wall bit (x, y, bit)
    read zone (zone id, x, y)
    realign slice (handle, horiz align, vert align, horiz anchor, vert anchor)
    rename hero (who)
    rename hero by slot (who)
    reparent to hero (handle, hero)
    reparent to npc (handle, npc)
    replace attack sprite (handle, num, palette)
    replace backdrop sprite (handle, num)
    replace border sprite (handle, num, palette)
    replace char (ID, position, char)
    replace hero sprite (handle, num, palette)
    replace large enemy sprite (handle, num, palette)
    replace medium enemy sprite (handle, num, palette)
    replace portrait sprite (handle, num, palette)
    replace small enemy sprite (handle, num, palette)
    replace sprite (slice, sprite type, num, palette)
    replace substring (in string, replace what, with what, max replacements, case insensitive)
    replace walkabout sprite (handle, num, palette)
    replace weapon sprite (handle, num, palette)
    reset enemy data (enemyid, data)
    reset enemy name (enemyid)
    reset enemy stat(enemy, stat)
    reset formation (formation)
    reset formation slot (formation, slot)
    reset game(args...)
    reset hero palette (who, type)
    reset hero picture (who, type)
    reset map state (whichdata)
    reset palette
    resize extra (handle, length)
    resume box advance
    resume catapillar
    resume caterpillar
    resume doors
    resume hero walls
    resume map music
    resume NPCs
    resume NPC walls
    resume obstruction
    resume overlay
    resume player
    resume random enemies
    resume random enemys
    resume text box controls
    resume timers
    resume walkabouts
    return(value)
    RGB (red, green, blue)
    right
    right button
    right key
    room in active party
    run game(file string id)
    run key
    running on console
    running on desktop
    running on Linux
    running on Mac
    running on mobile
    running on ouya
    running on web
    running on Windows
    run script by ID (id, argument1, argument2, argument3...)
    save in slot (slot)
    save map state (whichdata, customid)
    save menu (reallysave)
    save screenshot
    save slot used (slot)
    Scancodes
    script, name, argumentnames (statements)
    script error (string id)
    Script IDs
    script layer
    scroll to child
    scroll to slice (parent, sl, apply padding)
    search string (ID1, ID2, start)
    seconds of play
    seed random (seed)
    selected menu item(menu handle)
    select menu item(menu item handle)
    send email (save slot, subject string id, message string id)
    set active battle pause on all menus (value)
    set active time battle mode
    set ambient music (song)
    set battle countdown (value)
    set battle wait mode (state)
    set blending enabled (handle, state)
    set blend mode (handle, blend mode)
    set bottom padding (handle, pixels)
    set capped hero stat (who, stat, value, type)
    set caterpillar mode (state)
    set child autosort (handle, setting)
    set color (index, value)
    set damage cap (cap)
    set days of play (days)
    set dead heroes gain experience (state)
    set death script (id)
    set debug keys disable (state)
    set default weapon (hero, item)
    set each step script (id)
    set ellipse border col (handle, color)
    set ellipse fill col (handle, color)
    set enemy appearance (enemyid, appearance, value)
    set enemy name (enemyid, stringid)
    set enemy stat(enemy, stat, value)
    set experience (who, experience, allowforget)
    set extra (handle, extra, value)
    set foot offset (offset)
    set formation background (formation, background, animation frames, animation ticks)
    set formation song (formation, song)
    set full hero swap mode (state)
    set global sound volume (volume)
    set grid columns (handle, columns)
    set grid rows (handle, rows)
    set harm tile damage (amount)
    set harm tile flash (color)
    set hero auto battle (who, bool)
    set hero base elemental resist (who, element, percent)
    set hero direction (who, direction)
    set hero frame (who, frame)
    set hero hand x (who, frame, new x)
    set hero hand y (who, frame, new y)
    set hero level (who, level, forgetspells)
    set hero name (ID, hero)
    set hero palette (who, palette, type)
    set hero picture (who, picture, type)
    set hero position (who, x, y)
    set hero speed (who, speed)
    set hero stat (who, stat, value, type)
    set hero stat cap (stat, value)
    set hero z (who, z)
    set horiz align (handle, edge)
    set horiz anchor (handle, edge)
    set hours of play (hours)
    set HP level up restore (state)
    set inn revive mode (state)
    set instead of battle script (id)
    set inventory size (new size)
    set item count in slot (slot, count)
    set item in slot (slot, item)
    set last save slot (slot)
    set left padding (handle, pixels)
    set level cap (cap)
    set level MP (who, mp level slot, new value)
    set line color (handle, color)
    set load script (id)
    set map edge mode (mode, default tile)
    set menu anchor x(menu handle, new anchor)
    set menu anchor y(menu handle, new anchor)
    set menu bit(menu handle, bit, value)
    set menu border(menu handle, new border)
    set menu boxstyle(menu handle, new box style)
    set menu cancel button menu(menu handle, menu)
    set menu disabled textcolor(menu handle, new textcolor)
    set menu item bit(menu item handle, bit, value)
    set menu item caption(menu item handle, string ID)
    set menu item color(menu item handle, colorcode)
    set menu item disabled color(menu item handle, colorcode)
    set menu item extra(menu item handle, extra, num)
    set menu item settag(menu item handle, new settag)
    set menu item spacing(menu handle, spacing)
    set menu item subtype(menu item handle, new subtype)
    set menu item tag(menu item handle, new tag, whichtag)
    set menu item togtag(menu item handle, new settag)
    set menu item type(menu item handle, new type)
    set menu max chars(menu handle, new max)
    set menu max rows(menu handle, new max rows)
    set menu min chars(menu handle, new min)
    set menu offset x(menu handle, new x)
    set menu offset y(menu handle, new y)
    set menu on close script(menu handle, script id)
    set menu text align(menu handle, new align)
    set menu textcolor(menu handle, new textcolor)
    set minutes of play (min)
    set money (amount)
    set music volume (volume)
    set MP level up restore (state)
    set NPC direction (who, direction)
    set NPC extra (who, which, value)
    set NPC frame (who, frame)
    set NPC ignores walls (who, value)
    set NPC moves (who, value)
    set NPC obstructs (who, value)
    set NPC position (who, X, Y)
    set NPC speed (who, speed)
    set NPC usable (who, value)
    set NPC z (npc, z)
    set onetime (onetime,value)
    set on keypress script (id)
    set opacity (handle, percent)
    set outline(handle, outline)
    set padding (handle, pixels)
    set panel is vertical (handle, value)
    set panel padding (handle, padding)
    set panel percent (handle, percent)
    set panel pixels (handle, pixels)
    set panel primary index (handle, zero or one)
    set parent (handle, parent handle)
    set rect bgcol (handle, color)
    set rect border (handle, border)
    set rect fgcol (handle, color)
    set rect fuzziness (handle, percent)
    set rect fuzzy zoom (handle, zoom)
    set rect opacity (handle, percent)
    set rect raw border (handle, border)
    set rect stationary pattern (handle, value)
    set rect style (handle, style)
    set rect trans (handle, transparency setting)
    set right padding (handle, pixels)
    set scroll bar style (handle, style)
    set scroll check depth (handle, depth)
    set seconds of play (sec)
    set selected child (select, child)
    set select slice index (handle, index)
    set slice clipping (handle, clip)
    set slice edge x (handle, edge, value)
    set slice edge y (handle, edge, value)
    set slice extra (handle, extra, value)
    set slice height (handle, height)
    set slice lookup (handle, code)
    set slice screen x (handle, x)
    set slice screen y (handle, y)
    set slice size (handle, width, height)
    set slice text(handle, string id)
    set slice velocity (handle, horiz pixels per tick, vert pixels per tick, ticks)
    set slice velocity x (handle, pixels per tick, ticks)
    set slice velocity y (handle, pixels per tick, ticks)
    set slice visible (handle, vis)
    set slice width (handle, width)
    set slice x (handle, X)
    set slice y (handle, Y)
    set sort order (handle, order)
    set sprite frame (handle, num)
    set sprite palette (handle, num)
    set sprite set number (handle, record)
    set sprite trans (handle, drawtransparent)
    set sprite visible
    set tag (tag,value)
    set text bg(handle, color)
    set text color(handle, color)
    set tile animation offset (animation pattern, offset, layer)
    set timer (id, count, speed, trigger, string, flags)
    set timer args (id, args...)
    set top padding (handle, pixels)
    set turn based battle mode
    set ui color (color, palette index)
    variable := value
    set vert align (handle, edge)
    set vert anchor (handle, edge)
    set victory music (song)
    set wrap(handle, wrap)
    set zone extra (zone id, extra num, value)
    show backdrop (number)
    show battle health meter (state)
    show battle ready meter (state)
    show grid (handle, shown)
    show map
    show mini map
    show mouse cursor
    show no value
    show string (ID)
    show string at (ID, x, y)
    show text box (number)
    show value (number, ...)
    show value of (expression, ...)
    show virtual gamepad
    sign (number)
    slice at pixel (parent, x, y, number, check descendants, visible only)
    slice child (handle, number)
    slice child index (handle)
    slice collide (handle1, handle2)
    slice collide point (handle, x, y)
    slice contains (handle1, handle2)
    slice edge x (handle, edge)
    slice edge y (handle, edge)
    Slice handles
    slice height (handle)
    slice is container (handle)
    slice is ellipse (handle)
    slice is grid (handle)
    slice is line (handle)
    slice is map layer (handle)
    slice is moving (handle)
    slice is panel (handle)
    slice is rect (handle)
    slice is scroll (handle)
    slice is select (handle)
    slice is sprite (handle)
    slice is text (handle)
    slice is valid (value)
    slice parent (handle)
    slice screen x (handle)
    slice screen y (handle)
    slice subtree
    slice to back (handle)
    slice to front (handle)
    slice type (handle)
    slice width (handle)
    slice x (handle)
    slice y (handle)
    song: same as last map
    song: same as map
    song: silence
    sort children (handle, wipe)
    sound is playing (num)
    south
    south wall
    speaking NPC
    spells learned (hero, number)
    spells learnt (hero, number)
    spells menu (who)
    sprite frame count (handle)
    sprite is dissolving (handle)
    sprite is horiz flipped (handle)
    sprite is vert flipped (handle)
    spritelayer
    sqrt (number)
    status screen (who)
    stop music
    stop slice (handle)
    stop song
    stop sound (num)
    stop timer (id)
    string color (ID, foreground color, background color)
    string compare (ID1, ID2)
    string equal (ID1, ID2)
    string from textbox (ID, textbox, line, ignored)
    string is visible (ID)
    string length (ID)
    string sprintf (dest string ID, format string ID, arguments...)
    string style (ID, style)
    string to globals (ID, starting global, length)
    string X (ID)
    string Y (ID)
    subscript, name, argumentnames (statements)
    number -- number
    subtree
    suspend box advance
    suspend catapillar
    suspend caterpillar
    suspend doors
    suspend hero walls
    suspend map music
    suspend NPCs
    suspend NPC walls
    suspend obstruction
    suspend overlay
    suspend player
    suspend random enemies
    suspend random enemys
    suspend text box controls
    suspend timers
    suspend walkabouts
    swap by name (name,name)
    swap by position (slot1, slot2)
    swap in hero (who)
    swap menu items(handle1, handle2)
    swap out hero (who)
    switch(expression)
    system day
    system hour
    system minute
    system month
    system second
    system year
    teach spell (hero, attack)
    team menu
    teleport to map (map, x, y)
    textbox controls are suspended
    textbox line (string ID, textbox, line, expand, strip)
    textbox text (string ID, textbox, expand, strip)
    then
    timer: default
    timer: game over
    timer flag: battle
    timer flag: critical
    timer flag: menu
    timers are suspended
    top menu
    total experience (who)
    trace (string)
    trace value (expression, ...)
    trim string (ID, start, length)
    true
    tweak palette (red, green, blue, first, last)
    unequip (hero, slot)
    unhide mouse cursor
    unlock hero (who)
    up
    update level up learning(who, allowforget)
    update palette
    up key
    use door (number, fade screen)
    use item (item)
    use item in slot (slot)
    use key
    use menu item(menu item handle)
    use NPC (who)
    use shop (shop)
    variable (name)
    vehicle A
    vehicle B
    vert flip sprite (handle, flip)
    visible menu item count(menu handle)
    wait (ticks)
    wait for all
    wait for camera
    wait for dissolve (handle)
    wait for hero (who)
    wait for key (key)
    wait for menu (menu handle)
    wait for NPC (who)
    wait for scancode (key)
    wait for slice (handle)
    wait for sound (num)
    wait for text box
    walkabouts are suspended
    walk hero (who, direction, distance)
    walk hero to x (who,x)
    walk hero to y (who,x)
    walk NPC (who, direction, distance)
    walk NPC to X (who, X)
    walk NPC to Y (who, Y)
    Wall Bit Constants
    west
    west wall
    while(condition) do(commands)
    window is focused
    wrap
    write color (index, element, value)
    write enemy data (enemyid, data, value)
    write global (id,value)
    write map block (x, y, value, layer)
    write pass block (x,y,value)
    write preference bit (bitnum, value)
    write spell (hero, list, slot, attack)
    write wall bit (x, y, bit, value)
    write zone (zone id, x, y, value)
    value,xor,value
    Y sort children (handle)
    zone at spot (x, y, count)
    zone number of tiles (zone id)


    Declarations

    [Back to top-level index]

    plotscript, name, argumentnames (statements)

    The plotscript command contains a list of commands that can be triggered directly by an event in your game.
    Plotscript starts with the keyword plotscript, a comma, and then the name of the plotscript. If there are any arguments to the script, you list their names separated by commas after the name of the script, optionally with default values declared like arg = defaultvalue.
    Then comes the text of the script. It is enclosed in begin and end statements. Scripts that are defined as plotscripts can be called directly from "trigger" events in your game, or by name within other scripts.

    [Notice] What's the difference between plotscript and script?
    The only difference is that plotscripts are listed in the game editor, allowing them to be attached to triggers (such as the new-game script), while plain scripts are hidden and can't be selected. (Technically you can use a script as a trigger, but only by using a command like set death script.)
    # example of a simple script
    plotscript,my first script,begin
    	# commands go here
    end
    # example of a script with arguments
    # (It can called with between 1 and 3 arguments.)
    plotscript,my fancy script,fe,fi=0,fo=0,begin
    	# commands go here,
    	# and they can use the aruments fe, fi, and fo
    	# that where passed to the script
    end

    script, name, argumentnames (statements)

    The script command contains a list of commands. Script starts with the keyword script, a comma, and then the name of the script. If there are any arguments to the script, you list their names separated by commas after the name of the script with optional default values. Then comes the text of the script. It is enclosed in begin and end statements. Scripts that are defined as script cannot be called directly from events in your game. They can only be called by name within other scripts. To make a script that can be run directly from your game, use plotscript.

    # example of a simple script
    script,my first script,begin
    	# commands go here
    end
    # Example of a script with arguments
    # (It can called with between 1 and 3 arguments.)
    script,my fancy script,fe,fi=0,fo=0,begin
    	# Commands go here,
    	# and they can use the aruments fe, fi, and fo
    	# that where passed to the script.
    end

    subscript, name, argumentnames (statements)

    subscript is just like script except that it must placed inside another script (or even inside another subscript). See script for details of syntax of arguments. The difference from a regular script is that a subscript can only be called from its parent script (or some other subscript), and it can directly access its parent script's variables in addition to its own arguments and variables. Subscripts can be useful when you have some piece of repeated code that you want to "de-duplicate" by moving into another script which you can call repeatedly, but without having to turn local variables into global variables.

    # Some nearby NPCs move into a line to the north of the hero
    plotscript, line up soldiers, begin
    	show textbox(32)  # "Yes sir!"
    	wait for textbox
    	suspend player
    	set hero direction(me, up)
    	variable (x, y)
    	# The position of the start of the line
    	x := hero X(me) -- 2
    	y := hero Y(me) -- 4
    	subscript, line up NPC, npc, begin
    		# Increment X to get next position in the line
    		x += 1
    		walk NPC to X(npc, x)
    		wait for NPC(npc)
    		walk NPC to Y(npc, y)
    		wait for NPC(npc)
    		set NPC direction(npc, down)
    	end
    	# NPCs move one at a time
    	line up NPC(1)
    	line up NPC(3)
    	line up NPC(11)
    	line up NPC(10)
    	line up NPC(5)
    	resume player
    end

    global variable (id,name)

    Creates a global variable that can be used in any script. The first argument to the global variable declaration is a unique ID number. The second argument is the name of the variable. The ID number for a global variable is a number from 0 to 16383. Each global variable must have a unique number, but this number will not conflict with the ID numbers you use for scripts. It is all right to have a script and a global variable with the same ID number. See also variable

    # any script can read and set the value of a global
    global variable(1,mini game score)

    variable (name)

    Creates a local variable that can only be used inside the script where it was created. The value of this variable is lost when the script ends. If you need a variable who's value persists between calls to a script, or that is automatically saved when the player saves their game, you will need to use a global variable instead.

    variable(points) # make a new variable
    variable+=1 # add one to it

    define constant (number,name)

    Creates a global constant. The first argument is the number that the constant will represent, and the second argument is the name of the constant. Use constants to replace commonly used numbers with friendly names. The following are some general purpose constants have been defined for you (there are hundreds more intended for specific commands):
    zero one two three four five six seven eight nine ten false true off on north east south west up down left right me none

    include, filename

    The include command effectively inserts another text file into your script. It is followed by a single filename that tells what file will be included. This can be used to organise your scripts and other definitions like define constant into multiple files. The filename can include a path, for example include, ..\utility scripts\math.hss. You can optionally include quote marks around the filename, e.g. include, "misc.hss", which causes normal string parsing (for example, allowing a # character in a filename).
    Previously every plotscript file had to start with include, plotscr.hsd but this is now optional. plotscr.hsd, scancode.hsi, and the exported your game name.hsi file are all automatically included.

    include, cutscenes.hss  # All scripts for cutscenes
    include, ..\utility scripts\math.hss  # A few useful scripts shared between multiple games


    Math, Comparison, and Logic Operators

    [Back to top-level index]

    number + number

    Adds two values together and returns the result. This can also be written as add(number,number)

    number -- number

    Subtracts the second number from the first number and returns the result. It is necessary to use the double minus so that HSPEAK.EXE can tell the difference between subtraction, and a minus sign that indicates a negative number. You can also write subtract(number,number)

    number * number

    Multiplies two values together and returns the result. This can also be written as multiply(number,number)

    number / number

    Divides the second number into the first number and returns the result. The result is rounded down to an integer. This can also be written as divide(number,number)

    number,mod,number

    Divides the second number into the first number and returns the remainder. This can also be written as modulus(number,number)

    number ^ power

    Raises a number to a power and returns the result. (If the result is too large and overflows no error occurs: the value is simply wrapped around a 32 bit signed integer.) This can also be written as exponent(number,power)

    abs (number)

    Returns the absolute value of a value. That is, negative values are made positive and others are unchanged: abs(-14) is 14, and abs(14) is 14.

    sign (number)

    Returns -1 if number is negative, 0 if it is 0, and 1 if number is positive.

    sqrt (number)

    Returns the squareroot of a number, rounded to the nearest integer.

    number == number

    Checks to see if the two numbers are equal. If they are equal it returns true, otherwise it returns false. This can also be written as equal(number,number)

    number <> number

    Checks to see if the two numbers are not equal. If they are not equal it returns true. If they are equal it returns false. This can also be written as not equal(number,number)

    number < number

    Checks to see if the first number is less than the second number. If it is, it returns true, otherwise it returns false. This can also be written as less than(number,number) and as number << number

    number > number

    Checks to see if the first number is greater than the second number. If it is, it returns true, otherwise it returns false. This can also be written as greater than(number,number) and as number >> number

    number <= number

    Checks to see if the first number is less than or equal to the second number. If it is, it returns true, otherwise it returns false. This can also be written as less than or equal to(number,number)

    number >= number

    Checks to see if the first number is greater than or equal to the second number. If it is, it returns true, otherwise it returns false. This can also be written as greater than or equal to(number,number)

    value,and,value

    Returns the bitwise AND of both values. In other words, for each bit in each value, they are compared to see if they are both "1". If they are, the result bit is set to 1. Otherwise, it's set to 0.

    See also:

    value,or,value

    Returns the bitwise OR of both values. In other words, for each bit in each value, they are compared to see if either bit is "1". If one is, the result bit is set to 1. Otherwise, it's set to 0.

    See also:

    value,xor,value

    Returns the bitwise AND of both values. In other words, for each bit in each value, they are compared to see if either (but not both!) bit is "1". If ONE is, the result bit is set to 1. Otherwise, it's set to 0.

    See also:

    value && value

    Returns true if both of the values are true (non-zero). If either of them is false, and returns false. This command uses shortcut evaluation: if the first argument is false, the second argument is never evaluated.

    value || value

    Returns true if at least one of the values are true (non-zero). Only if both of them are false does or return false. This command uses shortcut evaluation: if the first argument is true, the second argument is never evaluated.

    value ^^ value

    Returns true if one, but not both of the values are true (non-zero). If both of them are true, or both of them are false, ^^ returns false.

    not (value)

    Returns the logical complement/negation of a value. That is, it returns true (1) if the value is false (0), or false (0) if the value is true (non-zero).

    random (lownumber, highnumber)

    Returns a random integer in the range of the two numbers. The returned value will be greater than or equal to the first number, and less than or equal to the second number

    random choice (values...)

    Returns one of its arguments, randomly. Up to 32 different values can be provided. Returns 0 if it has no arguments.

    # Move an npc randomly to either (5,10), (5,14), or (5,18)
    set npc position(npc, 5, random choice (10, 14, 18))

    seed random (seed)

    Reseeds the random number generator. If you pass in a seed (number) other than 0, the random number generator will be seeded with that number, allowing for repeatable random sequences - random will always return the same sequence of random numbers afterwards. Each seed causes a completely different sequence.
    If called with no argument (or seed = 0), this will reseed the random number generator to a new random sequence (which is useful only if you've previously called seed random(...) to put it into a predictable sequence.)

    [Notice] You don't need to call this command before using random. In fact, this command is useful only if you don't want completely random numbers.
    See also:

    multdiv (a, b, c)

    Computes (a * b) / c with rounding, and without overflowing. The intermediate result is performed in floating point so that it won't overflow, and the final result is clamped to the range of a 32-bit integer.
    This is equivalent to min(2^31 - 1, max(-2^31, round(1.0 * a * b / c))) in other languages.

    dir X (direction)

    Simpler helper function to convert a direction into a relative X value. Returns -1 for left, 1 for right, and otherwise 0. It's often useful to multiply the return value, e.g. to get an increment of 20 pixels rather than 1 tile.

    # To find the tile in front of the hero:
    variable (x, y, dir)
    dir := hero direction(me)
    x := hero X(me) + dir X(dir)
    y := hero Y(me) + dir Y(dir
    
    # To find the point 20 pixels in front of the hero (the hero has a 20x20 hitbox, but "hero pixel X/Y"
    # return the top-left corner, so add 10 pixels to start at the center of the hero):
    x := hero pixel X(me) + 10 + 20 * dir X(dir)
    y := hero pixel Y(me) + 10 + 20 * dir Y(dir)
    See also:

    dir Y (direction)

    Simpler helper function to convert a direction into a relative Y value. Returns -1 for up, 1 for down, and otherwise 0. See dir X.

    See also:


    Math, Comparison, and Logic Operators → Working with Variables

    variable := value

    This command assigns a new value to a variable. If you do not specify the new value, the variable will be reset to zero. This command works exactly the same for global and local variables.
    The := operation actually returns value, so you can use it as an expression, for example in temp1 := (temp2 := 1).

    increment (variable,amount)

    or
    variable += amount
    This command adds an amount to the current value of a variable. If you do not specify the amount, then the variable will be incremented by one. This command works exactly the same for global and local variables.
    The += operation actually returns the new value of variable, so you can use it as an expression, for example in while ((index += 1) < 10).

    decrement (variable,amount)

    or
    variable -= amount
    This command subtracts an amount from the current value of a variable. If you do not specify the amount, then the variable will be decremented by one. This command works exactly the same for global and local variables.
    The -= operation actually returns the new value of variable, so you can use it as an expression, for example in while (index -= 1).

    read global (id)

    A function that returns the value of a global variable using its ID number instead of its name. Why would you want to do a silly thing like that? Because it allows you to simulate simple fake arrays, in the old C-pointer style.

    See also:

    write global (id,value)

    A function that writes a value into a global variable using its ID number instead of its name. Why would you want to do a silly thing like that? Because it allows you to simulate simple fake arrays, in the old C-pointer style

    See also:


    Flow Control

    [Back to top-level index]

    begin, other commands, end

    begin is a synonym for ( and end is a synonym for ). Parentheses are normally used for bracketing things that all fit on the same line, and begin/end statements are often used to enclose very long things such as whole scripts or long flow control blocks that take up several lines. But using one or the other is a matter of taste.
    For example, the following:

    if (check tag(tag:have rusty sword)) then (show text box (5), wait for text box)
    is equivalent to:
    if (check tag(tag:have rusty sword)) then, begin
    	show text box (5)
    	wait for text box
    end

    end

    See begin.

    if(condition) then(commands) else(commands)

    The if statement checks the value of its condition, and if the value is true (actually, any value other than false (which is zero) also counts as true), it runs the commands in the then block. If the value is false, it runs the commands in its else block. The conditional is usually a comparison operator such as == or <>, or a command which returns either true or false, such as check tag. The else is optional as long as you have a then, and the then is optional as long as you have an else. You can also place one or more else ifs after the then (or immediately after the if if you skip the then) instead of nesting multiple if statements.

    See also:

    ... else if(condition) then(commands) ...

    This can appear after an if or then block. It is a shortcut for else followed by if which lets you omit a pairs of brackets/begin and end around the else, as this example shows:

    # "inventory" returns the number you own. Remember that any number other than 0 counts as true
    if (inventory (item:apple)) then (
      show text box (10)  # "Apples! My favourite!"
    ) else if (inventory (item:orange)) then (
      show text box (11)  # "My, what a tasty looking orange..."
    ) else if (inventory (item:pear)) then (
      show text box (12)  # "Perhaps if you gave me that pear..."
    ) else (
      show text box (13)  # "Come back when you have something tasty for me!"
    )

    then

    See if.

    else

    See if.

    while(condition) do(commands)

    The while command checks the value of its condition, and if the value is true (or any value other than 0/false) it runs the commands in the do block. It keeps checking the conditional and runs the do block over and over again until the conditional returns false. The conditional is usually an equality operator such as == or <>, or something else that returns true/false such as checktag.

    do

    Used to group several statements together. Normally appears after a while, for or switch. However, do blocks can actually appear by themselves. This is useful if you want to break out of them to skip to the end. (continue inside an orphan do block acts just like break.)

    See also:

    for(counter,start,finish,step) do(commands)

    The for command runs the commands in the do block a specified number of times. The first argument to for is the counter. It must be a variable. The next two arguments are the starting value and the finishing value. For example, if you use a start value of 1 and a finish value of 10 then the do block will run 10 times. The first time the do block runs, the counter will be 1, then it will be 2, then 3 and so on until it reaches 10, the finish value. The fourth argument of for is optional. It is the step by which the counter will change each loop. If you use a step of 2 then the counter will count 1,3,5,7,9. If you switch the start and finish values and use a step of -1 then the counter will go backwards. If you use 0 as the step, the counter will never change, so the do block will repeat forever. See return and put hero for examples.

    return(value)

    [Warning] return in HamsterSpeak is very different from return in nearly all other programming languages, which is equivalent to exit in HamsterSpeak!
    Sets the value to be returned by the script. This is only useful when the script has been called as a function from another script. It is irrelevant to scripts called directly from your RPG, for example, text box scripts or menu scripts. This command only matters when you are calling one script from another script. This command does NOT cause the script to terminate, it just sets the return value. If you never use the return command, the script will return zero. If return is used more than once in the same script, only the last one executed matters.
    script, key wait, ticks, begin
      # Returns true if a key was pressed during the wait,
      # or false (0) if the wait finished uninterrupted.
      # The wait duration is always the same. (Compare with the example for "exit returning".)
      variable(i)
      for(i, 1, ticks) do, begin
        wait(1)
        if(key is pressed(use key)) then(return(true))
        if(key is pressed(menu key)) then(return(true))
      end
    end
    
    plotscript, usage example, begin
      show text box(5) # let all volunteers take one step forward!
      if(key wait(40)) then(
        walk hero(me, north, 1)
        wait for hero(me)
        show text box(6) # You there! I saw you move! You volunteer!
      )else(
        show text box(7) # a bunch of lily livered cowards, eh?
      )
    end
    
    See also:

    exit

    exit(value)

    With no argument, is equivalent to exit script. With one argument is equivalent to exit returning.

    [Notice] This is the same as the return statement in most other programming languages.

    exit returning(value)

    exit(value)

    Sets the value to be returned by the script, and exits the script. Can be written as either exit returning(value) or the new style exit(value). This is only useful when the script has been called as a function from another script.

    script, key wait, ticks, begin
      # Returns true if the wait was cancelled by a keypress.
      variable(i)
      for(i, 1, ticks) do, begin
        wait(1)
        if(key is pressed(use key)) then(exit returning(true))
        if(key is pressed(menu key)) then(exit returning(true))
      end
    end
    
    plotscript, usage example, begin
      show text box(5) # let all volunteers take one step forward!
      if(key wait(40)) then(
        walk hero(me, north, 1)
        wait for hero(me)
        show text box(6) # You there! I saw you move! You volunteer!
      )else(
        show text box(7) # a bunch of lily livered cowards, eh?
       )
    end
    
    The exit returning command works exactly the same as the return command followed immediately by exit script. Whether you decide to use return or exit returning to set your script's return value is often just a matter of style and taste.
    See also:

    exit script

    exit

    Causes the script to end immediately, and return the value set by the most recent return statement. Can be written as either exit script or the new style exit.

    See also:

    break (levels)

    Breaks out of a for or while loop or switch (or even an isolated do block) and continues the script after the end of the do block. If breaking out of a for loop, the loop's variable isn't modified.
    levels is optional (defaulting to 1), and is almost never used (see below).
    For example:

    plotscript, search for gemstones, begin
      variable (gems)
      # A minimum payout of 1 gem, a maximum of 15
      for (gems, 1, 15) do (
        wait(20)
        $1 = "Found "
        append number(1, gems)
        center string at(1)   # Show "Found 1", etc, in the center of the screen (the position is optional)
        if (random(1, 6) == 1) then (break)  # Roll a die and stop on a 1
      )
      # Remove the text from the screen
      hide string(1)
      # "${S1} shiny rocks in the river", displays as "Found 2 shiny rocks in the river", etc
      show textbox(17)
    end
    levels tells how many nested loops/blocks to break out of. It must be at least 1. Remember that other flow control blocks such as if/then/else and case() do() don't count, only those listed above.
    # Randomly pick one of the flowers on the map that hasn't bloomed yet and make it bloom
    plotscript, a flower blooms, begin
      variable (x, y, found)
      for (x, 0, map width -- 1) do (
        for (y, 0, map height -- 1) do (
          # Look for a flower tile (on map layer 0), suppose it's tile 10
          if (read block(x, y) == 10) then (
            if (random(1, 10) == 1) then (   # 10% chance of picking this one
    	  found := true
    	  break (2)  # Exit both 'for' loops. The x and y variables will remain the same
          )
        )
      )
      # The break(2) jumps to here
    
      if (found) then (
        # Do a little animation
        write block(x, y, 11)
        wait(20)
        write block(x, y, 12)
      )
    end

    continue (levels)

    When used inside the do block of a for or while command (or in an isolated do block), continue skips the rest of the do block and continues on to the next loop, if any. That's equivalent to jumping to the bottom of the loop, so its effect is like enclosing the rest of the loop in an if (except for isolated do blocks, in which case it jumps straight to the top of the loop because there's no condition to check).
    When used inside a switch statement, continue causes a jump into the next case's do() block, even if the case doesn't match, or into the else() (aka case(else) do()) block if that follows the current case.

    levels is optional (defaulting to 1), and is almost never used. When inside several nested loops/blocks it tells which one to continue. It must be at least 1. For example if there are 3 nested for loops, continue(3) continues the outermost one, in the process breaking out of the inner two. For example:

    plotscript, update shadow tiles, begin
      for (x, 0, map width -- 1) do (
        for (y, 0, map height -- 1) do (
    
          for (layer, 4, 7) do (
            # Suppose tiles on any of the layers 4 to 7 are overhead tiles which cast shadows
            if (read map block(x, y, layer) <> 0) then (
              # Found a non-empty tile. Put a shadow tile (42) on the ground (layer 1)
              write map block(x, y, 42, 1)
    	  # We don't need to check the other layers. Skipping them speeds up the script
              continue(2)
            )
          )
          # This part is reached only if the continue(2) didn't happen
          # Remove any shadow tile on layer 1, no shadow here
          write map block(x, y, 0, 1)
    
          # The continue(2) jumps to here (immediately before the 'for' loops back)
        )
      )
    end

    switch(expression)

    Select between a number of case blocks to execute based on the value of an expression. The switch command is an alternative to a big block of nested if/then/else commands that all check the same value. Switch can be easier to read than a lot of if's. Consider the follow script snippet:

    if (v == 0) then (
      something
    ) else if (v == 1 || v == 2) then (
      something else
    ) else if (v == 3 || v == 4) then (
      yet another thing
    ) else if (v == 10) then (
      #nothing happens here
    ) else (
      something to do if none of the other ifs are true
    )
    This is a good candidate for using switch. The example below shows how this can be done:
    switch(v) do(
      case(0) do(
        something
      )
      case(1, 2) do(  # A case can contain multiple values...
        something else
      )
      case(3)
      case(4) do(  # ...or you can use multiple cases after another
        yet another thing
      )
      case(10) do()  #nothing happens here
      else(
        something to do if none of the cases happen
      )
    )
    The else section is optional. There are two different styles (syntaxes) in which switch can be written. The second style looks like this (completely equivalent to the above example):
    switch(v) do(
      case(0)    something
      case(1, 2) something else
      case(3)    
      case(4)    yet another thing
      case(10)   do() #nothing happens here
      case(else) something to do if none of the cases happen
    )
    Besides readability, there is one other important difference between using switch and using a sequence of if's. The switch command only checks the value of the expression (v) once. The if/then/else method checks v repeatedly, so it could be slower, and could be susceptible to errors if you accidentally change the value of v somewhere in the middle.

    case(value)

    The case command is used to enclose a block of commands for one possible result of a switch command. See switch for more details.


    Wait Commands

    [Back to top-level index]

    Note that all of the wait commands wait for at least one tick, even if the thing they are waiting for is false (unless you call a command with invalid arguments, causing a script error instead). For example, "wait for textbox" waits for one tick even if there is no textbox.

    [Warning] If a battle occurs, a menu is entered (unless it 'Allows Scripts') or another script is triggered, your script will be paused until the other thing finishes. While paused, any wait commands don't continue checking. For example, wait stops counting down, and wait for NPC doesn't end if the NPC it's waiting for stops moving while a script is paused but then starts again before it the script resumes.

    wait (ticks)

    Makes the script wait for the specified number of ticks. There are roughly 18 ticks to a second, but this can vary under some conditions. If you leave out the argument, it will wait for one tick.

    show text box(2) # Show a text box
    wait(50) # Wait about 3 seconds
    advance text box # "hit spacebar"

    wait for text box

    Makes the script wait until there is no text box displaying on the screen. Useful to know when to move on after using a show text box command.

    [Warning] wait for text box doesn't wait if suspend box advance has been used, because it's impossible for the player to advance the textbox!
    show text box(2) # Show a text box
    wait for text box # wait until the player continues

    wait for menu (menu handle)

    Given a menu handle, causes the script to wait until that menu has been closed.

    wait for hero (who)

    Waits for the specified hero stop walking. Use the constant me to refer to the leader, or use numbers 0,1,2,3 to refer to a specific hero. If you leave out the argument, the first hero will be assumed.

    move hero to y (me, 10) # move hero to (x, 10)
    wait for hero (me) # wait until he stops

    wait for key (key)

    Waits for the player to press a key. (Specially, (possibly repeated) keypresses or mouse button release.) key is an optional scancode such as a keyboard key (e.g. key:ctrl) a joystick button (e.g. joy:left), or a virtual scancode such as use key. If you do not specify key, then any key will be used.
    any key waits for any keyboard or joystick button, (except Numlock, Capslock and Scrolllock, or any joystick buttons that have no builtin meaning e.g. X/Y/L1/L2/R1/R2) and also waits for a mouse click if "'any key', etc, include mouse clicks" is turned on in the Mouse Controls menu. usekey will wait for Space, Ctrl or Enter, joystick use key, and optionally left click; and cancelkey and menukey both wait for Alt or Esc, joystick cancel, and optionally right click.
    If and only if anykey is used, then waitforkey(anykey) will return the scancode of the keyboard or joystick key that was pressed, but won't ever be a constant like usekey. It returns a value >= 180 if a mouse button was released (see scancode.hsi).

    [Notice] Previously you couldn't use scancodes like key:x, and there was a separate wait for scancode command for those, but now you can use any scancode with wait for key, and use any of the codes like use key with other key commands like key is pressed.
    [Warning] While wait for key waits, on-keypress scripts will not be triggered.
    show text box(623) # "press cancel!"
    wait for key(cancel key)

    wait for scancode (key)

    Identical to wait for key.

    wait for NPC (who)

    Waits for the specified NPC to stop walking. The argument is either an NPC reference, or an NPC ID (if more than one copy of that NPC exists on the map, it only waits for the first one). Be aware that this command has the potention to wait forever, if the NPC will continue moving forever.

    [Notice] If the NPC ceases to exist, or if you move to a different map, then wait for npc stops waiting (continues).
    walk NPC (2,up,3) # make NPC 2 go up three spaces
    wait for NPC (2) # wait until the NPC'S done

    wait for camera

    Wait for the camera to stop panning after a pan camera, focus camera or pixel focus camera command.

    pan camera (left,10) # show the villain 10 tiles off screen
    wait for camera # wait until he's on screen

    wait for all

    Waits for any camera motion due to pan camera, focus camera, etc. to stop, waits for all heroes to stop walking and pathfinding, and waits for NPCs to stop scripted pathfinding (e.g. pathfind NPC to). If suspend NPCs has been used then wait for all also waits for all NPCs to come to a halt. Beware that without suspend NPCs, automatic NPC walking such as wandering, pacing, avoiding, or pathfinding, as well as movement due to walk NPC/walk NPC to X/walk NPC to Y are ignored! That means that NPCs might still be partway between tiles.

    [Notice] wait for all does NOT wait for text boxes.
    # do a bunch of things all at once
    suspend NPCs
    walk hero(me, south, 3)
    pathfind NPC to(4, 30, 35, 10)
    NPC chases NPC(5, 4, false, 10)
    pan camera(north, 20, 1)
    
    # wait until everything is done
    wait for all 
    
    camera follows hero(me)
    resume NPCs

    wait for slice (handle)

    Documented in the Moving Slices section.

    wait for dissolve (handle)

    Documented in the Sprite Slices section.

    wait for sound (num)

    Documented in the Sound Effects section.


    Working with Tags

    [Back to top-level index]

    set tag (tag,value)

    Sets the value of a tag. The available constants are: off, on, true, or false. You can specify the number of the tag, or you can use the constants in your HSI file. These constants are in the form of tag:name.

    check tag (tag)

    A function that checks the value of a tag, and returns true if the tag is turned on, and false if the tag is turned off. It can be used in if and while statements. You can specify the number of the tag, or you can use the constants in your HSI file. These constants are in the form of tag:name.

    set onetime (onetime,value)

    Sets the value of an NPC onetime use flag. NPC onetime use flags behave like tags but are stored separately. value is the new setting; for clarity you can use the constants off, on, true, or false.

    check onetime (onetime)

    A function that checks the value of an NPC onetime flag, and returns true if the one-time NPC has already been used, and false if the onetime NPC has not yet been used. It can be used in if and while statements. NPC onetime flags are similar to tags, but stored separately.


    Suspend and Resume

    [Back to top-level index]

    suspend player

    Blocks the player from controlling the game, so the plotscript can have exclusive control. The exceptions to this are text boxes and menus.
    The player can still advance text boxes unless you use suspend box advance.
    suspend player prevents the player from opening the main menu using the menu key (ESC/etc), but it doesn't suspend controls on any menu or the player's ability to close menus with the cancel key. (You can change that with set menu bit(menu handle, menubit:no controls, true) where menu handle might for example be top menu.)

    suspend player
    # do stuff
    resume player

    resume player

    Restores normal control after a suspend player command. This is very important. If you use suspend player, but forget resume player, the game will be stuck after the script ends.

    suspend player
    # do stuff
    resume player

    player is suspended

    Returns true if suspend player is active.

    suspend NPCs

    Stops NPCs from walking around automatically (ie., suspends NPC AI). When suspend NPCs is run, all NPCs stop in their tracks once they've finished their current step to the next tile, ready for you to control them with commands like walk NPC and pathfind NPC to. You should use a wait command like wait for NPC to ensure an NPC has finished its current movement before getting it to start a new one (which could cause tile misalignment).
    Use set NPC moves(who, false) instead to prevent a single NPC from moving.

    [Notice] If you want NPCs to stop immediately without finishing their current steps, consider suspend walkabouts instead.
    suspend NPCs
    # do stuff
    resume NPCs

    resume NPCs

    Restores automatic NPC movement after a suspend NPCs command. This does not resume NPCs suspended with set NPC moves.

    suspend NPCs
    # do stuff
    resume NPCs

    npcs are suspended

    Returns true if suspend NPCs is active.

    suspend walkabouts

    Suspends (pauses) all NPC and hero movement immediately and completely, as well as NPC AI, player movement controls, NPC activation, Walk In Place animations, and vehicle mounting/dismounting/rising/falling animations. Unlike suspend NPCs, NPCs stop moving immediately rather than finishing their step.
    This doesn't suspend updating of the hero/NPCs slices. For example, put hero, put NPC, set hero z, set hero frame, etc. still cause the hero/NPC slices to move, change frame, etc.
    Although player movement is suspended, this doesn't suspend everything suspend player does: the player can still open the menu (or the vehicle's menu setting or Instead-of-menu script) and advance text boxes. They can't activate NPCs or dismount vehicles.

    [Danger] While walkabouts are suspended, wait for hero and wait for NPC commands will freeze forever, and commands like walk hero and walk NPC won't cause any movement until you resume walkabouts.
    [Notice] This is one of the main effects of menus set to "Suspend gameplay & scripts", along with suspend player, suspend timers, suspend box advance, suspend text box controls, pausing scripts and script triggers, and suspending slice movement.

    resume walkabouts

    Undoes suspend walkabouts. Has no effect if walkabout movement is actually suspended by a menu set to "Suspend gameplay & scripts".

    walkabouts are suspended

    Returns true if suspend walkabouts is active.

    suspend obstruction

    Allows heroes to walk through NPCs, allows NPCs to walk through heroes, and allows NPCs to walk through each other. Also, when obstruction is suspended, step-on activated NPCs won't be activated, and of course NPCs can't be pushed. Use resume obstruction to restore normal obstruction behavior. Use set NPC obstructs(who, false) instead to allow a single NPC to move through heroes and NPCs, and vice-versa.

    suspend obstruction
    # walk through things
    resume obstruction

    resume obstruction

    Restores normal obstruction after a suspend obstruction command. This doesn't undo the effect of set NPC obstructs.

    suspend obstruction
    # walk through things
    resume obstruction

    obstruction is suspended

    Returns true if suspend obstruction is active.

    suspend hero walls

    Allows heroes to walk through walls, and to walk off the edge of the map. Use resume hero walls to restore normal wall behavior.

    suspend hero walls # hero is now a ghost
    # walk through things
    resume hero walls # back to mortality...

    resume hero walls

    Restores normal wall behavior after a suspend hero walls command

    suspend hero walls # hero is now a ghost
    # walk through things
    resume hero walls # back to mortality...

    hero walls are suspended

    Returns true if suspend hero walls is active.

    suspend NPC walls

    Allows NPCs to walk through walls, including to leave the zone they are restricted to, and to walk off the edge of the map. Use resume NPC walls to restore normal wall behavior. Use set NPC ignores walls(who, true) instead to allow a single NPC to walk through walls.

    [Notice] If you use this command on a map with NPCs walking about normally you should use suspend NPCs first, otherwise NPCs will start walking into walls and get stuck there when you call resume NPC walls!
    Usually it is better to use set NPC ignores walls to allow just a specific NPC to walk through walls.
    [Notice] NPCs will still be unable to walk through each other, or to walk through the hero. Use suspend obstruction to allow that.
    suspend NPC walls # npc is now a ghost
    # walk through things
    resume NPC walls # back to mortality...

    resume NPC walls

    Restores normal wall behavior after a suspend NPC walls command. This doesn't undo the effect of set NPC ignores walls.

    suspend NPC walls # npc is now a ghost
    # walk through things
    resume NPC walls # back to mortality...

    npc walls are suspended

    Returns true if suspend NPC walls is active.

    suspend caterpillar

    Stops your other heroes from following the leader. This is useful when you want to control them individually with walk hero commands. In earlier versions this was misspelled as suspend catapillar. The old spelling still works for backwards compatibility.

    [Notice]If you want to set whether the other heroes in the party are visible, use set caterpillar mode.
    suspend caterpillar # cutscene
    # move heroes, probably fight a battle or two...
    resume caterpillar # normal game again.

    resume caterpillar

    Reverses the suspend caterpillar command, and makes your other heroes follow the leader as normal. In earlier versions this was misspelled as resume catapillar. The old spelling still works for backwards compatibility.

    suspend caterpillar # cutscene
    # move heroes, probably fight a battle or two...
    resume caterpillar # normal game again.

    caterpillar is suspended

    Returns true if suspend caterpillar is active.

    suspend catapillar

    An alias for suspend caterpillar.

    resume catapillar

    An alias for resume caterpillar.

    suspend doors

    Stops doors from triggering when stepped on by the lead hero. One use is to allow you to script your own transitions between maps, using door at spot, etc. While doors are suspended use door still works.

    resume doors

    Restores normal door triggering after a suspend doors command. If the lead hero is already standing on a door, it will not be triggered.

    doors are suspended

    Returns true if suspend doors is active.

    suspend random enemies

    Prevents enemies from attacking your party while walking over tiles that can normally spawn random battles. This is useful to prevent battles from interrupting a plotscript. In earlier versions, this was misspelled as suspend random enemys. The old spelling still works for backwards compatibility.

    suspend random enemies # no battles for now
    walk hero (me, up, 10) # cross pit of evil monsters of doom
    resume random enemies # back to normal

    resume random enemies

    Undoes the suspend random enemies command and allows random battles to occur as normal. In earlier versions, this was misspelled as resume random enemys. The old spelling still works for backwards compatibility.

    suspend random enemies # no battles for now
    walk hero (me, up, 10) # cross pit of evil monsters of doom
    resume random enemies # back to normal

    random enemies are suspended

    Returns true if suspend random enemies is active.

    suspend random enemys

    An alias for suspend random enemies.

    resume random enemys

    An alias for resume random enemies.

    suspend box advance

    Prevents the player from advancing text boxes by pressing the 'use' key. While this is active, the only way to make a text box advance is with the advance text box command (or show text box) or using the "Advance text box when menu closes" menu bit. Useful for cut-scenes that play out like a movie, where the player just watches the dialogue unfold. Be very careful with this command, since you do not want to leave the player stuck on a text box forever. Undo with resume box advance.
    Note that the player can still move the cursor in choiceboxes while this is active, use suspend text box controls to disable that.

    [Warning] wait for text box does't wait while suspend box advance is active!
    suspend box advance # stop players from mucking things up
    show text box(2)   # Show a text box
    wait(45)           # Wait about 3 seconds
    advance text box   # Next text box. Maybe it ends with "Press USE key to continue"
    resume box advance # go back to normal

    resume box advance

    Undoes the suspend box advance command, allowing the player to advance text boxes by pressing the use key, as normal.

    box advance is suspended

    Returns true if suspend box advance is active.

    suspend text box controls

    Prevents the player from moving the cursor in choice boxes. In future this will also prevent the player from skipping pauses and fade-in animations for text boxes, once they are implemented. This does not prevent the player from advancing the text box, use suspend box advance for that. Undo with resume text box controls.

    resume text box controls

    Undoes the suspend text box controls command, allowing the player to control choice boxes, as normal.

    textbox controls are suspended

    Returns true if suspend text box controls is active.

    suspend overlay

    Draws old-style overhead tiles under heroes and NPCs instead of over them. This does not affect the drawing of normal layers. You might still find this useful for creating bridges or catwalks that can be walked on or passed under. Undo with resume overlay.

    resume overlay

    Undoes the suspend overlay command, causing overhead tiles to be drawn over heroes and NPCs as normal.

    overlay is suspended

    Returns true if suspend overlay is active.

    suspend map music

    Causes ambient music not to automatically play when you enter a map. Does not affect the currently playing music, or the map's ambient music. Use when playing thematic music during a scene that involves changing maps.

    # begin scene
    play song(song:Happy Times)
    show textbox (117)
    wait for textbox
    # goto another map without triggering music
    fade screen out
    wait
    suspend map music
    use door(3)
    fade screen in
    # continue scene
    show textbox (118)
    wait for textbox
    # return to normal music behaviour and play the ambient music
    resume map music
    play song (get ambient music)

    resume map music

    Causes ambient music to automatically start playing when you enter a map again after a suspend map music command.

    map music is suspended

    Returns true if suspend map music is active.

    suspend timers

    Causes all plot timers started with set timer to be paused. It does not cancel them. Undo with resume timers

    resume timers

    Undoes suspend timers. All previously paused plot timers will become active again.

    timers are suspended

    Returns true if suspend timers is active.


    Moving Heroes

    [Back to top-level index]

    walk hero (who, direction, distance)

    Makes a hero move the specified number of tiles in some direction. The first argument tells who to move, it is a caterpillar rank. Use me or numbers 0-3. (If the catepillar party is disabled then there will only be one hero, me.) The second argument is the direction, such as north. The third argument is the number of tiles to move. If you leave out the third argument, the hero will move one tile. If you use a negative number for walk distance, the hero will walk backwards. Walk hero is usually used with the wait for hero command. You should normally use the suspend player command before moving heroes, and if you want to move heroes other than the leader, you should use the suspend caterpillar command.

    suspend player # stop player
    walk hero(me,up,3) # move him up 3 tiles
    resume player # OK, done

    wait for hero (who)

    Documented in the Wait Commands section.

    pathfind hero to (who, x, y, stuck ticks)

    Makes the specified hero walk along the shortest path to the destination position. They will go around obstacles. If the destination cannot be reached at all, they will go to the closest reachable tile. The first argument who is the hero's rank in the caterpillar party, or me for the leader. When the caterpillar party is enabled, this command only works on the leader, and will do nothing for other heroes. Use suspend caterpillar if you want to make the other heroes pathfind. Non-leader heroes do not treat NPCs as obstacles when they pathfind. The second argument is the destination x tile coordinate. The third argument is the destination y tile coordinate. The fourth argument stuck ticks is optional. If it is included, a hero who gets stuck along the way for more than the specified number of ticks will give up and stop pathfinding to the target. If stop ticks is omitted or zero, the hero will keep pathfinding even if it gets stuck, and will not stop until it reaches the destination, or is stopped with the cancel hero walk command. Be careful if you are using wait for hero to wait for pathfind hero to when no stuck ticks timeout is used, since wait for hero might wait forever if the hero has no way to get to its destination.

    hero chases npc (who, npc, stop when reached, stuck ticks)

    Makes the specified hero walk along the shortest path to the destination NPC, even if the destination NPC is moving. The chasing hero will go around obstacles. If the destination NPC cannot be reached at all, the chasing hero will go to the closest reachable tile. The first argument who is the caterpillar rank of the hero who will be chasing, or me for the leader. When the caterpillar party is enabled, this command only works on the leader, and will do nothing for other heroes. Use suspend caterpillar if you want to make the other heroes pathfind. Non-leader heroes do not treat NPCs as obstacles when they pathfind. The second argument npc is the NPC to chase. You can use an NPC reference or NPC ID. The third argument stop when reached can be true if you want the chasing hero to stop after the first time it reaches the destination NPC. If ommitted or false, the hero will keep chasing even after it reaches a moving destination NPC. The fourth argument stuck ticks is optional. If it is included, a hero who gets stuck along the way for more than the specified number of ticks will give up and stop pathfinding to the target. If stop ticks is omitted or zero, the hero will keep pathfinding even if it gets stuck, and will not stop until it reaches the destination, or is stopped with the cancel hero walk command. Be careful if you are using wait for hero to wait for hero chases NPC when no stuck ticks timeout is used, since wait for hero might wait forever if the hero has no way to get to its destination.

    cancel hero walk (who)

    If the specified hero is walking with a command like walk hero or pathfinding (due to a command like pathfind hero to or because the player clicked somewhere), they will stop. They are allowed to finish their current step to the next tile, so they will not end up misaligned with the tile grid.

    [Notice] If you want to stop a hero immediately without letting them finish their step, use walk hero with a distance of zero tiles, like:
    cancel hero walk(who) # Cancel any pathfinding
    walk hero(who, hero direction(hero), 0)
    This will misalign the hero with the tile grid, breaking movement and wall and collision checking! You are responsible for realigning the hero afterwards somehow.

    hero is chasing (who)

    If the specified hero is currently chasing an NPC, such as by clicking on the hero with mouse/touch controls, or a previous hero chases NPC command then return an NPC reference. If the hero is not currently chasing an NPC, returns false.

    set hero direction (who, direction)

    Makes the specified hero face in the specified direction (e.g. down). The hero is specified by their rank in the walkabout caterpillar, 0-3. Use me to affect the leader.

    set hero direction (me,right) # face right

    hero direction (who)

    Returns the specified hero's direction. The hero is specified by their rank in the walkabout caterpillar, 0-3

    set hero frame (who, frame)

    Sets the walking frame of the specified hero to 0 or 1. The hero is specified by their rank in the walkabout party, 0-3

    See also:

    hero frame (who)

    Returns the walking frame (0 or 1) of the specified hero. The hero is specified by their rank in the walkabout party, 0-3

    set hero position (who, x, y)

    Instantly moves the specified hero to an X,Y position on the map. The coordinates are in units of tiles. For pixel-positioning use the put hero command.

    put hero (who, x, y)

    Moves a hero to a precise location on the map. The first argument is the hero's position in the walkabout party. The second and third arguments are the X,Y pixel position of the top left corner of the hero walkabout sprite, relative to the top left corner of the map. Be aware that using this command can misalign your hero with the tile-grid, preventing it from walking normally. To position the hero by tile, use the set hero position command. Normally you will use this command to escape the tile-based movement system.

    # This script will make the hero jump in an arch 15 pixels high 2 tiles to the right,
    # but it won't animate it. You can use setheroframe or setheropicture to do that.
    variable (i, jump)
    suspend player
    set hero direction (me, right)
    jump := -5
    for (i, 0, 10) do (
      put hero (me, hero pixel X (me) + 4, hero pixel Y (me) + jump)
      jump += 1
      wait
    )
    resume player

    hero X (who)

    Returns the specified hero's X position in tiles. Note that a hero's tile is the tile its top left corner is on.

    hero Y (who)

    Returns the specified hero's Y position in tiles. Note that a hero's tile is the tile its top left corner is on.

    hero pixel X (who)

    Returns the hero's X position on the map in pixels. To find the hero's position in tiles, use the hero X function instead.

    hero pixel Y (who)

    Returns the hero's Y position on the map in pixels. To find the hero's position in tiles, use the hero Y function instead.

    forward X (who)

    Returns the X position of the tile immediately in front of the specified hero. who is optional, defaulting to 0 (me), the leader.
    Wraps over the edge of wrapping maps.

    forward Y (who)

    Returns the Y position of the tile immediately in front of the specified hero. who is optional, defaulting to 0 (me), the leader.
    Wraps over the edge of wrapping maps.

    # This will check if npc 1 is in front of the leading hero, and if so show a textbox,
    # as if you spoke to the npc. "use npc (1)" instead would actually activate it.
    if (npc X (1) == forward X && npc Y (1) == forward Y) then(
       show text box (2)
    )
    

    hero Z (who)

    Returns the specified hero's Z position in pixels. The Z value is the number of pixels they are above the tile that they are 'standing' on, not including the map's foot offset. All heroes normally have a Z value of 0 (even on maps with a foot offset) unless they are riding a vehicle which rises.

    See also:

    set hero z (who, z)

    Sets the Z location of the specified hero. The Z value is the number of pixels they are above the tile that they are 'standing' on. Useful for scripts where you want a hero to jump or levitate. All heroes normally have a Z value of 0 (even on maps with a foot offset: the foot offset is added to the Z value) unless they are riding a vehicle which rises.

    [Notice] Hero Z values are reset to 0 when you change map or dismount a vehicle, and aren't saved in saved games.
    See also:

    walk hero to x (who,x)

    Makes the specified hero walk to a given X coordinate on the map

    walk hero to y (who,x)

    Makes the specified hero walk to a given Y coordinate on the map

    check hero wall (who,direction)

    Returns true if there is a wall blocking the hero from moving in the specified direction. No actual movement takes place.

    [Notice] This command should only be used when the hero is standing still and aligned with the tile grid. You can use the check wall collision x/y commands for much more flexible wall-checking, which works from any starting position on the map.
    See also:

    get hero speed (who)

    Returns the walking speed of the specified hero, in pixels per tick.

    See also:

    set hero speed (who, speed)

    Changes the walking speed (pixels per tick) of the specified hero, from 0 to 20. who is a caterpillar slot; use me to refer to the leader. Normally only the speed of the leader matters, unless you use suspend caterpillar, because the whole party moves at the leader's speed. speed defaults to 4. Tiles are 20 pixels in size, and speeds that do not divide evenly or nearly evenly into 20 will result in jerky movement. So only use speeds 0, 1, 2, 3, 4, 5, 7, 10, or 20.

    [Notice] Changes to hero speed aren't saved in saved games!
    [Notice] Hero speed is weird. It isn't actually a property of the hero, but of the caterpillar slot. So if you change the leader's speed and then a different hero is swapped into the leader position, the leader (and party) speed doesn't change. That's usually a good thing!
    [Danger] Don't set speed to zero while a hero is moving, it will cause the hero to stop mid-step and become misaligned with the grid and stuck. Wait for the hero to stop first or check with hero is walking. (You probably shouldn't use speed 0 at all.)
    See also:

    teleport to map (map, x, y)

    An alternative to use door, teleport to map moves you to a given x,y position (in tiles) on the specified map without the need to create a door-link on the map. Teleport to map does not fade to black.

    [Notice] An automatic wait(1) occurs immediately after this command.

    gracefully dismount vehicle

    Documented in the Triggering Stuff section.

    hero is walking (who)

    Returns true if the specified hero (by position in the caterpillar) is currently walking. Returns false if the hero is standing still.


    Doors

    [Back to top-level index]

    teleport to map (map, x, y)

    Documented in the Moving Heroes section.

    use door (number, fade screen)

    Instantly uses door number, just as if you had stepped into it. fade screen is an optional argument, defaulting to true. If true, the screen will fade out before using the door (even if it leads to the same map), and fade back in one tick later. Otherwise, there are no automatic screen fades.

    [Notice] An automatic wait(1) occurs immediately after this command.
    [Notice] If you call fade screen out immediately after use door, then the screen won't automatically fade back in afterwards. That's intentional, so that you can cancel the fade. (But you might have to do this in the map autorun script, if there is one, since it will suspend the script that called use door!)

    door exists (number, map)

    Returns true if there is a door with ID number on the specified map. If you leave out the map number, the current map will be assumed. This command is useful for avoiding script errors due to invalid door IDs.

    get door x (number, map)

    Returns the x coordinate (in tiles) of the door with ID number on the specified map. If you leave out the map number, the current map will be assumed.

    See also:

    get door y (number, map)

    Returns the y coordinate (in tiles) of the door with ID number on the specified map. If you leave out the map number, the current map will be assumed.

    See also:

    get door destination id (number, map)

    Returns the door ID of the door currently linked to by the door with ID number on the specified map. If you leave out the map number, the current map will be assumed. To get the door's location, use get door x and get door y. If door number does not exist, or is not currently linked to any other door, then -1 is returned.

    [Notice]A door's destination can vary depending on tags. Check your doorlinks if you get unexpected results! There's no script command to get information about doorlinks currently inactive due to tags.

    get door destination map (number, map)

    Returns the map ID of the destination door currently linked to by the door with ID number on the specified map. If you leave out the map number, the current map will be assumed. If door number does not exist, or is not currently linked to any other door, then -1 is returned.

    [Notice]A door's destination can vary depending on tags. Check your doorlinks if you get unexpected results! There's no script command to get information about doorlinks currently inactive due to tags.

    door at spot (x, y)

    Checks whether there is a door on the position given by x, y in tiles and if so returns its ID; otherwise returns -1. Note that the door might not have any active doorlink, or no door links at all. You can use get door destination id to check if a door is active. If you want to script your own map transitions, you will find suspend doors helpful.


    NPCs

    [Back to top-level index]

    NPC reference (ID, copy, allow disabled?, pool)

    (See NPC reference for an explanation of NPC references.)
    Returns a reference to one of the NPCs on the map, or false/0 if the NPC you asked for is not found on the map.
    ID is the NPC ID of the NPC to look up. The ID is the same number that appears in CUSTOM when you are editing NPCs or placing NPCs on the map. (Unlike other NPC commands, this one does not accept an NPC reference in place of the NPC ID.)
    copy is optional. It specifies which copy (instance) of the NPC you want, in case there are more than one on the map. If you don't specify it, you will just get a reference to the first copy. Copies are counted starting from zero. You can see the copy number of NPCs in the Map Editor, at the bottom of the NPC, and using the F6 NPC debugger, by hoving the mouse over an NPC.
    allow disabled? is optional, and defaults to false. If true, when used on a copy of an NPC hidden due to tag conditions, NPC reference will return a reference instead of returning false.
    pool is an optional NPC pool. If you don't specify which pool, then the ID is assumed to refer to the local pool for the current map. See also the global NPC reference command.
    If you plan on using the same NPC reference many times in a script you can store it in a variable.

    #---NPC reference example---
    
    plotscript, ref example, begin
    
      variable(Fred)
    
      # find the first copy of NPC 10,
      # and store the reference in a variable
      Fred := NPC reference(10,0)
    
      # now we can manipulate that NPC with the variable
      walk NPC     (Fred,south,3)
      wait for NPC (Fred)
    
      # make the NPC spin!
      set NPC direction (Fred,east)
      wait(2)
      set NPC direction (Fred,north)
      wait(2)
      set NPC direction (Fred,west)
      wait(2)
      set NPC direction (Fred,south)
      wait(2)
    
    end

    global NPC reference (ID, copy, allow disabled?)

    Alias:

    global NPC (ID, copy, allow disabled?)

    This command is the same as NPC reference except that it takes a global NPC ID number instead of a local NPC ID number. If there is no copy of the global NPC ID on the current map, it will return false. This command cannot get references to NPCs located on different maps, and the NPC reference it returns is only valid on the current map.
    global NPC is an alias for global NPC reference.

    See also:

    next NPC reference (npcref)

    This command is for looping over all the npcs on the map, in the same way that first child and next sibling can be used to iterate over all the children of a slice. When called with no argument or 0, it returns an NPC reference to the first NPC on the map. When npcref is an NPC reference it returns a reference to the next NPC. It returns 0 when there are no more NPCs, and skips over NPCs that are disabled by a tag condition (including used one-time-use NPCs). It's safe to delete NPCs while you're iterating over them (unlike next sibling!), but creating NPCs at the same time might result in them getting skipped.

    [Notice] Tag-disabled NPCs are skipped.
    # Iterate over all NPCs... and delete them all!
    variable(npcref)
    npcref := next NPC reference()  # The first NPC
    while (npcref) do (
        delete NPC(npcref)
        npcref := next NPC reference(npcref)
    )

    NPC at spot (x, y, number)

    This command returns a reference to the NPC at the given X and Y coordinate, in tiles, on the map. The optional third argument lets you choose which NPC to reference in case there is more than one NPC standing on that same spot (starting from the bottom-most NPC, which is number 0). false is returned if there is no NPC there, or number is too large (greater than or equal to the number of NPCs). You can also pass the constant get count for the third argument to return the total number of NPCs on that tile.

    [Notice]An NPC's tile is the tile its top left corner is on.
    See also:

    NPC at pixel (x, y, number)

    This command returns a reference to the NPC at the given X and Y coordinate in pixels. That is, any npc whose 20x20 sprite (including transparent sections) is over that pixel. The optional third argument lets you choose which NPC to reference in case there is more than one NPC standing on that same spot (starting from the bottom-most NPC, which is number 0). false is returned if there is no NPC there, or number is too large (greater than or equal to the number of NPCs). You can also pass the constant get count for the third argument to return the total number of NPCs on that tile.

    See also:

    get NPC ID (reference)

    This command (along with NPC copy number and get NPC pool) is the inverse of NPC reference. Returns an NPC's ID. If you give get NPC ID an NPC reference it will return the NPC's ID. If the reference is not valid then get NPC ID will return -1. This command can be used on tag-disabled NPCs too, returning their ID number.

    [Notice] Some cheeky users use this command to check whether any instances of a local NPC ID exists, since like nearly all commands you can give it an NPC ID instead of a reference. E.g. get NPC ID(4) == 4 is true only if there's at least one copy of NPC 4.

    get NPC pool (reference)

    This command (along with get NPC ID and NPC copy number) is the inverse of NPC reference. This command takes an NPC reference and returns the ID of the NPC pool that this NPC belongs to: either pool:local or pool:global. reference can't be an NPC ID.

    NPC copy number (reference)

    This command is the inverse of NPC reference (along with get NPC ID). That is, it returns the copy number that you need to pass to NPC reference to get this NPC. If you give NPC copy number a reference to an NPC it will return which copy of that NPC definition it is - 0 if it's the first NPC, 1 is the second, etc. This number is also shown in the map editor at the bottom of an NPC, and in the F6 NPC debug mode when you mouse-over an NPC.
    If the reference is not valid then NPC copy number will return -1. This command also works on references to tag-disabled NPCs.

    NPC copy count (ID, pool)

    This command tells you how many copies of a particular NPC ID exist on the map. This can be very useful if you want apply the same action to each copy of an NPC on the map by looping over them. Generally this is used together with the NPC reference command.
    The pool argument is optional (defaulting to pool:local), and tells which NPC pool ID refers to.

    [Notice] This command does not count tag-disabled NPCs. So if there are four copies of NPC 2 on a map, but they only appear when tag 5 is on, then npc copy count(2) returns 4 when tag 5 is on and 0 when it isn't.
    #---NPC copy count example---
    
    plotscript, every NPC example, begin
    
      variable(copy number, guard count, current guard)
    
      # The guard is NPC 10, and there are many copies of him on the map
      guard count := NPC copy count(10)
    
      # This loop repeats once for each copy of NPC 10
      for (copy number, 0, guard count -- 1) do, begin
        current guard := NPC reference(10, copy number)
        walk NPC(current guard, south, 4)
    
        # if we added a "wait for NPC(current guard)" right here
        # then the guards would walk one at time
      end
    
    end

    change NPC ID (reference, new ID, pool)

    This command takes an NPC reference and lets you change the ID number of the NPC it points to, and change between local and global NPC pools. This means that the NPC will now use a different picture, palette, walking speed, text box, everything. This change is not permanent. It only lasts until the next time a map gets loaded. The pool argument is an optional NPC pool. If you don't specify a pool, then the NPC ID will be assumed to be the same pool that the NPC was previously part of.
    If reference is an NPC ID then this command acts on the first NPC instance of that ID/pool, and the pool is not changed.

    create NPC (ID, X, Y, direction, pool)

    This command will magically create a new copy of an NPC with the given ID number. You can specify an X and Y position where it will be created, and optionally a direction too (if you leave out the direction, the new NPC will be facing south). The pool argument is an optional NPC pool defaulting to pool:local (NPC definitions local to the current map).
    create NPC returns an NPC reference that you can use to refer to the new NPC in other commands like walk NPC. If the new NPC cannot be created (there is a maximum of 300 total NPC copies in memory at a time) then create NPC will return false (zero). The new NPC is not permanent. It only lasts until a new map is loaded.

    create global NPC (ID, X, Y, direction)

    This command works the same as the create NPC command, except that the ID number always refers to the global pool of NPCs, instead of the local pool. The instance of this global NPC will be created on the current map, and only lasts until you leave the map. It is not global in the sense of moving from map to map.

    See also:

    destroy NPC (reference)

    This command will erase the specified NPC. You can use either an NPC reference or the NPC's ID number. The deletion is not permanent. Unless this is an NPC that you created with create NPC, the NPC will be back again next time the map gets loaded. If you need to permanently remove an NPC, use tags.

    [Notice] This only deletes the one NPC you specify. If you use an NPC ID number as the argument, only the first copy of the NPC on the map will be deleted.
    [Notice] This command can be also be written as delete NPC.

    delete NPC (reference)

    An alias for destroy NPC.

    NPC is disabled (reference)

    This command returns true if the NPC reference reference points to an NPC who does not exist, or has been disabled because of tags or one-time-use.


    NPCs → Moving and Positioning NPCs

    walk NPC (who, direction, distance)

    Makes the specified NPC move in the specified direction for the specified number of tiles. The first argument tells who to move. You can use an NPC reference or NPC ID. The second argument is a direction, e.g. north. The third argument is the number of tiles to move. If you leave out the third argument, the NPC will move one tile. If you use a negative number for walk distance, the npc will walk backwards. walk NPC is usually used with the wait for NPC command. You should normally use the suspend NPCs command before moving NPCs to prevent their automatic movements from interfering with your scripted movements.

    walk NPC to X (who, X)

    Makes the specified NPC walk to a given X coordinate on the map. You can use either an NPC reference or NPC ID to specify which NPC will move.

    walk NPC to Y (who, Y)

    Makes the specified NPC walk to a given Y coordinate on the map. You can use either an NPC reference or NPC ID to specify which NPC will move.

    wait for NPC (who)

    Documented in the Wait Commands section.

    set NPC direction (who, direction)

    Makes the specified NPC face in the specified direction, e.g. north. You can use either an NPC reference or NPC ID to specify which NPC will turn.

    NPC direction (who)

    Returns the specified NPC's direction.

    pathfind NPC to (who, x, y, stuck ticks)

    Makes the specified NPC walk along the shortest path to the destination position. They will go around obstacles. If the destination cannot be reached at all, they will go to the closest reachable tile. The first argument who is the NPC. You can use an NPC reference or NPC ID. The second argument is the destination x tile coordinate. The third argument is the destination y tile coordinate. The fourth argument stuck ticks is optional. If it is included, an NPC who gets stuck along the way for more than the specified number of ticks will give up and stop pathfinding to the target. If stop ticks is omitted or zero, the npc will keep pathfinding even if it gets stuck, and will not stop until it reaches the destination, or is stopped with the cancel NPC walk command. Be careful if you are using wait for NPC to wait for pathfind NPC to when no stuck ticks timeout is used, since wait for NPC might wait forever if the NPC has no way to get to its destination.

    NPC chases NPC (who, other who, stop when reached, stuck ticks)

    Makes the specified NPC walk along the shortest path to the destination NPC, even if the destination NPC is moving. The chasing NPC will go around obstacles. If the destination NPC cannot be reached at all, the chasing NPC will go to the closest reachable tile. The first argument who is the NPC who will be chasing. The second argument other who is the NPC to chase. You can use an NPC reference or NPC ID. The third argument stop when reached can be true if you want the chasing NPC to stop after the first time it reaches the destination NPC. If omitted or false, the NPC will keep chasing even after it reaches a moving destination NPC. The fourth argument stuck ticks is optional. If it is included, an NPC who gets stuck along the way for more than the specified number of ticks will give up and stop pathfinding to the target. If stop ticks is omitted or zero, the npc will keep pathfinding even if it gets stuck, and will not stop until it reaches the destination, or is stopped with the cancel NPC walk command. Be careful if you are using wait for NPC to wait for NPC chases NPC when no stuck ticks timeout is used, since wait for NPC might wait forever if the NPC has no way to get to its destination.
    If the destination NPC is deleted or disappears due to a tag condition, the chasing NPC stops.

    NPC is chasing (who)

    If the specified NPC is currently chasing another NPC from a previous call to NPC chases NPC then return an NPC reference to the target NPC. If the NPC is not currently chasing another NPC, returns false.

    NPC is walking (who)

    Returns true if the specified NPC is currently walking, or false if standing still. You can use either an NPC reference or NPC ID to specify which NPC will be checked.

    cancel NPC walk (who)

    If the specified NPC is walking with a command like walk NPC or pathfinding with a command like pathfind NPC to, they will stop. They are allowed to finish their current step, so they will not end up misaligned with the tiles. This command has no effect on automatic NPC movement patterns, it only stops scripted movement.

    [Notice] If you want to stop an NPC immediately without letting them finish their step, use walk NPC with a distance of zero tiles, like:
    cancel NPC walk(npc)  # Cancel any pathfinding
    walk NPC(npc, NPC direction(npc), 0)
    This will misalign the NPC with the tile grid, breaking movement and wall and collision checking! You are responsible for realigning the NPC afterwards somehow.

    set NPC frame (who, frame)

    Sets the walking frame of the specified NPC to 0 or 1. You can use either an NPC reference or NPC ID to specify which NPC will change.

    See also:

    NPC frame (who)

    Returns the walking frame (0 or 1) of the specified NPC.

    set NPC position (who, X, Y)

    Instantly moves the specified NPC to an X,Y position on the map. The coordinates are in units of tiles. You can use either an NPC reference or NPC ID to specify which NPC will be moved.

    put NPC (who,x,y)

    Moves an NPC to a location on the map in pixels. The first argument is and NPC reference or an NPC ID number. The second and third arguments are the X,Y pixel position relative to the top left corner of the map. Be aware that using this command can mis-align your NPC with the tile-grid, preventing it from walking normally. To position the NPC by tile, use the set NPC position command.

    NPC X (who)

    Returns the specified NPC's X position in tiles. Note that an NPC's tile is the tile its top left corner is on.

    See also:

    NPC Y (who)

    Returns the specified NPC's Y position in tiles. Note that an NPC's tile is the tile its top left corner is on.

    See also:

    NPC pixel X (who)

    Returns the NPC's X position on the map in pixels. The argument is an NPC reference or an NPC ID number. To find the NPC's position in tiles, use the NPC X function instead.

    NPC pixel Y (who)

    Returns the NPC's Y position on the map in pixels. The argument is an NPC reference or an NPC ID number. To find the NPC's position in tiles, use the NPC Y function instead.

    NPC Z (who)

    Returns the specified NPC's Z position in pixels. The Z value is the number of pixels they are above the tile that they are 'standing' on, not including the map's foot offset. All NPCs normally have a Z value of 0 (even on maps with a foot offset) unless they are used as a vehicle which rises.

    See also:

    set NPC z (npc, z)

    Sets the Z location of the specified NPC. The Z value is the number of pixels they are above the tile that they are 'standing' on. Useful for scripts where you want a NPC to jump or levitate. All NPCs normally have a Z value of 0 (even on maps with a foot offset) unless they are a vehicle which rises.

    See also:

    check NPC wall (who, direction)

    Returns true if there is a wall blocking the NPC from moving in the specified direction. No actual movement takes place. It does not matter whether the NPC is set to ignore walls or ignore the passmap.

    [Notice] This command should only be used when the NPC is standing still and aligned with the tile grid. You can use the check wall collision x/y commands for much more flexible wall-checking, which works from any starting position on the map.
    See also:


    NPCs → NPC Instance Data

    This section contains commands for getting and setting properties of individual NPC instances. See NPC Definitions for inspecting or modifying NPC definitions/types.

    set NPC ignores walls (who, value)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), set whether that NPC can walk through walls, including off the edge of a map, and violating its zone restrictions. value should be true or false.
    Turning this on doesn't let the NPC walk through the lead hero and other NPCs; you need set NPC obstructs for that.
    This command is just like suspend NPC walls/resume NPC walls, but only affects a single npc.

    [Notice] Don't confuse this with alter NPC(who, NPCstat:ignore passmap, value), which sets whether an NPC ID can pass through walls on the wallmap, but doesn't allow it to ignore zones or walk off the map.

    get NPC ignores walls (who)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), returns whether that NPC can walk through walls.

    [Notice] Don't confuse this with read NPC(who, NPCstat:ignore passmap), which tells whether an NPC ID can pass through walls on the wallmap, but doesn't allow it to ignore zones or walk off the map.

    set NPC moves (who, value)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), set whether that NPC moves according to its move-type, or whether it stands still and waits for you to control it with walk NPC.
    value should be true or false.
    This command is just like suspend NPCs/resume NPCs, but only affects a single npc.

    [Notice] If you set an NPC to not move by itself, it will still complete its current step, moving the rest of the way to the next tile.

    get NPC moves (who)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), returns true or false indicating whether that NPC moves according to its move-type, or whether it is suspended. This is always true, even for "Stand Still" NPCs unless set NPC moves has been used.

    set NPC obstructs (who, value)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), set whether the NPC should be an obstruction to heroes and other NPCs. If set to false, the NPC can move through heroes and other NPCs and vice-versa. Heroes can always pass through Step-on NPCs. value should be true or false.
    This command is almost like suspend obstruction/resume obstruction, but it only affects a single npc and it doesn't stop activation of step-on NPCs.
    If you want to allow an NPC to walk through all obstacles, you also need to use the set NPC ignores walls command.

    get NPC obstructs (who)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), returns false if that NPC's obstruction has been suspended with set NPC obstructs (and is always true otherwise).

    set NPC usable (who, value)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), set whether the NPC can be activated by the player as normal (as defined in the NPC ID data). use NPC will still work on the NPC. value should be true or false.

    get NPC usable (who)

    Given an NPC reference or NPC ID (in which case the first NPC with that ID is used), returns false if normal activation of that NPC has been suspended with set NPC usable. This is always true otherwise, even for NPC types which are not activatable.

    See also:

    NPC extra (who, which)

    Returns an extra data value previously set on NPC instance who with set NPC extra.
    If you use an NPC ID for who, the first instance's data will be used. extra is the extra array index to read.
    This command is like get extra but only works on NPCs and accepts NPC IDs as well as NPC references.

    See also:

    set NPC extra (who, which, value)

    Sets one of the extra data variables on the NPC instance who. If you use an NPC ID for who, the first instance's data will be used. extra is an extra array index.
    This command is like set extra but only works on NPCs and accepts NPC IDs as well as NPC references. See append extra and resize extra for more ways to modify zone extra data.

    [Notice] Like other NPC instance data, the extra data for NPCs on the current map is not saved in save games! However, it is saved in mapstate NPC saves (see save map state).
    See also:


    NPCs → NPC Definitions

    These are the only commands for inspecting or modifying NPC definitions/types. All other commands act on single NPC instances (see NPC Instance Data).

    alter NPC (who, NPCstat, value, pool)

    Changes the stats of an NPC type. alter NPC can be used for many purposes. The following constants for this command are available:

    Normally you would only give an NPC ID number to alter NPC, but if you want to use an NPC reference it will still work. Just remember that alter NPC changes every copy of the NPC on the map, not just the specific one you referenced.
    The pool argument is an optional NPC pool. It cannot be used if you are specifying the NPC by reference, since then that NPC reference's current npc pool will be used.
    Changes to global npcs in pool:global will persist when you move to other maps, regardless of whether the map is set to remember NPC data. Those changes will be reset if you load a saved game or start a new game.
    A good way to make use of alter NPC is to wrap it in your own script. For example:
    # Example alter NPC wrapper for changing NPC appearance
    # Palette -1 means the default palette.
    plotscript, change NPC, who, picture, palette = -1, begin
      alter NPC(who, NPCstat:picture, picture)
      alter NPC(who, NPCstat:palette, palette)
    end

    read NPC (who, NPCstat, pool)

    Returns data such as picture, palette, walking speed, text box, etc. for an NPC. Use the same constants as alter NPC.
    The pool argument is an optional NPC pool. It is only allowed when you specify the NPC by ID number. If you specify the NPC with an NPC reference then the pool is determined by the reference.

    [Notice]If you use this command to read the give item number, the result is offset + 1. A zero means no item.
    See also:

    get NPC speed (who)

    Returns the walking speed of the specified NPC (either NPC reference or ID number) in pixels per tick.
    (This is just an alias for read NPC(who, NPCstat:movespeed)).

    set NPC speed (who, speed)

    Changes the walking speed of the specified NPC. speed defaults to 4. Tiles are 20 pixels in size, and speeds that do not divide evenly or nearly evenly into 20 will result in jerky movement. So only use speeds 0, 1, 2, 3, 4, 5, 7, 10, or 20.
    Normally you would only use an NPC ID number for who, but if you want to use an NPC reference it will still work. Just remember that set NPC speed changes every copy of the NPC on the map, not just the specific one you referenced.
    (This is just an alias for alter NPC(who, NPCstat:movespeed, speed)).

    [Warning] Don't set speed to zero while an NPC is moving, it will cause the NPC to stop mid-step and become misaligned with the grid. Get all instances of the NPC to stop first and wait for them, or check with NPC is walking.


    The Camera

    [Back to top-level index]

    camera pixel X

    Returns the X position of the top left corner of the screen in pixels.

    camera pixel Y

    Returns the Y position of the top left corner of the screen in pixels.

    camera follows hero (who)

    Normally, the camera follows your leader. With this command, you can make the camera follow any hero you want. If you leave out the argument, the camera will follow your leader as normal.

    camera follows NPC (who)

    With this command, you can make the camera follow an NPC instead of the hero. If more than one copy of the specified NPC exists, the camera will follow the first one. To revert the camera to normal, use camera follows hero.

    camera follows slice (slice)

    With this command, you can make the camera follow a slice instead of the hero. The slice's anchor point will be centered on the screen. To revert the camera to normal, use camera follows hero. Note that this command usually only makes sense for slices that are parented to a map layer, or parented to something attached to a map layer like a hero or NPC.

    pan camera (direction,distance,pixelstep)

    This command causes the camera to stop following your leader and pan in the specified direction. The first argument is a direction, e.g. north. The distance is the number of tiles you want the camera to move before it stops. You can also specify the number of pixels you want the camera to move for each tick. if you leave the last argument out, the camera will move by 2 pixels per tick. This command is normally used with wait for camera. To revert the camera to normal, use camera follows hero.

    focus camera (x,y,speed)

    This command causes the camera to focus itself on the specified X,Y tile coordinates of the map. These coordinates are in units of tiles. The third argument, the speed, tells how fast the camera will pan. If you do not specify a speed, the camera will pan 2 pixels per tick. This command is normally used with wait for camera. To revert the camera to normal, use camera follows hero.

    pixel focus camera (x,y,speed)

    This command causes the camera to focus itself on the specified X,Y pixel coordinates of the map. These coordinates are in units of pixels. The third argument, the speed, tells how fast the camera will pan. If you do not specify a speed, the camera will pan 2 pixels per tick. This command is normally used with wait for camera. To revert the camera to normal, use camera follows hero.

    put camera (x,y)

    This command causes the top left corner of the camera to instantly jump to the specified X,Y pixel coordinates of the map. These coordinates are in units of pixels, not tiles. To position the camera by tiles, just multiply the tile position by 20. To revert the camera to normal, use camera follows hero.

    wait for camera

    Documented in the Wait Commands section.


    Text Boxes

    [Back to top-level index]

    show text box (number)

    Displays the numbered text box, just as if you had talked to an NPC. The text box will not actually pop up until the next wait command. This command is most often used with the wait for text box command.

    show text box(2) # Show a text box
    wait for text box # wait until the player continues

    advance text box

    Advances a text box just as if the player had pressed a key. For use while suspend box advance is active.

    suspend box advance # stop players from mucking things up
    show text box(2)   # Show a text box
    wait(45)           # Wait about 3 seconds
    advance text box   # Next text box. Maybe it ends with "Press USE key to continue"
    resume box advance # go back to normal

    wait for text box

    Documented in the Wait Commands section.

    current text box

    Returns the number of the currently displayed text box, or -1 if there's none.

    speaking NPC

    If the player activated an NPC which showed a textbox and the hero and NPC are still "speaking" (the textbox chain isn't done), returns the NPC reference for that NPC. Otherwise returns false.

    [Warning] If you try to use this in a script called either AFTER or INSTEAD of a textbox, the textbox has closed by the time the script starts, so the NPC is no longer speaking and this will return false.
    Likewise, if an NPC calls a script directly without showing a textbox this will just return false. But you don't need speaking NPC for scripts triggered directly from NPCs, because the script is given the NPC reference as its second argument (if any). (The first argument is customisable in the NPC editor.)
    See also:

    string from textbox (ID, textbox, line, ignored)

    Loads one of the lines of a textbox into a string ID. Valid numbers for line are 0-7. Trailing and leading whitespace is stripped from the line, and embedded codes like ${H1} in the string are automatically substituted.

    [Notice]This command is obsolete and exists only for compatibility with old games: It has been replaced with textbox line. The fourth argument does nothing.

    textbox line (string ID, textbox, line, expand, strip)

    Loads one of the lines of a textbox into a string ID. Valid numbers for line are 0-7. If expand is true (which is the default) codes such as ${H1} in the string will be substituted automatically. If strip is true (which is NOT the default), white space at the beginning and end of the string are removed.

    textbox text (string ID, textbox, expand, strip)

    Loads all lines of a textbox into a single string ID. If expand is true (which is the default) codes such as ${H1} in the string will be substituted automatically. If strip is true (which is NOT the default), white space at the beginning and end of the string are removed.

    See also:


    Triggering Stuff

    [Back to top-level index]

    show text box (number)

    Documented in the Text Boxes section.

    fight formation (number)

    Starts a battle with the numbered enemy formation. This command returns true on victory and false if the battle ends for any other reason. However if all heroes die the game will still end as normal unless you set a death script. In that case, false is returned after the death script has finished. The situations which cause true to be returned are:

    The situations which cause false to be returned are:
    [Notice]An automatic wait(1) occurs immediately after this command.
    See also:

    use NPC (who)

    Remotely trigger an NPC. You can use either an NPC reference or an NPC ID. Whatever actions are associated with triggering that NPC will be taken, text box, script, vehicle, item, whatever.
    This command works even if the NPC has been made un-usable with set NPC usable and regardless of any "suspend" commands. However you can't activate an NPC that's tag-disabled (including one-time-use flags).

    [Notice] An automatic wait(1) occurs immediately after this command.

    use door (number, fade screen)

    Documented in the Doors section.

    use shop (shop)

    Takes you directly to a shop. You can specify the shop's ID number or its name in the form shop:name

    teleport to map (map, x, y)

    Documented in the Moving Heroes section.

    force mount vehicle (npc)

    Makes you mount the vehicle specified by NPC ID or NPC reference. Unlike use NPC, force mount vehicle does not bother checking the tile you are currently standing on. If the NPC is not a vehicle, nothing will happen.

    current vehicle id

    Returns the vehicle ID number of the vehicle your hero is currently riding. If you are not riding a vehicle, it will return -1

    current vehicle npc

    Returns an NPC reference to the vehicle your hero is currently riding. If you are not riding a vehicle, it will return 0 or false

    gracefully dismount vehicle

    Attempts to dismount whatever vehicle you are riding. If you are not riding a vehicle, nothing will happen. If the vehicle is not in a location where you are allowed to dismount, then nothing will happen.

    See also:

    dismount vehicle

    Forces you to instantly dismount whatever vehicle you are riding without advancing the hero or allowing an airship to land. This will work even if the vehicle is located in a place where it would not normally allow dismounting. If you are not riding a vehicle, nothing will happen.
    If you want normal dismounting behavior, as if the player had pressed the key to dismount a vehicle, use the gracefully dismount vehicle command instead.

    game over

    Resets the game and returns you to the title screen. This command is most useful for after-you-win-the-game type scripts, and for death-scripts that are triggered when you lose in battle. (The script calling game over ends immediately.) This command is similar to reset game, the main difference being that if the title screen and load screen have both been disabled (the Skip title/load screen preference bitsets), game over will completely exit the game (either taking you back to the game select screen, or exiting to the operating system), while reset game starts a new game.

    [Notice] The game will instantly transition to the title screen (or load menu, if the title is disabled) without a screen fade. So you probably want to call fade screen out beforehand.
    [Notice] By using reset game or load from slot instead, you can pass arguments to the newgame and loadgame scripts.

    reset game(args...)

    Resets and starts a new game, skipping both title and load game screens. It can be necessary to use this instead of game over so that the program will not exit if the title screen and load screen have both been disabled. It always resets the game back to the beginning and runs the new-game script. (The script calling reset game ends immediately.) You can pass any number of optional args, which become the arguments to the newgame script. For an example, see load from slot, which passes its arguments to the loadgame script in the same way.

    [Danger] The default arguments of a newgame script (and all other triggered scripts) are currently ignored. If you don't pass enough args, then the remaining arguments default to zero.
    [Notice] Unlike game over, the screen will always automatically fade out to black when calling reset game.

    run game(file string id)

    Documented in the Advanced Functions section.


    Basic Display Commands

    [Back to top-level index]

    show value (number, ...)

    show values (number, ...)

    Displays one or more numbers at the bottom left corner of the screen, which remains there until overwritten or show no value is used. Useful for count-down timers, and for debugging complicated scripts. The number of arguments to this command is variable. See show value of and trace value for similar debugging tools. You can't print strings with this command; use show string instead.

    [Notice] At most one of show value, show string, and show value of can show at once.
    				show value(hero X(me), hero Y(me))   # Shows something like "  3   14" at the bottom of the screen
    			

    show value of (expression, ...)

    Displays one or more expressions and their values at the bottom left corner of the screen, which remains there until overwritten or show no value is used. Useful for debugging complicated scripts. The number of arguments to this command is variable; each is printed as source text along with its value. You can't print strings with this command; use show string instead.

    [Notice] At most one of show value, show string, and show value of can show at once.
    # Shows something like "coins=0, hero X(me)=3, hero Y(me)=14" at the bottom of the screen
    show value of(coins, hero X(me), hero Y(me))

    show string (ID)

    Displays string #ID in the bottom left corner of the screen, as with the show value command. Use show no value to remove the string from the screen. Note that this command displays the value of the string at the moment the command was run. Later changes to the value of the string will not appear unless you run show string again. If you need real-time display of changes to a string, use show string at or center string at instead.

    show no value

    Gets rid of the number in the bottom left corner of the screen after a show value or show string command.

    cancel map name display

    If the map name is being displayed, this command makes it disappear. For example, this may be useful if you want the map name to appear when you enter a map normally, but not when you jump to the map for a plotscripted cutscene.

    show backdrop (number)

    Displays the specified full screen backdrop on the screen. This allows you to show full screen pictures without attaching them to text boxes. Use show map or show backdrop(-1) to hide the backdrop and show the map again. You can also do some simple animation effects by calling show backdrop many times with wait commands in between.
    Whether and which backdrop is displaying is saved in save games.

    [Notice]It's also possible to display backdrops as sprite slices using load backdrop sprite.

    show map

    shows the map again after a show backdrop command. Don't confuse this with show mini map


    Opening Built-in Menus

    [Back to top-level index]

    main menu

    Opens the main menu; exactly equivalent to open menu(0). If menu 0 is already open, it is brought to the top. Returns the menu handle of the new or existing instance of menu 0.
    This isn't affected by anything that prevents the player from opening the main menu in the normal ways.

    [Warning] If menu 0 does NOT have the "Allow gameplay & scripts" bit set, then your script will pause as soon as the menu opens, until either it's closed or another menu with that bit ON is opened. And once the menu has closed the menu handle is invalid!

    show mini map

    Displays the mini-map

    items menu

    Takes you directly to the items menu. Note that if the player uses an item that calls up a text box, the items menu command will behave like a show text box command for that text box.

    [Notice]If the player uses a item which kills all the heroes in the party (outside of battles a hero isn't counted as dead if their maximum HP is zero or negative), a normal game over occurs: the game over script is run if there is one, otherwise the game ends. However the game over won't happen until the next wait command (such as wait).

    status screen (who)

    Takes you directly to a hero's status screen. Specify the hero using its position in the party 0-3. Use find hero if you want to specify the hero by name. The pick hero command can also be useful.

    spells menu (who)

    Takes you directly to a hero's spells menu. Specify the hero using its position in the party 0-3. Use find hero if you want to specify the hero by name. The pick hero command can also be useful.

    [Notice]If the player uses a spell which kills all the heroes in the party (outside of battles a hero isn't counted as dead if their maximum HP is zero or negative), a normal game over occurs: the game over script is run if there is one, otherwise the game ends. However the game over won't happen until the next wait command (such as wait).

    equip menu (who, allow switching)

    Takes you directly to a hero's equip menu. Specify the hero using its position in the party 0-3. Use find hero if you want to specify the hero by name. The pick hero command can also be useful. If you do not specify any hero, the first hero in the party will be used. The optional second argument allow switching says whether to allow the player to switch to a different hero by pressing Left and Right keys. It defaults to true.

    save menu (reallysave)

    Takes you directly to the save menu. Will return the number from 1 to 1000 of the slot the player saved in, or false if the player did not save. You can optionally pass an argument of false to make the menu display without actually saving.

    load menu (reallyload, show new game)

    Displays the load game menu (unless there are no saved games, in which case it's skipped). The player can pick a saved game to load or Exit/Cancel or New Game. New Game only appears if show new game is true, which is the default, together with the Exit button. (If show new game is false the button is labelled Cancel instead of Exit.) If there are no saved games, it's equivalent to selecting New Game, even if show new game is false.
    The reallyload argument is optional, and defaults to true. When true, if the player picks a save it's loaded, if they pick New Game (or there are no saves) then the calling script continues, and if they select Exit/Cancel the game quits to the titlescreen if there is one or completely if not.
    If you pass false as reallyload argument the menu only displays (or is skipped) without actually loading or quiting. You'll need to interpret the return value to find out which option the player selected: positive values (1 to 1000) are save slot numbers, 0 means New Game/menu skipped and -1 is Quit or cancelled (pressed ESC).

    [Notice] If you want the New Game option to actually reset the game, call reset game afterwards:
    load menu
    reset game
    [Notice] If you don't want the player to be able to quit the game, only load a game or continue, then write:
    variable (slot)
    slot := load menu (false)
    if (slot > 0) then (load from slot (slot))
    See also:

    order menu

    Takes you directly to the order menu, where you can change the order of the heroes in your active party.

    team menu

    Takes you directly to the team menu, where you can change the order of the heroes in your active party, and swap heroes in and out of your reserve.

    inn screen (price, skip fade)

    Opens an Inn screen with a specific price. The optional skip fade argument defaults to false. If you set it to true, no fade effect will happen when sleeping at the inn. This command returns true if the player slept in the inn, and false if they cancelled.

    See also:

    debug menu

    Documented in the Debugging section.


    The Party

    [Back to top-level index]

    See also the Hero Data section for inspecting or modifying individual heroes.

    [Notice] You should definitely read Ways to refer to a hero in a script to understand the differences between hero ID numbers (including hero:name constants), hero party slots, and walkabout rank!


    The Party → Inspecting the Party

    leader

    Returns the hero ID number (as given in the Edit Heroes menu) of the current caterpillar party leader.

    find hero (who)

    Searches through your (battle) party to see if the specified hero is there, and returns the position where the hero was found, or -1 if the hero was not found. The position in the party is needed by most commands operating on heroes. You can use the names (constants) defined in your HSI file in the format hero:name for the ID number of the hero (as it has in the Edit Heroes menu). Not only does this tell you if a hero is in your party, but you can also use it to tell whether or not the hero is in your active party. find hero will return 0, 1, 2 or 3 if the hero is in the active party, and 4 or higher if the hero is in the reserve. Note that position in the battle party is not the same as position in the caterpillar: the leader is not necessarily hero 0. The opposite to find hero is hero by slot.

    hero by slot (where)

    This command is the reverse of find hero. Given a position in your party, it will tell you which hero is in that slot, or -1 if no hero is in that slot. The number returned can be compared with the names (constants) defined in your HSI file in the format hero:name.

    rank in caterpillar (who)

    Searches through your active party to see if the specified hero is there, and returns the position in the walkabout caterpillar where the hero was found, or -1 if the hero was not found. Use the names (constants) defined in your HSI file in the format hero:name. This is particularly useful if you need to use a command like walk hero but you are not sure which position the hero is in.

    See also:

    hero by rank (where)

    This command is the reverse of rank in caterpillar. Given a position in your walkabout party, it will tell you which hero is in that position, or -1 if no hero is in that position. The number returned can be compared with the names (constants) defined in your HSI file in the format hero:name.

    room in active party

    A function that returns the number of available spaces in your active party. It will return zero or false if there is no room.


    The Party → Changing the Party

    add hero (who)

    Puts the named hero in your party. If there is no room, the hero will be added to your reserve. Use the constants defined in your HSI file. They are in the form of hero:name. This command returns the party slot that the hero was added to, or -1 if both the active and reserve parties are completely full.

    delete hero (who)

    Removes the named hero from your party. If you have more than one copy of the hero in your party, only the first one will be deleted. Use the constants defined in your HSI file. They are in the form of hero:name

    delete hero by slot (slot)

    Removes a hero from the given slot in your party. Returns -1 if no hero was removed because the slot was already empty.

    See also:

    swap in hero (who)

    Moves the named hero in your from your reserves to your active party. If there is no room in your active party, the hero will not be moved. Use the constants defined in your HSI file. They are in the form of hero:name

    swap out hero (who)

    Moves the named hero from your active party into your reserve. Use the constants defined in your HSI file. They are in the form of hero:name

    lock hero (who)

    Locking a hero prevents the player from moving the hero on the party menu. Locked heroes in the active party cannot be moved into the reserve, and locked heroes in the reserve are completely hidden. Also prevents a hero from being moved by swap in hero or swap out hero. Use the constants defined in your HSI file. They are in the form of hero:name

    unlock hero (who)

    Reverses lock hero, and makes it possible to move a hero in and out of the active party again. Use the constants defined in your HSI file. They are in the form of hero:name

    swap by name (name,name)

    Swaps two named heroes in your party no matter what position they are in. Use the names defined in your HSI file in the form hero:name

    swap by position (slot1, slot2)

    Swaps two heroes in your party by their positions in the party (ie, by party slot).

    heal party (revive dead heroes)

    Documented in the Hero Stats section.


    Money

    [Back to top-level index]

    party money

    Returns how much money your party has.

    get money (amount)

    Adds the specified amount to your party's money

    lose money (amount)

    Subtracts the specified amount from your party's money.

    set money (amount)

    Changes the amount of money your party has.

    pay money (amount)

    A function that checks to see if you have enough money to pay the amount specified. If you do, it subtracts it, and returns true. If you do not have enough, it subtracts nothing, but returns false. Intended for use in if statements.

    if(pay money(1000)) then, begin
    	get item(item:uber sword)
    end, else, begin
    	show text box(61) # ha ha, no uber sword for you!
    	wait for text box
    end


    Items

    [Back to top-level index]

    Currently there are almost no script commands to get or set any item data, except for the name and description of an item.

    use item (item)

    Attempts to use an item as if you had selected it in the items menu. The argument is the item's ID number, or one of the item:name constants in your .hsi file. This command will only work if the item can be used outside of battle, either as a cure attack, or to teach a hero a spell, or to trigger a text box. This command does not care if you actually have any of the item in your inventory, and if it is a consumable item, you will not lose any. The return value is true if you successfully used the item, or false if the item was unusable or the user cancelled.

    [Notice]If the item causes an attack to happen which kills all the heroes in the party (outside of battles a hero isn't counted as dead if their maximum HP is zero or negative), a normal game over occurs: the game over script is run if there is one, otherwise the game ends. However the game over won't happen until the next wait command (such as wait).
    See also:

    get item name (ID, item)

    This command will take the name of item #item and stick it in string #ID, overwriting its contents. This can be useful for "You got <item>!" type messages.

    get item description (ID, item)

    This command will take the description of item #item and stick it in string #ID, overwriting its contents.

    get item maximum stack size (item)

    Returns the maximum allowed size of a stack of items in the inventory. The item argument is an item ID; you can refer to the item by number, or you can use the constants defined in your .hsi file, which are in the form of item:name. If the item uses the default stack size, then the default value is returned.

    equip where (hero, item)

    Documented in the Equipment section.


    Items → Inventory

    get item (item, number)

    Adds the specified number of the specified item to your inventory. If you do not specify a number, only one will be added. You can refer to the item by number, or you can use the constants defined in your HSI file, which are in the form of item:name

    delete item (item, number)

    Removes the specified number of the specified item from your inventory. If you do not specify a number, only one will be removed. You can refer to the item by number, or you can use the constants defined in your HSI file, which are in the form of item:name

    item in slot (slot)

    Return a the item ID number at a specific slot in your inventory. If the inventory slot is empty, it will return -1. Slots are numbered from 0 to get inventory size-1.

    set item in slot (slot, item)

    Change the item ID number at a specific slot in your inventory. The slot argument is the position in your inventory screen (slots are numbered from 0 to get inventory size-1), and the item argument is the item ID number, or one of the item:name constants defined in your .hsi file. If you want to erase an item slot, use -1 as the item ID. If the slot was empty, one copy of the item will be placed in it. Otherwise the original item count is preserved. If the maximum stack size of the new item type is less than the number of items in that slot, the extra items will be removed from that slot and placed whereever there is room.

    item count in slot (slot)

    Return the count of items at a specific slot in your inventory, or 0 if that slot is empty. Slots are numbered from 0 to get inventory size-1.

    set item count in slot (slot, count)

    Change the count of items at a specific slot in your inventory. The count argument is the new number of items from 1 up to the maximum count (which is dependent on the item, but no more than 99; see get item maximum stack size), or 0 if you want to delete any items currently in the slot. If the slot is empty or if the item count is out of bounds, this command will fail.

    get item maximum stack size (item)

    Documented in the Items section.

    use item in slot (slot)

    Attempts to use whatever item is in a given inventory slot as if you had selected it in the items menu. The argument is the inventory slot number. This command will only work if there is actually an item in the slot, and the item can be used outside of battle, either as a cure attack, or to teach a hero a spell, or to trigger a text box. The return value is true if you successfully used the item, or false if the item was unusable or the user cancelled.

    [Notice]If the item causes an attack to happen which kills all the heroes in the party (outside of battles a hero isn't counted as dead if their maximum HP is zero or negative), a normal game over occurs: the game over script is run if there is one, otherwise the game ends. However the game over won't happen until the next wait command (such as wait).
    See also:

    inventory (item)

    Returns a count of how many of the specified item are in your inventory. If you do not have the item, it returns zero or false. You can refer to the item by number, or you can use the constants defined in your HSI file, which are in the form of item:name

    get inventory size

    Returns the number of inventory slots.

    set inventory size (new size)

    Changes the number of inventory slots that are available. Use the constant inv:max to restore the maximum value. The number you give will be rounded up to the nearest multiple of 3.


    Items → Equipment

    unequip (hero, slot)

    Removes the item that the specified hero has equipped in the specified slot. The first argument is the position of the hero in your party, 0-3 for the active party, 4-40 for the reserve. (Use find hero if you want to refer to the hero by name). The second argument is the slot to unequip. Use the slot:weapon, slot:armor, etc. constants from your .hsi file.

    [Notice] When a hero's equipment changes, the current values of all stats other than HP and MP for the hero are reset to their new maximum values. The current values of the HP and MP stats are capped to the new maximums but not otherwise changed. If you want to cause the HP and MP to be scaled up or down proportionally (so that e.g. 8/10 HP becomes 16/20 HP), the easiest way to do that is to make use of a side-effect of gain hero stat:
    gain hero stat(who, stat:hp, 0)
    gain hero stat(who, stat:mp, 0)

    force equip (hero, slot, item)

    Forces a hero to equip an item, even if it is not normally equipable. The first argument is the position of the hero in your party, 0-3 for the active party, 4-40 for the reserve. (Use find hero if you want to refer to the hero by name). The second argument is the slot to equip. Use the slot:weapon, slot:armor, etc. constants (or whatever you've named the slots). (These constants can been seen in the autogenerated .hsi file.) The third argument is the item to equip. You can use the item's ID number or the item:name constants from your .hsi file. The item equipped will be deducted from your inventory, but if you force equip an item that you do not already have then a free copy of it will be created.

    [Notice] When a hero's equipment changes, their current HP and MP stats aren't updated. See the Note at unequip for more information.

    equip where (hero, item)

    Returns the number of the slot that a hero can equip an item in (a constant of the form slot:weapon, etc, in your .hsi file), or false if the hero cannot equip it. The first argument is the position of the hero in your party, 0-3 for the active party, 4-40 for the reserve. (Use find hero if you want to refer to the hero by name). The second argument is the item to check the equipability of. You can use the item's number or the item:name constants from your .hsi file.
    If the item can be equipped in more than one different slot, this command only returns the first valid slot.

    [Notice] When a hero's equipment changes, their current HP and MP stats aren't updated. See the Note at unequip for more information.

    check equipment (hero, slot)

    Returns the number of the item that the specified hero has equipped in the specified slot, or -1 if there is nothing equipped there. The first argument is the position of the hero in your party, 0-3 for the active party, 4-40 for the reserve. (Use find hero if you want to refer to the hero by name). The second argument is the slot to check. Use the slot:weapon, slot:armor, etc. constants from your .hsi file.

    get default weapon (hero)

    Returns the number of the item that the specified hero uses as a default weapon when no other weapon is equipped. The argument is the position of the hero in your party, 0-3 for the active party, 4-40 for the reserve. (Use find hero if you want to refer to the hero by name).

    set default weapon (hero, item)

    Changes the item that the specified hero uses as a default weapon when no other weapon is equipped. The first argument is the position of the hero in your party, 0-3 for the active party, 4-40 for the reserve. (Use find hero if you want to refer to the hero by name). The second argument is the item to use as the new default weapon. You can use the item's number or the item:name constants from your .HSI file.


    Effects

    [Back to top-level index]


    Effects → Music

    play song (song)

    Plays the specified song. Use the constants defined in your HSI file. They appear in the form of song:name

    play music

    An alias for play song.

    current song

    Returns the number of the currently playing song, or -1 if none.

    current music

    An alias for current song.

    stop song

    Stops whatever music is currently playing.

    stop music

    An alias for stop song.

    set victory music (song)

    Changes the after-battle victory music to the specified song. Use the constants defined in your HSI file. They appear in the form of song:name

    get victory music

    Returns the number of the after-battle victory music. Compare with the constants defined in your HSI file. They appear in the form of song:name

    set ambient music (song)

    Plays a song and sets it as the map's ambient music, that is the song that is played when you enter the map (if you call save map state with mapstate:all or mapstate:mapsettings) or after a textbox with 'restore music' set. Unless you save the mapstate, the effect goes away if you change maps or fight a battle. You can use the constants song: silence and song: same as last map for song, the default is silence.

    See also:

    get ambient music

    Returns the song number of the map's ambient music, either a song ID or the constants song: silence or song: same as last map.

    See also:

    set music volume (volume)

    Sets the volume at which music is played, volume being a number on the scale of 0 to 255, 0 being silent, 255 loudest. This is the same as the Music setting in the in-game Volume menu. If you want to manipulate the sound (e.g. fading out the music) you should take note of the original volume that the player has set and return to this later. The default volume is usually not the maximum 255, so you should not hardcode fades to begin at volume 255.

    [Notice] The actual resolution at which the volume is set is not necessarily 1/255th of full volume but depends on the engine version. For example, music_sdl only supports 128 different volume levels. So if you set the volume and then read it back, it might change slightly.

    get music volume

    Returns the volume at which music is played, on a scale of 0 to 255, 0 being silent, 255 loudest. This is the same as the Music setting in the in-game Volume menu.

    set global sound volume (volume)

    Sets the volume at which sound effects (sfx) are played, volume being a number on the scale of 0 to 255, 0 being silent, 255 loudest. This is the same as the Sound setting in the in-game Volume menu. Any currently playing sounds are affected, so this can be used for fading. If you want to temporarily change the volume you should record the original volume that the player has set and return to this later. The default volume is usually not the maximum 255, so you should not hardcode fades to begin at volume 255.

    get global sound volume

    Returns the volume at which music is played, on a scale of 0 to 255, 0 being silent, 255 loudest. This is the same as the Sound setting in the in-game Volume menu.


    Effects → Master Palette and Screen Fades

    Everything displayed on-screen uses colors from a 256-color master palette. Screen fading works by momentarily changing the colors in the palette, for example shifting them all to black. The screen fade commands are a very common source of confusion because they pause the engine during the fade, and don't redraw the screen at all. Instead, what is already on-screen (which was drawn in the previous game tick) is re-displayed with a new palette. So

    fade screen out
    show backdrop (1)
    fade screen out
    will not work as expected: the screen fades out, then it fades back in, then the backdrop appears instantly. You need to add a wait(1) immediately after the show backdrop so that the engine repaints the screen (still entirely black) with the backdrop before it fades the backdrop into view.
    This works because there's both a 'visible' master palette and a 'loaded' one. fade screen out smoothly changes the visible one to be all the same color but doesn't modified the loaded one. fade screen in changes the visible one smoothly back to the loaded one. load palette, tweak palette, write color, etc modify the loaded palette but not the visible one. You need to call either fade screen in or update palette to copy the loaded palette to the visible one to make your changes visible. update palette instantly changes the visible palette to the loaded one.
    For example, this means you can fade between two different master palettes like so:
    load palette(2)
    fade screen in

    fade screen out (red, green, blue)

    Fades the screen to a solid color. If you do not specify any arguments, the screen will fade to black. The red, green, blue values are numbers from 0 to 63 that tell how bright that particular color should be. (63,0,0) would be blood red. (40,0,40) would be purple. (63,63,63) would be bright white. The screen will remain faded out until you run fade screen in, fight a battle, or use a door.

    fade screen in

    Fades the screen back to normal after a fade screen out command, or smoothly applies the changes made with other palette commands such as greyscale palette, tweak palette, load palette, reset palette, and write color.
    (You can also make palette changes take effect immediately without a fade using update palette.)

    [Warning] Switching a game to 24-bit mode causes this command (but no others) to behave slightly differently when used after modifying the master palette (tweak palette,, etc): it does an extra (implicit) wait(1).

    load palette (palette number)

    Loads a different master palette (one of the palettes on the "View Master Palettes..." menu), and the user interface colors for that palette. Use this if a backdrop or entire map was imported/drawn with a palette other than the default. Changes to the palette do not take effect until you call update palette or fade screen in, however the UI colors are changed immediately.

    update palette

    Instantly returns from fade screen out, and applies changes made by other palette command such as greyscale palette, tweak palette, reset palette, and write color.

    greyscale palette (first, last)

    Converts a section of the master palette from color to greyscale. The two arguments determine what range of colors will be affected. If called with no arguments, the entire palette is affected. Changes do not take effect until you call update palette or fade screen in. Changes to the master palette last as long as you are playing, but are not stored in saved-games. If you need to make master-palette changes persist in saved-games you will have to use the on-load plotscript trigger.

    tweak palette (red, green, blue, first, last)

    Color-adjusts a section of the master palette. The first three arguments are the changes to make to the red, green, and blue values of each palette color. For example, tweak palette (20,-30,0) would redden everything, and drop out most of the green. These arguments expect values in the range -63 to 63, NOT -255 to 255. The last two arguments determine what range of colors will be affected. If they are left out, the entire palette is affected. Changes do not take effect until you call update palette or fade screen in. Changes to the master palette last as long as you are playing, but are not stored in saved-games. If you need to make master-palette changes persist in saved-games you will have to use the on-load plotscript trigger.

    reset palette

    Reloads the default master palette and its user interface colors, undoing any changes you have made with other palette-altering commands such as tweak palette, greyscale palette, or load palette. Changes to the palette do not take effect until you call update palette or fade screen in. However the UI color indices (those in the 'Change User-Interface Colors' menu) are changed immediately (if you're not using multiple master palettes, then UI color indices never change).

    read color (index, element)

    Returns a color value from the master palette, in the range 0 to 63. The first argument is the index in the palette to read from, 0 to 255. The second argument is the color value to read, red, green, or blue. You can use 0,1, and 2, or you can use the predefined constants color:red, color:green, and color:blue. The counterpart to this is write color.

    [Notice] This command converts color components from the usual 0-255 down to 0-63, for compatibility with old OHRRPGCE versions which ran on DOS! For operation on full color values (0-255), use get color.
    See also:

    write color (index, element, value)

    Writes a color value into the master palette. The first argument is the index in the palette to write to, 0 to 255. The second argument is the color value to write, red, green, or blue. You can use 0, 1, and 2, or you can use the predefined constants color:red, color:green, and color:blue. The third argument is the color value to write. It should be in the range of 0 to 63, NOT 0 to 255 as is used in nearly all computer programs. Use set color if you want to set color values in the 0-255 range. Changes do not take effect until you call update palette or fade screen in. Changes to the master palette last as long as you are playing, but are not stored in saved-games. If you need to make master-palette changes persist in saved-games you will have to use the on-loadgame plotscript trigger.

    See also:

    get color (index)

    Returns a color value from the master palette. The argument is which index in the palette to return. The value is a 32-bit number representing the red, green and blue components of the palette entry. See RGB for more details on its format.

    set color (index, value)

    Updates the master palette with a new 32-bit color. The value, a 32-bit number representing the red, green and blue components of the color, can come from RGB or get color. Changes do not take effect until you call update palette or fade screen in. Changes to the master palette last as long as you are playing, but are not stored in saved-games. If you need to make master-palette changes persist in saved-games you will have to use the on-loadgame plotscript trigger.

    See also:

    find color (r, g, b, searchstart)

    Searches the master palette for the color most similar to the given r, g, b triple and returns its index, from 0 to 255. The color is selected using an approximate perceptual distance function.
    r, g, b should be in the range 0-255 (but out-of-bounds values are allowed, which weights those colors even more heavily). The searchstart argument is optional, and defaults to 0. It says how many colors at the beginning of the palette to ignore. For example, if searchstart is 1, then color 0 will never be returned, which is useful because 0 is often used as the transparent color.

    RGB (red, green, blue)

    Combines the individual red, green and blue components of a color into a single 32-bit number. The formula used is "red * 256 * 256 + green * 256 + blue". The highest byte is unused, but reserved for future potential use for alpha transparency.

    See also:

    extract color (color, component)

    Takes a 32-bit color value (as returned by get color), and extracts the red, green or blue component, based on the component parameter. You may use the color:red, color:green and color:blue parameters to choose which one.

    See also:

    get ui color (color, autotoggle)

    Documented in the User Interface Colors and Box Styles section.

    set ui color (color, palette index)

    Documented in the User Interface Colors and Box Styles section.


    Effects → Sound Effects

    play sound (num, loop, preempt)

    Plays or resumes a sound effect. Pass true to loop if you want the sound effect to start over when it finishes instead of stopping (it defaults to false). Pass true to preempt if you want to automatically stop the sound before playing it. If preempt is false (which is the default), and the sound is already playing (and not paused) then this command will do nothing.

    [Notice] There isn't yet a way to play a sound effect twice at the same time.
    See also:

    stop sound (num)

    Stops a sound effect. If the sound is not playing, nothing will happen.

    See also:

    pause sound (num)

    Temporarily stops a sound effect. It can be resumed with play sound, which causes it to continue from whence it left off.

    See also:

    sound is playing (num)

    Checks to see whether a sound effect is playing or not. Useful for synchronization, etc. Returns true if the sound is paused but not stopped.

    wait for sound (num)

    Waits until a sound effect has finished playing. Useful for synchronization, etc.

    See also:

    get global sound volume

    Documented in the Music section.

    set global sound volume (volume)

    Documented in the Music section.


    User Interface Colors and Box Styles

    [Back to top-level index]

    get ui color (color, autotoggle)

    Look up which color a UI color is. color should normally be a ui: constant such as ui:menu item. See color code for a list of constants. Also, if color is a palette index (0 - 255) then it is returned unchanged.
    autotoggle is optional, and defaults to false. If true, when you get certain UI colors that normally flash (for example, ui:selected item), the return value will change every tick according to the flashing, rather than just returning the value seen in the Edit User-Interface Colors menu.

    See also:

    set ui color (color, palette index)

    Change a UI color. color should be a ui: constant such as ui:menu item. See color code for a list of constants. palette index should be a value 0-255, an index in the current master palette.

    [Notice] The change will be lost if you call load palette, reset palette, quit the game, or load a game.
    See also:

    get box style color (box style)

    Returns the background/fill color (0-255 master palette index) of box style, which should be 0 to 14.

    get box style edge color (box style)

    Returns the edge color (0-255 master palette index) of box style, which should be 0 to 14.
    This is the color of the simple line border; if the box style uses a box border spriteset (see get box style border) then the line border is usually not visible.

    get box style border (box style)

    Returns either border:line (which is -1) if a box style use a simple line border rather than a box border spriteset, or the spriteset ID of the border for box style, which should be 0 to 14.


    Hero Data

    [Back to top-level index]

    See also The Party section for commands for finding, adding, removing or swapping heroes in the party.

    [Notice] You should definitely read Ways to refer to a hero in a script to understand the differences between hero ID numbers (including hero:name constants), hero party slots, and walkabout rank!

    rename hero (who)

    Pops up a name-editing box that allows you to change the name of a hero in the party. The game and scripts are paused while this menu is up.
    The argument is the hero's ID number, or name in the format hero:name. The return value is true if the player renamed the hero, or false if they cancelled.

    rename hero by slot (who)

    Pops up a name-editing box that allows you to change the name of a hero in the party. The game and scripts are paused while this menu is up.
    The argument is the hero's position in the party as returned by find hero. The return value is true if the player the hero renamed, or false if they cancelled.


    Hero Data → Hero Graphics

    set hero picture (who, picture, type)

    Permanently changes a hero's picture. The first argument is the hero's position in the party. (Use find hero if you want refer to the hero by name.) The second argument is the index number of the picture to use (the sprite set of the appropriate type), and the last argument is a constant inside battle or outside battle or hero portrait, which determines if you are changing the hero's battle picture or their walkabout picture or their portrait. If the last argument is left out, outside battle is assumed.
    The palette is not modified (but if the palette is "default" it will of course update to the spriteset's default).

    set hero palette (who, palette, type)

    Permanently changes a hero's 16-color palette. The first argument is the hero's position in the party. (Use find hero if you want refer to the hero by name.) The second argument is the index number of the 16-color palette to use, and the last argument is a constant inside battle or outside battle or hero portrait, which determines if you are changing the hero's battle palette or their walkabout palette or their portrait palette. If the last argument is left out, outside battle is assumed.

    get hero picture (who, type)

    A function that returns the index number of a hero's picture. The first argument is the hero's position in the party as returned by find hero. The second argument is a constant inside battle or outside battle or hero portrait, which determines if you are checking the hero's battle picture or their walkabout picture or their portrait. If the second argument is left out, outside battle is assumed.

    get hero palette (who, type)

    A function that returns the index number of a hero's 16-color palette. The first argument is the hero's position in the party as returned by find hero. The second argument is a constant inside battle or outside battle or hero portrait, which determines if you are checking the hero's battle palette or their walkabout palette or their portrait palette. If the second argument is left out, outside battle is assumed.

    reset hero picture (who, type)

    Resets a hero's picture that was previously changed with set hero picture back to the default picture. The first argument is the hero's position in the party. (Use find hero if you want refer to the hero by name). The second argument is a constant inside battle or outside battle or hero portrait, which determines if you are resetting the hero's battle picture or their walkabout picture or their portrait. If the last argument is left out, outside battle is assumed.
    The palette is not modified (but if the palette is "default" it will of course update to the spriteset's default).

    reset hero palette (who, type)

    Resets a hero's palette that was previously changed with set hero palette back to the default palette. The first argument is the hero's position in the party. (Use find hero if you want refer to the hero by name.) The second argument is a constant inside battle or outside battle or hero portrait, which determines if you are resetting the hero's battle palette or their walkabout palette or their portrait palette. If the last argument is left out, outside battle is assumed.

    See also:


    Hero Data → Hero Battle Settings

    get hero auto battle (who)

    Returns true if the hero is set to fight automatically in battles, or false if the hero will be under normal player control. The hero number should be the hero's position in the battle party (not the name or caterpillar rank)

    set hero auto battle (who, bool)

    Changes whether or not the hero should fight automatically in battles (true), or if the hero will be under normal player control (false). The hero number should be the hero's position in the battle party (not the name or caterpillar rank)


    Hero Data → Hero Hand Position

    get hero hand x (who, frame)

    Get the x position of a hero's weapon hand in battle. The position is in pixels relative to the top left corner of the hero's battle sprite. The first argument is the hero's position in the party. The second argument is the attack frame. You can use the constants hand:Attack A and hand:Attack B

    get hero hand y (who, frame)

    Get the y position of a hero's weapon hand in battle. The position is in pixels relative to the top left corner of the hero's battle sprite. The first argument is the hero's position in the party. The second argument is the attack frame. You can use the constants hand:Attack A and hand:Attack B

    set hero hand x (who, frame, new x)

    Change the x position of a hero's weapon hand in battle. The position is in pixels relative to the top left corner of the hero's battle sprite. The first argument is the hero's position in the party. The second argument is the attack frame. You can use the constants hand:Attack A and hand:Attack B The third argument is the new x position.

    set hero hand y (who, frame, new y)

    Change the y position of a hero's weapon hand in battle. The position is in pixels relative to the top left corner of the hero's battle sprite. The first argument is the hero's position in the party. The second argument is the attack frame. You can use the constants hand:Attack A and hand:Attack B The third argument is the new y position.

    get default hero hand x (who, frame)

    Get the original x position of a hero's weapon hand in battle as specified in the hero editor. The position is in pixels relative to the top left corner of the hero's battle sprite. The first argument is the hero's position in the party. The second argument is the attack frame. You can use the constants hand:Attack A and hand:Attack B

    get default hero hand y (who, frame)

    Get the original y position of a hero's weapon hand in battle as specified in the hero editor. The position is in pixels relative to the top left corner of the hero's battle sprite. The first argument is the hero's position in the party. The second argument is the attack frame. You can use the constants hand:Attack A and hand:Attack B


    Hero Data → Hero Stats

    get hero stat (who, stat, type)

    A function that returns one of a hero's stats. The first argument is the position of the hero you want to check in your party as as returned by find hero. The second argument is the name of the stat that you want to check. The names of the stats are defined in your HSI file in the form stat:name. The third argument is either current stat or maximum stat or base stat. Follow those links for explanations. If you leave out the type, current stat will be assumed.

    set hero stat (who, stat, value, type)

    A command that changes one of a hero's stats. The first argument is the position of the hero you want to change in your party as returned by find hero. The second argument is the name of the stat that you want to change. The names of the stats are defined in your HSI file in the form stat:name. The third argument is the new value of the stat. The last argument is either current stat or maximum stat or base stat. Follow those links for explanations. If you leave the last argument blank, current stat will be assumed. You can set the current value of a stat to more than the maximum value. If you want to permanently change a stat you would change both the current value and just one of either the maximum value or the base value.

    [Notice] Cap stats are ignored by this command. Use set capped hero stat if you want to limit the current or maximum value of a stat to a cap. But the stat will be capped later due to certain events such as equipping or unequipping an item, levelling up, or using set hero stat cap. Caps don't apply to base stats.
    [Notice] The maximum and base values of a stat are tied together. Modifying the max will always modify the other by the same amount.
    [Notice] Modifying a hero's HP will turn on or off the hero's Is Alive tag as needed, but will not trigger a game over if all the heroes have zero HP.
    [Notice] If you want to permanently increase or decrease the max and base of a stat just use gain hero stat.
    # Use this script to reset a stat to its max value
    script, reset stat, hero slot, stat, begin
      set hero stat(hero slot, stat, get hero stat(hero slot, stat, maximum stat), current stat) 
    end
    # Increase (or decrease, if amount is negative) the current value
    # of a stat (so, make a temporary change) without violating stat caps or going below zero.
    # You can use the "gain hero stat" command instead to make a permanent change.
    script, adjust stat, hero slot, stat, amount, begin 
      variable (value)
      value := get hero stat(hero slot, stat, current stat) + amount
      if (value < 0) then (value := 0)
      set capped hero stat(hero slot, stat, value, current stat)
    end

    gain hero stat (who, stat, amount, reset to max)

    Permanently increase or decrease one of a hero's stats. The base, maximum and current value of the stat are all changed, consistently.
    The first argument who is the position in your party of the hero you want to change, as returned by find hero.
    The second argument is the name of the stat that you want to change. The names of the stats are defined in your HSI file in the form stat:name, such as stat:hp.
    The third argument is the amount to change the stat; it will be added to the base value and maximum value of the stat.
    The optional fourth argument reset to max says how the current value of the stat should be updated. If false (which is the default), the current value will be set so that it's the same percentage of the max before and after. For example, 8/10 HP become 12/15 HP. If reset to max is true, then the current value is set equal to the max.
    The maximum and current stat values are capped to the stat cap, if any. (Base stats are by definition not capped.)

    set capped hero stat (who, stat, value, type)

    A command that changes one of a hero's stats. The first argument is the position of the hero you want to change in your party as returned by find hero. The second argument is the name of the stat that you want to change. The names of the stats are defined in your HSI file in the form stat:name. The third argument is the new value of the stat. Unlike set hero stat, if you try to set a stat to a value larger than the stat cap it will be reduced to the stat cap (without an error). The last argument is either current stat or maximum stat (base stat will also work but will not be capped). If you leave the last argument out, current stat will be assumed.

    get hero stat cap (stat)

    A function that returns the maximum allowed value for a hero stat (as set in the Stat Caps menu in Custom). The argument is the stat you want to check; one of the stat:name constants defined in your HSI file. If the return value is 0 or false there is no stat cap for that stat.

    set hero stat cap (stat, value)

    Set the maximum allowed value for a hero stat. The stat argument is the stat to affect; one of the stat:name constants defined in your HSI file. The value argument should be either greater than zero to set a cap, or 0/false to remove the cap for that stat.

    [Notice]The new cap comes into immediate force: the current and maximum values of all stats of all heroes in the party are capped according to the caps. In addition, the current values of all stats other than HP and MP for all heroes are reset to their new maximum values. The current values of the HP and MP stats are not otherwise changed aside from being capped, so you might like to check and scale up HP and MP of heroes if the new max is more than the old cap.

    get level MP (who, mp level slot, type)

    Returns a hero's level MP (FF1-style MP). The argument who is the hero's position in the party, as returned by find hero. The argument mp level slot is a number from 0 to 7 that represents a row of spells in the hero's spell list (the level is NOT counted from 1 to 8, as it's displayed in-game and in the spell-list editor!) The optional third argument is either current stat or maximum stat. If you leave out the type current stat will be assumed. Pass maximum stat instead to get the hero's maximum amount of level MP for that slot. The maximum depends only on the hero's experience level.

    set level MP (who, mp level slot, new value)

    Changes one of a hero's level MP (FF1-style MP) numbers. The argument who is the hero's position in the party, as returned by find hero. The argument mp level slot is a number from 0 to 7 that represents a row of spells in the hero's spell list (the level is NOT counted from 1 to 8, as it's displayed in-game and in the spell-list editor!) The argument new value is the new number of level MP points. Each point lets the player cast one spell from that row.
    This changes the current value of a Level MP stat, therefore changes will be erased if the hero levels up or otherwise has their MP restored (e.g. by an inn). There's not yet any command to make a permanent change (to maximum level MP).

    hero uses level MP (who)

    Returns true if a hero makes use of level MP (FF1-style MP). The argument who is the hero's position in the party, as returned by find hero. This will be true if the hero has at least one named spell list set to use level MP, and that spell list is included in their battle menu. This is the same logic that is used internall to decide if Level MP will be displayed on the Status screen.

    heal party (revive dead heroes)

    Restores the HP, MP and level MP of the active party heroes to 100%, just like inns or the textbox "Restore HP & MP" conditional do.
    The optional revive dead heroes argument tells whether heroes with 0 HP should be healed. If omitted, the General Preference Bitset "Inns Don't Revive Dead Heroes" determines the default.

    hero base elemental resist as int (who, element)

    Gets the 'intrinsic' amount of damage that a hero receives from attacks of a certain element, as a percentage of normal. (That is, the value entered in the 'Elemental Resistances' menu in Custom. Equipment elemental modifiers are added onto this value.) The argument who is the hero's position in the party, as returned by find hero. The argument element is a number from 0 to whatever the highest enabled element is. The result is rounded to the nearest integer. For example, if the hero takes 2.6% damage (1/40 normal), then the result will be 3.

    [Notice]When floating point support is added to HamsterSpeak, an alternative to this command will be added.

    set hero base elemental resist (who, element, percent)

    Sets the 'intrinsic' amount of damage that a hero receives from attacks of a certain element, as a percentage of normal. (That is, the value entered in the 'Elemental Resistances' menu in Custom. Equipment elemental modifiers are added onto this value.) The argument who is the hero's position in the party, as returned by find hero. The argument element is a number from 0 to whatever the highest enabled element is. The argument percent is the percentage (written without a percent sign). For example -50 means the hero is healed by 50% of the attack damage instead of being hurt.

    [Notice]Unlike the elemental resist editors in Custom, you can't use fractions of a percent here.

    hero total elemental resist as int (who, element)

    Gets the amount of damage that a hero receives from attacks of a certain element, as a percentage of normal. The argument who is the hero's position in the party, as returned by find hero. The argument element is a number from 0 to whatever the highest enabled element is. The result is rounded to the nearest integer. For example, if the hero takes 2.6% damage (1/40 normal), then the result will be 3. This is the value calculated from the hero's 'intrinsic' resistances combined with the equipment they are wearing.

    [Notice]When floating point support is added to HamsterSpeak, an alternative to this command will be added.


    Hero Data → Hero Stats → Experience and Levels

    get hero level (who)

    A function that returns a hero's current level. The argument is the position of the hero you want to check in your party as as returned by find hero. The return value with be your current level, from 0 to 99

    set hero level (who, level, forgetspells)

    A command that sets a hero's current level. The first argument is the position of the hero you want to change in your party as as returned by find hero. You can specify any hero in the active or reserve party and any (non-negative) level (even above the level cap). Unlike old workarounds, this command teaches the hero any spells they would have learnt by that level and correctly sets the experience to next level-up (experience gained to the current next level is lost). You can also decrease the hero's level, which will cause spells to be forgotten, unless the optional 3rd argument (defaulting to true) is set as false.

    set experience (who, experience, allowforget)

    Sets a hero's total experience and updates their experience level, stats and spell list. The argument is the position of the hero you want to check in your party as as returned by find hero. To decrease a hero's level without forgetting spells which are learnt at a certain experience level, pass false as the optional third argument. Heroes won't level beyond the level cap (which is 99 usually), though you can temporarily raise the cap using set level cap to get around this.

    update level up learning(who, allowforget)

    Documented in the Hero's Spells section.

    hero levelled (who)

    Returns the number of levels the specified hero gained. who is the hero's position in the battle party. If you want to use hero:Name you should use find hero. This command only applies to the most recent battle or give experience, set hero level or set experience command that targeted either this hero (or who party) - levels gained from previous battles or commands are forgotten. If the hero lost levels, the result is negative. In other words, this does not return true or false, but can be be used in an if statement like:

    give experience (party, 50)
    if (herolevelled (find hero (hero: Bob))) then (
      $31="Bob gained "
      append number(31, hero levelled (find hero (hero: Bob)))
      $31+" level(s)!"
      show textbox (233) # ${S31} :show string 31
    )

    spells learned (hero, number)

    Documented in the Hero's Spells section.

    total experience (who)

    Returns a hero's total experience. The argument is the position of the hero you want to check in your party as as returned by find hero.

    See also:

    experience to next level (who)

    Returns experience required by a hero to reach the next level. The argument is the position of the hero you want to check in your party as as returned by find hero.

    experience to level (level, hero slot)

    Returns the total experience required to reach a specified level from level 0. The second argument is a hero slot. Different heroes may have different experience curves. If the hero slot argument is left out, then the default experience curve will be used.

    give experience (hero, amount)

    Gives experience to either a hero by position in party (use result returned by find hero command if you want to give experience by name or ID) or the whole party, if the constant party is passed as first argument. If you give experience to the whole party, then it will be split amongst the heroes as it is in battle; dead heroes get experience depending on whether the "Dead heroes gain share of experience" general bitset is set, and swapped out heroes gain according to the options in the Battle System Options menu. This command can cause heroes to level up and learn spells but does not inform the player or trigger any effects. See hero levelled and spells learned for dealing with this. This command can give negative experience, but it will never cause a hero to delevel. You should use set experience to remove experience in a way that allows delevelling. You can't give experience to heroes with level equal to or greater than the level cap (which is 99 usually), though you can temporarily raise the cap using set level cap to get around this.


    Hero Data → Hero's Spells

    teach spell (hero, attack)

    Tries to teach a hero a spell. This only works when the spell is set to "learned from item" in one of the hero's spell lists; it will not work for spells learned based on level. The first argument is the hero's position in the party (as returned by find hero). The second argument is the attack to learn. You can use the names defined in your .HSI file in the form atk:attackname. (You may also use the attack's ID number. This is the number you see in the attack editor + 1.) If the hero was taught the spell, teach spell will return true, or if the hero cannot learn the spell (perhaps because they already know it) it will return false. Use write spell to add a spell to a spell list without restriction.

    forget spell (hero, attack)

    Causes a hero to forget a spell, by deleting all occurrences of it in their spell lists, regardless of how the spell was learnt. If the hero doesn't know the spell, nothing happens. (This doesn't affect attacks which are options directly in the hero's battle menu.) Returns true if the hero knew the spell, false if not.
    The first argument is the hero's position in the party (as returned by find hero).
    The second argument is the attack to forget. You can use the constants (defined in your .hsi file) in the form atk:attackname. (You may also use the attack's ID number. This is the number you see in the attack editor + 1).

    read spell (hero, list, slot)

    Checks what spell (attack) is in a certain slot of a hero spell list. Returns 0 (false) if the slot is empty, otherwise the attack ID (i.e. one of the atk:attackname constants), which is the ID shown in the attack editor + 1. The first argument is the hero's position in the party (as returned by find hero). The second argument is the number of the spell list to check. This is a value from 0 to 3. The third argument is the slot to check. This is a number from 0 to 23. Spell slots are numbered in rows, so the first row is 0,1,2 the second row is 3,4,5, and so on.

    write spell (hero, list, slot, attack)

    Forces a hero to learn a particular spell. The first argument is the hero's position in the party (as returned by find hero). The second argument is the spell list to put the spell in. This is a number from 0 to 3. The third argument is the slot to put the spell in. This is a number from 0 to 23. Spell slots are numbered in rows, so the first row is 0,1,2 the second row is 3,4,5, and so-on. The last argument is the attack to put in the spell list. You can use the names defined in your .HSI file in the form atk:attackname (You may also use the attack's ID number. This is the number you see in the attack editor + 1). You can also erase a spell by writing 0 or none as the attack ID. Note that this command will overwrite and replace any spell that is already in that slot. If you overwrite a slot that can normally learn another spell, you will never learn that other spell (unless you first erase the spell you wrote there)

    knows spell (hero, attack)

    Checks whether a hero already knows a spell (whether it's in one of their spell lists - if it's an option directly in the hero's battle menu that doesn't count!) and returns true or false.
    The first argument is the hero's position in the party (as returned by find hero).
    The second argument is the attack to check for. You can use the constants (defined in your .hsi file) in the form atk:attackname. (You may also use the attack's ID number. This is the number you see in the attack editor + 1).

    can learn spell (hero, attack)

    Checks whether a hero is capable of learning a spell from an item (and therefore also with the teach spell command) and returns true or false.
    The first argument is the hero's position in the party (as returned by find hero).
    The second argument is the attack to check for. You can use the constants (defined in your .hsi file) in the form atk:attackname. (You may also use the attack's ID number. This is the number you see in the attack editor + 1).

    spells learnt (hero, number)

    This is deprecated, do not use it. It is identical to spells learned except it returns the id numbers of spells, instead of the id numbers +1. The attack constants exported in your .hsi file are all +1 the attack IDs in Custom.

    spells learned (hero, number)

    Returns the id numbers (+1) of spells the hero learned from the last battle or give experience, set hero level or set experience command that targeted either this hero or the whole party. If the second argument is get count then the number of spells that the hero learned is returned. Pass 0 for number to get the first spell learnt, 1 to get the second, etc. You can use a loop and strings to list to the player all the spells a hero learned:

    [Notice]If you want to compare attacks returned by this command with attack ID numbers, you must add 1 to the ID number, unless you use atk:... constants.
    # The following script uses strings 0, 1, 2 for its use (they will be overwritten)
    plotscript, print learned spells, who=0, begin
      variable(i)
      get hero name (1, who)  # construct the static part of the text in string 1
      $1+" learned spell "
      for (i, 0, spells learned (who, get count) -- 1) do (
        read attack name (2, spells learned (who, i))  # get the i-th spell learnt
        0 $= 1  # copy the static part to the displayed string
        0 $+ 2  # combine with the spell name
        show string at (0, 160, 100)
        wait for key (anykey)
      )
      hide string (0)
    end

    update level up learning(who, allowforget)

    Update a hero to make sure they know the spells they are supposed to have learned for their current level. The who is the hero's position in the battle party. You can optionally pass false as the allowforget argument if you want to make sure the hero will not forget any spells that they are not supposed to know yet. This command is most useful for situations where you are manipulating the hero's level, and for some reason do not want to use set hero level which automatically handles spell learning. This command can also be handy when playtesting a game in progress, since it can be used to make sure that heroes loaded from a saved-game will learn spells that did not exist yet at the time when they got their last level-ups.


    Hero Data → Out-of-battle Attacks

    outside battle cure (attack minus 1, target, attacker)

    Obsolete, replaced by map cure. This is identical to mapcure except for the attack argument differing by one.

    map cure (attack, target, attacker)

    Uses an attack on a hero outside of battle as if you had used it from an item or cast it as a spell. In spite of the name, it works for both cure spells and damage spells. The first argument, attack is name of the attack from your HSI file in the form atk:name. (You may also use the attack's ID number. This is the number you see in the attack editor + 1.) The second argument, target is the position in the party of the hero to cure (or harm). The third optional argument, attacker is the position in the party of the hero who is using the attack. If this argument is omitted or set to -1, then the average stats of the active party will be used, just like when the attack is used from an item. The return value is true if the cure/attack succeeded, and false if it did nothing.

    [Notice]The map cure command replaces the old command outside battle cure which had a bug which required you to use atk:name -- 1 instead of atk:name for the attack argument.
    [Notice]If the attack results in all the heroes in the party being dead (outside of battles a hero isn't counted as dead if their maximum HP is zero or negative), a normal game over occurs: the game over script is run if there is one, otherwise the game ends. However the game over won't happen until the next wait command (such as wait).
    [Notice] If you want to cure a hero that has 0 HP with an attack, then the attack's Target Class needs to be set to something that allows targetting dead heroes. Otherwise the attack doesn't happen and this command returns false. Other Target settings, including "Spread Attack", are ignored.


    Attack Data

    [Back to top-level index]

    get attack name

    An alias for read attack name.

    read attack name (str ID, attack)

    This command will take the name of attack and stick it in the str ID string, overwriting its contents. Use the atk:name constants from your HSI file.

    [Notice] If you want to use this command with attack ID numbers, you must add 1 to the ID number.
    [Notice] This command replaces the old get attack name which required you to use atk:name -- 2 or the attack id number -- 1

    get attack caption (str ID, attack)

    This command will take the caption of attack and stick it in the str ID string, overwriting its contents. Use the atk:name constants from your HSI file as the attack.

    [Notice] If you want to use this command with attack ID numbers, you must add 1 to the ID displayed in the attack editor.

    get attack extra (attack, extra num)

    Returns the value in one of an attack's "extra data" fields, which you can set in the Misc submenu. Use the atk:name constants from your HSI file as the attack ID. extra num is an extra array index.

    [Notice] If you want to use this command with attack ID numbers, you must add 1 to the ID displayed in the attack editor.


    Enemy and Formation Functions

    [Back to top-level index]

    get enemy stat(enemy, stat)

    Returns the selected stat from the selected enemy definition. The first argument is the number of the enemy whose stats you want to check. The second argument is the name of the stat that you want to check. The names of the stats are defined in your HSI file in the form stat:name.

    set enemy stat(enemy, stat, value)

    Sets the selected stat of the selected enemy definition to the value you supply. The first argument is the number of the enemy whose stats you want to set. The second argument is the name of the stat that you want to set. The names of the stats are defined in your HSI file in the form stat:name. The third is the new value of the stat.

    [Notice] Enemy stat changes are temporary. They are not saved in saved games. If you want to reset them early, use reset enemy stat.

    reset enemy stat(enemy, stat)

    Resets the selected stat of the selected enemy definition to its original value as set in the editor. enemy is an enemy ID and stat is the name of the stat that you want to check. The names of the stats are defined in your HSI file in the form stat:name.

    enemy elemental resist as int (enemy, element)

    Gets the amount of damage that an enemy receives from attacks of a certain element, as a percentage of normal. The argument enemy is the enemy's ID number. The argument element is a number from 0 to whatever the highest enabled element is. The result is rounded to the nearest integer. For example, if the enemy takes 2.6% damage (1/40th normal), then the result will be 3.

    [Notice]When floating point support is added to HamsterSpeak, an alternative to this command will be added.

    get enemy name (enemyid, stringid)

    Put the name of an enemy in a string. enemyid is the number of the enemy (you can use a constant like enemy: skeleton, and stringid is the number of the string in which to store the name of the enemy.

    [Warning] The arguments are the opposite order to every other "get ... name" command! Whoops!
    See also:

    set enemy name (enemyid, stringid)

    Lets you change an enemy's name to a new name in a string. The string length cannot be more then 16 characters, if it is more then 16 the name will be truncated.
    enemyid is the number of the enemy (you can use a constant like enemy: skeleton, and stringid is the number of the string that you supply the name of the enemy from.

    [Notice] Enemy name changes are temporary. They are not saved in saved games. If you want to reset them early, use reset enemy name.

    reset enemy name (enemyid)

    Resets the name of an enemy to the value originally set in the editor. enemyid is the number of the enemy.

    get enemy appearance (enemyid, appearance)

    Returns data on the appearance of a enemy. enemyid is the enemy number that you want to return the appearance of, appearance is one of the following constants:


    You can compare the values returned for enemy:picturesize with the constants enemysize:small, enemysize:medium and enemysize:large.
    This command is just an alias for read enemy data.

    set enemy appearance (enemyid, appearance, value)

    Lets you change an enemy's appearance. enemyid is the number of the enemy's appearance that you want to change, appearance is one of the constants given in get enemy appearance. value is the value to assign: spriteset id for enemy:picture; constants enemysize:small, enemysize:medium, or enemysize:large when changing picture size (spriteset group); or palette number when changing palette.

    [Notice] Enemy appearance changes are temporary: they are not saved in saved games. If you want to reset them early, use reset enemy data, because set enemy appearance is (now) just an alias for write enemy data.

    read enemy data (enemyid, data)

    Returns the enemy's reward values. Enemyid is the number of enemy, data is a predefined constant defining the data you want returned. Use the following constants:

    See also:

    write enemy data (enemyid, data, value)

    Lets you set items of an enemy's data. enemyid is the number of enemy. data is a predefined constant for the data you want to change: use the same constants listed at read enemy data. value is the new value given to that setting.

    [Notice] Enemy data changes are temporary. They are not saved in saved games. If you want to reset them early, use reset enemy data.

    reset enemy data (enemyid, data)

    Undoes the effect of write enemy data, resetting one piece of an enemy's data to the original value set in the enemy editor. enemyid is the number of enemy. data is a predefined constant for the data you want to change: use the constants listed at read enemy data or get enemy appearance.


    Enemy and Formation Functions → Formations

    add enemy to formation (formation, enemy id, x, y, slot)

    Adds an enemy with given enemy id (use the constants of the form enemy:name in your exported .hsi file) to the specified formation. give the position of the center of the bottom edge of the enemy (approximately where it appears to stand), relative to the center 320x200 of the screen. Use the formation editor to get coordinates to feed into this command. slot (0 to 7) is an optional argument, if you specify it, then the enemy is created in the suggested slot if empty. If you omit slot or slot isn't empty, the enemy is put in the first empty slot. The actual slot number used is returned, or -1 if the enemy couldn't be added.

    [Notice] Changes to enemy formations are temporary: they are not saved in save files.

    delete enemy from formation (formation, slot)

    Deletes an enemy in the given slot (as returned by find enemy in formation for example) in the formation.

    [Notice]Changes to enemy formations are temporary: they are not saved in save files.

    find enemy in formation (formation, enemy id, copy number)

    Searches for an enemy in a formation, returning the slot number, or -1 if not found. copy number is optional, use 0 or greater specify which enemy to return if there is more than one, or the constant get count. The first (searching the slots sequentially) enemy copy is number 0. The number of specified enemies in the formation is returned if the constant get count is used. enemy id can be either an enemy id, or the constant any enemy, which searches for any enemy (the first enemy in the formation by default), or the total number of enemies with get count.

    plotscript, look at formation, formation, begin
      # In this example, we'll pick a random enemy from a formation, and check if there are any plips.
      # You'll need an enemy named plip to try this out, or change the "enemy:plip" constant below to something else
      variable (number of enemies, random enemy slot)
    
      # The total number of enemies
      number of enemies := find enemy in formation (formation, any enemy, get count)
      # Pick an enemy at random
      random enemy slot := find enemy in formation (formation, any enemy, random(0, number of enemies -- 1))
    
      $30 = "There is a "
      # Here we append the enemy's name to string 30
      get enemy name (formation slot enemy (formation, random enemy slot), 30)
      $30 + " in this formation"
      show string (30)
    
      # Let's check whether there is at least one plip in this formation
      variable (number, plip slot)
      number := find enemy in formation (formation, enemy:plip, get count)
      if (number > 0) then (
        # We'll put a string onscreen where the plip appears in battle
        $31 = "Plip!"
        plip slot := find enemy in formation (formation, enemy:plip)
        center string at (31, formation slot x (formation, plip slot), formation slot y (formation, plip slot) -- 20)
      )
    end
    

    formation slot enemy (formation, slot)

    Returns the ID number of the enemy in the specified formation slot (0 to 7), or -1 if the slot is empty.

    formation slot x (formation, slot)

    Returns the x position of the center of the enemy in the specified formation slot (0 to 7). An enemy's position is the center of the bottom edge of the enemy - approximately where it appears to stand.

    formation slot y (formation, slot)

    Returns the y position of the bottom edge of the enemy sprite in the specified formation slot (0 to 7). An enemy's position is the center of the bottom edge of the enemy - approximately where it appears to stand.

    set formation background (formation, background, animation frames, animation ticks)

    Sets the background and the background animation for a formation. The animation arguments do not need to be given, producing a static background. animation frames, optional, is the number of frames (1 to 50) to use for the background animation. 1 is non-animating. animation ticks, also optional, is the number of ticks to display each backdrop for. The engine normally (but not reliably) runs at 18 ticks per second.

    [Notice]Changes to enemy formations are temporary: they are not saved in save files.

    get formation background (formation)

    Gets the background used by a formation. If the backdrop is animated, this returns the ID of the first backdrop (the one set in Custom).

    set formation song (formation, song)

    Changes an enemy formation to use song as its music. Use the constants of the form song:songname from your exported .hsi file, or the special constants song: silence or song: same as map

    [Notice]Changes to enemy formations are temporary: they are not saved in save files.

    get formation song (formation)

    Returns the song associated with formation. Compare the result with the constants of the form song:songname from your exported .hsi file, or the special constants song: silence or song: same as map.

    reset formation (formation)

    Reset any scripted changes to formation. This script erases changes made with add enemy to formation, delete enemy from formation, set formation background, and set formation song and changes the formation back to the way it was defined in the Formation Editor in custom.

    reset formation slot (formation, slot)

    Reset any scripted changes to a specific slot in a formation. This script erases changes to enemy id, enemy x, and enemy y made with add enemy to formation or delete enemy from formation and changes the formation slot back to the way it was defined in the Formation Editor in custom.

    See also:

    last formation

    Returns the last formation fought. If the player hasn't fought any formations yet (since starting or loading the game), it returns -1.

    See also:

    random formation (formation set)

    Picks a formation randomly from the given formation set (1 to 255), returning the formation number.

    formation set frequency (formation set)

    Returns the formation frequency (from 0 to 200) of a formation set (1 to 255), as set in the Formation Set Editor. Note that the frequency is not actually a probability (as a percentage) of a battle occurring each step, but is roughly the number of battles per 100 steps, spaced randomly. The frequency is used to update the random battle countdown every step (see get battle countdown).

    get battle countdown

    Returns the random battle countdown value. This counter starts at a random value from 40 to 160, and is reduced by the formation set frequency whenever the player steps on a tile marked on the foemap. When it reaches zero a formation from that formation set is triggered and it resets.

    set battle countdown (value)

    Sets the random battle countdown value (see get battle countdown). Setting the value to 0 or less means that the next step will trigger a battle (even if the frequency is 0!) The counter is saved in save games, but resets when fighting a battle (for any reason), using a door (even to the same map) or teleport to map, or dismounting a vehicle.

    formation probability (formation set, formation)

    Returns the probability of a particular formation in a formation set being fought, as a percentage from 0 to 100. This does take the number of times the formation appears in the formation set into account.


    Getting Player Input

    [Back to top-level index]

    pick hero (message, skip if alone)

    Pops up a hero-picker box that lets you choose one of the heroes in your active party. The return value is the position in the party of the hero you picked, or -1 if the player cancelled.
    Both arguments are optional.
    message is the ID of the string to use for the prompt, which defaults to "Which Hero?". If you leave it out or pass -1, the default message is used, which is defined in the Global Text Strings menu (search it for "pick hero").
    If skip if alone is true then if there's only one hero in the active party then will automatically be picked, without showing the menu. It defaults to false!

    rename hero (who)

    Documented in the Hero Data section.

    rename hero by slot (who)

    Documented in the Hero Data section.


    Getting Player Input → Keyboard Input

    There are three main commands for checking for keypresses: keypress, new keypress and key is pressed. Use key is pressed (which checks whether a key is down) when you want the player to do something continually, such for moving, running, jumping, or attacking repeatedly each time a cooldown expires (you'll need to script your own cooldown). For nearly everything else you will use keypress, (or new keypress instead if you don't want key repeat), such as when you script a menu (both activating menu items and moving the cursor - since the cursor moves in jumps rather than continually), or to use a special ability such throwing a ball. You should use keypress for key repeat for scripted menus.

    [Notice] You can NOT wait for the player to press a key by continually polling key is pressed, etc, in a while loop unless you stick a wait in your loop. That's because key, joystick and mouse commands don't return real time data, but the state of the devices at the beginning of the current game tick (after the last wait).

    key is pressed (scancode, player)

    Returns true if the keyboard or joystick key with the specified scancode is being pressed (either held down or pressed since last tick), or false if it is not. The scancode argument is a scancode such as a keyboard key (e.g. key:ctrl) a joystick button (e.g. joy:left), or a virtual scancode such as use key (see control codes).
    player is an optional player number, normally only used with joy:... joystick scancodes or control codes, and tells which player's controller to read. By default it checks for a button press on any plugged-in controller.

    [Notice] This command is an alternative to keypress or new keypress; see Keyboard Input for usage hints.
    You can use keypress time to see how long a key/button has been down.
    [Notice] Previously you couldn't use virtual scancodes like use key, which could only be used with wait for key. Now all key commands accept any kind of constant; what a relief!
    [Warning] You can't rely on the behaviour of the caps-, scroll- and num-lock keys. They might report on/off state instead of pressed/not pressed, depending on the graphics backend, operating system, and engine version.

    keypress (scancode, player)

    Checks for a keypress event, and returns true or false. A keypress happens either when there's a new keypress (the key/button gets pressed down), or each time it repeats once it's been held down for a little while (18 times a second after it's been held half a second, by default).
    The scancode argument is a scancode such as a keyboard key (e.g. key:ctrl) a joystick button (e.g. joy:left), or a virtual scancode such as use key (see control codes).
    player is an optional player number, normally only used with joy:... joystick scancodes or control codes, and tells which player's controller to read. By default it checks for a button press on any plugged-in controller.

    [Notice] This command is an alternative to new keypress or key is pressed; see Keyboard Input for usage hints.
    [Warning] It's not a good idea to rely on the key repeat rate for things that affect gameplay such as the rate at which you can shoot bullets! The repeat rate is once every 55 milliseconds (18 times a second), independent of the frames per second (fps) that the game is running at. Suppose you use key repeat to shoot bullets and your game runs at 36 fps, then a bullet will be fired every other frame. But if played on a really slow computer that only ran the game at 18 fps, a bullet will be fired every frame!

    new keypress (scancode, player)

    Checks for a new keypress (the key/button gets pressed down), and returns true or false.
    The scancode argument is a scancode such as a keyboard key (e.g. key:ctrl) a joystick button (e.g. joy:left), or a virtual scancode such as use key (see control codes).
    player is an optional player number, normally only used with joy:... joystick scancodes or control codes, and tells which player's controller to read. By default it checks for a button press on any plugged-in controller.

    [Notice] This command is an alternative to keypress or key is pressed; see Keyboard Input for hints.

    keyval (scancode, player)

    (Obsolete, you can now use simpler commands like keypress instead.)
    Returns a bitmask for the state of the specified key, joystick/gamepad button, or virtual scancode.
    The scancode argument is a scancode such as a keyboard key (e.g. key:ctrl) a joystick button (e.g. joy:left), or a virtual scancode such as use key (see control codes).
    player is an optional player number, normally only used with joy:... joystick scancodes or control codes, and tells which player's controller to read. By default it checks for a button press on any plugged-in controller.
    The result holds the same information as given by the key is pressed and keypress commands, so you can use those instead. The first (least significant) bit is whether the key was depressed at the beginning of the current tick. The second bit is whether a keypress event happened (either this is a new keypress, or key repeat occurred) - same as keypress.
    It can therefore return 0, 1, 2 or 3:
    0 = not pressed
    1 = key held down since last tick, but is not a new press
    2 = the player pressed the key and released it, all in the same tick
    3 = new keypress (or typematic repeat)

    [Notice] Previously you couldn't use virtual scancodes like use key, which could only be used with wait for key. Now all key commands accept any kind of constant; what a relief!

    keypress time (scancode, player)

    Returns how long a key or button has been held down, in milliseconds (thousandths of a second), or 0 if the key isn't pressed.
    The scancode argument is a scancode such as a keyboard key (e.g. key:ctrl) a joystick button (e.g. joy:left), or a virtual scancode such as use key (see control codes). If you use a scancode that refers to multiple keys/buttons (e.g. usekey or anykey) then the longest time that any of those keys has been held down is returned.
    player is an optional player number, normally only used with joy:... joystick scancodes or control codes, and tells which player's controller to read. By default it checks for a button press on any plugged-in controller.
    If a fast keypress happens in less than a tick and the key is already up again then key is pressed can return false and keypress time return 0 although keypress returns true.

    last ascii

    This command is obsolete. Use get input text instead, if possible.
    Returns the character code of any currently pressed key, or 0 if none are. If more than one key corresponding to an ascii character is being pressed, then only one can be returned.

    get scancode name(string id, scancode, long name)

    Get a name for a scancode, what the key does if Shift isn't pressed, and put it in string id. For example, "7", "Q", "Space", "Caps Lock", "Gamepad Button 1", "Gamepad Up".
    scancode can be any key:... or joy:... scancode, or use key, menu key, etc.
    Normally a long name like "Left Shift" is returned, but if optional argument long name is false, then a one-character string for what the key inserts is returned if available, for example "[" instead of "Left Bracket", with the exception of "Space" and "Enter" and numpad keys like "Numpad Minus" which are always returned as long names.

    enable input text (enable)

    This command needs to be called before get input text can be used. If the optional argument is true or not given then get input text is enabled, otherwise it is disabled. Enabling get input text may cause some of the keys on international keyboards ("combining" keys, which are usually punctuation keys) to go "dead" --- that is, commands such as key is pressed and wait for key will stop showing that they are pressed. For that reason, get input text is disabled by default. You don't need to use this command before calling input string.

    See also:

    get input text (string id)

    Places in the specified string any text that the player has typed since the last tick. (The string will be empty if nothing has been.) Textual input must be enabled using enable input text before this command can be used! See that command for details. You will normally call this every tick in a loop and use concatenate strings to read the player's complete input. However it is much easier to call the input string function instead, which does this for you.

    See also:

    input string (ID, maxlength, use current, center, position x, position y)

    Allows the player to type in a string (until they press ENTER). Returns false if they press ESC to cancel. ID is the string you want to use. All other arguments are optional: maxlen is the length of input, if left blank the limit will be equal to the maximum length that fits on-screen (40 characters if the screen is the default 320 pixels wide). use current is whether you want to add to the existing string, or clear the string before typing. The default is to clear the string before typing, valid arguments are true or false. The string will be centered (see center string at unless center is false. If the string is not visible, then it will automatically be placed onscreen (centered if not specified) and hidden when done. position x and position y are optional (defaulting to the center of the screen), and are the position at which the string will be shown as it is being typed; otherwise the string will use its current positioning if already visible.

    See also:

    input string with virtual keyboard (ID, maxlength, onlyplayer)

    Allows the player to input a string using a virtual keyboard. The exact appearance and behavior of the virtual keyboard will vary on different platforms, for example, on Android a touch-screen keyboard will appear, but when playing on a console, the virtual keyboard will be controlled with the d-pad and buttons. You have no control over what portion of the screen is obscured by the virtual keyboard. The virtual keyboard will vanish when the command is finished. ID is the string you want to use. All other arguments are optional: maxlen is the length of input, if left blank the limit will be set to 40 (max visible onscreen length). The onlyplayer is optional. It only matters when the game is played on a console with multiple gamepads configured. It can be a number from 0 to 3, being that only that specific player has control over the virtual keyboard. By default onlyplayer is -1, which means that any player can control it.

    show virtual gamepad

    Documented in the Platform Specific section.

    hide virtual gamepad

    Documented in the Platform Specific section.

    auto virtual gamepad

    Documented in the Platform Specific section.


    Getting Player Input → Joystick/Gamepad Input

    Joystick buttons and up/down/left/right directions can also be read using the keypress, new keypress, key is pressed and wait for key commands, by using the joy:... scancode constants instead of keyboard scancodes.
    But the best way to support joysticks is to use control codes such as use key instead of keyboard scancodes, e.g. write if (keypress(use key)) instead of if (keypress(key:space) || keypress(key:enter) || keypress(key:ctrl)).

    joystick button (button, player)

    Returns true or false depending on whether button number button on the player's joystick/gamepad is pressed. button can be from 1-32 (assuming the joystick has that many buttons), or a joystick scancode like joy:Up.
    player is an optional player number telling which player's controller to read. By default it checks for button presses on any plugged-in controller.
    This command is redundant to key is pressed.

    [Notice] If you want to check for new button presses, or want key-repeat to happen, use the keypress or new keypress commands instead with a joy:... scancode.

    joystick axis (axis, multiplier, player)

    Returns the position of one of a joystick/gamepad's sticks along the X or Y axis, or of one of the trigger buttons. axis is a value 0 or higher, or one of the constants:


    The optional multiplier is the range of the return value: between -multiplier ... multiplier (or 0 ... multiplier for axis:L2 or axis:R2). By default, the range is -100 - 100.
    player is an optional player number telling which player's controller to read. By default it check all controllers and combines their input.
    [Warning] All axes are meant to return 0 when the player isn't touching the stick/trigger, but you must NOT rely on this as joysticks/thumbsticks in general don't return to exactly 0,0! Instead, you must use a "dead zone" around 0 where input is ignored. For example, ignore values between -50 and 50. Also, if you push a stick diagonally (e.g. up-right) it probably won't reach 100,-100.
    If possible (if you don't need to know how far or precisely what angle the stick is pushed), use the joy:Up, joy:Down, joy:Left, joy:Right or joy:RStick Up, joy:RStick Down, joy:RStick Left, joy:RStick Right buttons with key is pressed instead. These allow 8-directional movement and have a proper circular dead zone.
    [Notice] Constants like axis:Right X only mean what they say if the controller is a gamepad and if you're using the default gfx_sdl2 backend. All the other backends number gamepad buttons and axes unpredictably. So that means axis:L2 and axis:R2 can actually return negatives.


    Getting Player Input → Mouse Input

    init mouse

    Informs the engine that you intend to use the mouse. This command should be run before any mouse functions are be used, but it's not necessary. It causes the normal mouse cursor to be hidden when over the game's window, and causes mouse buttons to trigger on-keypress scripts. Therefore, it is a good idea to place this command in the newgame and loadgame scripts if you are going to use the mouse.

    [Notice]Running this command does not draw a cursor onscreen. Either you can enable the default mouse cursor with unhidemousecursor, or your script may display the cursor itself by placing a slice at the appropriate location. If you use a slice, your cursor will appear below menus and text and strings shown with show value, show string at, etc., which is currently unavoidable.
    Here is an example:
    #Simple Mouse cursor example
    
    plotscript, display mouse, begin
    
      # Hide the normal mouse cursor
      init mouse
      # Re-enables the normal mouse cursor
      unhide mouse cursor
    
    end
    #Custom Mouse cursor example
    
    plotscript, display mouse, begin
    
      # Hides the normal mouse cursor
      init mouse
    
      # Use a small enemy sprite (ID 1) slice as a mouse cursor
      variable (cursor)
      cursor := load small enemy sprite (1)
      # The following is optional: causes the mouse to be displayed
      # above textboxes and above all other slices (it still appears behind menus though)
      move slice above (cursor, lookup slice (sl:textbox layer))
    
      # Loop while the game is running
      while (true) do, begin
        put slice (cursor, mouse pixel x, mouse pixel y)
        wait (1)
      end
    end

    mouse pixel X

    Returns the X coordinate in pixels of the mouse on the screen (window). The position is clamped to the size of the window: it is always in the range 0 to get screen width -- 1.

    [Notice] Because of the clamping, currently there's no way to tell whether the mouse is actually over the window.

    mouse pixel Y

    Returns the Y coordinate in pixels of the mouse on the screen. The position is clamped to the size of the window: it is always in the range 0 to get screen height -- 1.

    mouse button (which)

    Returns true if the specified mouse button is currently pressed down. You can use the constants left button, middle button or right button to specify the button.

    [Notice] Just like keyboard commands such as key is pressed, you can not wait for the player to click the mouse with a while loop that doesn't contain a wait command, because the mouse state is only updated once per frame.
    [Warning] When scripting a user interface (GUI or menu) with custom mouse-based controls, you should almost always use mouse release instead of mouse button or mouse click. (mouse button is fine for gameplay actions, like throwing projectiles.)
    There are two reasons: firstly, that's how the mouse works in almost all software (try it!). Secondly, the engine itself uses 'mouse release' everywhere, so you may run into problems if you use mouse button for UI stuff. For example if you quit a custom menu on mouse button (ie the button is pushed down), but then the engine will do something like walk the hero to a tile when it sees the button goes back up, that'll cause an unwanted action.

    mouse click (which)

    Returns true if the specified mouse button has been 'clicked' down in the last tick. You can use the constants left button, middle button or right button to specify the button.

    [Notice] Just like keyboard commands such as key is pressed, you can not wait for the player to click the mouse with a while loop that doesn't contain a wait command, because the mouse state is only updated once per frame.

    mouse release (which)

    Returns true if the specified mouse button has been released since the last tick. You can use the constants left button, middle button and right button to specify the button.

    [Notice] Just like keyboard commands such as key is pressed, you can not wait for the player to click the mouse with a while loop that doesn't contain a wait command, because the mouse state is only updated once per frame.

    put mouse (X, Y)

    Changes the location of the mouse on the screen, in pixels. Note that this function might do nothing, if the game's window is not active (see window is focused). init mouse should be called before this command is used.

    mouse region (x min, x max, y min, y max)

    Constricts the mouse to a rectangular part of the window/screen, such as a choice selection box. It is recommend you do not use this command, as it is very annoying in windowed mode. The maximum values are inclusive. Call without arguments to free the mouse to leave the window. init mouse should be called before this command is used.

    input string with mouse keyboard (ID, maxlength)

    Allows the player to input a string using a virtual keyboard that respons to mouse clicks or touchscreen touches. You have no control over what portion of the screen is obscured by the virtual keyboard. The virtual keyboard will vanish when the command is finished. ID is the string you want to use. All other arguments are optional: maxlen is the length of input, if left blank the limit will be set to 40 (max visible onscreen length).

    unhide mouse cursor

    Alias:

    show mouse cursor

    Causes the normal OS mouse cursor to be displayed, even when fullscreened. You may want to run this command right after init mouse unless you plan to use a scripted customized mouse cursor.
    If you don't call init mouse, hidemousecursor or unhidemousecursor then the default behaviour is for the cursor to be shown when running in a window and hidden in fullscreen.

    [Notice] This command has no effect if the game is running on Android, because a mouse cursor is usually inappropriate on a touch screen.

    hide mouse cursor

    Causes the normal OS mouse cursor to be hidden. This command is seldom needed, because the cursor is hidden by default when you run init mouse.


    Getting Player Input → Mouse Input → Helpful Related Commands

    camera pixel X

    Documented in the The Camera section.

    camera pixel Y

    Documented in the The Camera section.

    slice at pixel (parent, x, y, number, check descendants, visible only)

    Documented in the Slice Collision Testing section.

    slice collide point (handle, x, y)

    Documented in the Slice Collision Testing section.

    NPC at pixel (x, y, number)

    Documented in the NPCs section.

    menu item at pixel(x, y)

    Documented in the Menu Items section.


    String Functions

    [Back to top-level index]

    In HamsterSpeak, strings are special variables which hold pieces of text, and are referred to by their ID numbers. There are 100 string variables, with IDs 0 to 99. Strings variables can be displayed onscreen directly, or alternatively embedded in textboxes or displayed with text slices. For more information, see the wiki article on strings.
    You can set the value of a string directly with $id="..." and append to an existing string with $id+"...". There is no limit on string length.

    [Notice]Unlike almost all other indices in the OHRRPGCE, when referring to a position in a string, position is a 1-based index into the string, not a 0-based index. For example, given a string "ABCDEFG", position=3 is "C", not "D". This means that position 0 is invalid. Beware!
    [Notice]Strings are not saved in saved games by default, but this can be enabled in the Saved Game Settings menu.

    show string (ID)

    Documented in the Basic Display Commands section.

    input string (ID, maxlength, use current, center, position x, position y)

    Documented in the Keyboard Input section.

    expand string(ID, saveslot)

    Expands "embed" codes in string ID such as ${H1}, modifying the string. (See the textbox editor for the list of all available embed codes.) This does the same thing that textboxes do automatically. The saveslot argument is optional. If you leave it out, the string's codes will be expanded based on the currently running game state. If you specify a save slot number (from 1-1000) then the string will be expanded based on data (hero names, variables, strings, etc.) from that saved game.


    String Functions → Basic String Commands

    $id="some text"

    Sets the contents of a string variable given by id, which can be a constant like 0 or 1, a variable, or even an expression like a call to a script, to a piece of text. The previous contents are erased. The whole statement must be on a single line; you can't split the text onto multiple lines (use multiple $id+"..." statements instead). The value of the whole statement is equal to id for convenience (see the example). The text (which is called a string literal) can contain certain escape codes (see examples below):
    \\ turns into a single \
    \" turns into a single " without signalling the end of the literal
    \n is a new line character, which can be used in text slices, show string, show string at and trace.
    \t is a tab character (which isn't useful at all as it doesn't actually cause a tab except when printing to a file with trace).
    \x## where ## is a two digit hexidecimal number adds an ASCII character to the string. For example \x4b is the letter K.

    # This displays Some text! in the corner of the screen
    $1 = "Some text!"
    showstring(1)
    
    # This displays
    # Guard:
    #   "Halt!"
    # near the bottom left corner of the screen (at 30,150) for a moment
    show string at ($1="Guard:\n  \"Halt!\"", 30, 150)
    wait (40)
    hide string (1)

    $id+"some text"

    Appends a string literal to a string variable. This is the same as $id="...", except that the existing contents of the string are preserved and appended to.

    clear string(ID)

    Erases the string buffer #ID to the empty string (""). That's all.

    append number (ID, number, min length, pad with zeros)

    Appends the decimal representation of number to the string with ID #ID. The optional min length argument can be used to add padding to the left or right. It's the minimum length of the string to append - if the number of digits (including the leading negative sign, if any) is less than this, then spaces or zeroes are added as padding:

    append number(1, 65)           # Appends "65" to string 1.
    append number(1, 1234, 3)      # Appends "1234" to string 1: no padding added
    
    append number(1, 65, 4)        # Appends "  65" to string 1.
    append number(1, 65, 4, true)  # Appends "0065" to string 1.
    
    append number(1, -65, 4)       # Appends " -65" to string 1.
    append number(1, -65, 4, true) # Appends "-065" to string 1.
    
    append number(1, 65, -4)       # Appends "65  " to string 1.
    append number(1, 65, -4, true) # Appends "65  " to string 1: the 4th argument is ignored
    append number(1, -65, -4)      # Appends "-65 " to string 1.

    string sprintf (dest string ID, format string ID, arguments...)

    Builds a string from a template (given by format string ID) and zero or more additional arguments, and puts the result in the string dest string ID. This is a restricted version of the sprintf function in other programming languages. This function takes at least 2 arguments. The format string is a mix of regular text and codes like %d. For each code, one argument is read and used to substitute for the code. The codes are:
    %d: substituted with a number, printed as a decimal.
    %x: substituted with a number, printed as a unsigned 32 bit hexidecimal, in lower case and without a leading 0x.
    %o: substituted with a number, printed as a unsigned 32 bit octal number, without a leading 0o.
    %b: substituted with a number, printed as a unsigned 32 bit binary number, with a space between every 8 bits, without a leading 0b.
    %s: substituted with a string. The argument should be a valid string ID.
    %c: substituted with a single character. The argument should be an ASCII code (that is, a number between 0 and 255).
    %%: substituted with a single %. In this case an argument is NOT used up.
    More sophisticated formatting codes like %-04d that are possible in other programming languages are not supported yet.

    [Notice] Modifiers like field width and precision which are available in other programming languages, e.g. "%4d" or "%.2f", aren't available. But append number has extra options for these.
    # This displays some text like "HP: 30  MP: 12  $: 104" at the bottom of the screen
    $1 = "HP: %d  MP: %d  $: %d"
    string sprintf(0, 1, getherostat(me, stat:HP), getherostat(me, stat:MP), partymoney)
    show string(0)
    # This displays some text like "Ah Bob! You've brought me 5 apples."
    # in the centre of the screen, and waits for the player to press a key.
    $10 = "Ah %s! You've brought me %d apples."
    getheroname(11, findhero(leader))
    string sprintf(12, 10, 11, inventory(item:apple))
    center string at(12, 160, 100)
    wait for key(anykey)
    hide string(12)
    
    # This displays "1abcdef ffffffff A%"
    # Notice that the expression '$1="%x %x %c%%"' returns the string ID 1 as a side effect.
    string sprintf(0, $1="%x %x %c%%", 28036591, -1, 65)
    show string(0)

    number from string (ID, default)

    Try to read the string specified by ID as a number and return it. Blank spaces at the beginning of the string will be ignored, and the string can start with a - sign for negatives. No other characters except numerical digits can appear in the string. You can also provide an optional default value that will be returned if the string is not a valid number (for example, if it contains a non-numeric letter)

    See also:

    copy string (dest, source)

    Copies the text from string #source to string #dest, overwriting the existing string completely.
    If you prefer, you can write dest $= source instead. You must supply string id numbers, not strings, as arguments.

    concatenate strings (dest, source)

    Copies the text from string #source to string #dest. However, unlike copy string, the text is appended to the end of dest.
    If you prefer, you can write dest $+ source instead. You must supply string id numbers, not strings, as arguments.

    string length (ID)

    Returns the length of string #ID.

    string equal (ID1, ID2)

    Alias:

    string compare (ID1, ID2)

    Returns true if the two strings #ID1 and #ID2 are identical, case sensitive.

    search string (ID1, ID2, start)

    Searches the string for a specified string, returns the position at which the string was found. start is the position at which you want to start looking, default is 1. ID1 is the the string you want to search, ID2 is the string you want to find. Returns false if the string wasn't found

    trim string (ID, start, length)

    trim string (ID)

    Cuts a string to the specified substring (if you specify start and length), OR removes all whitespace (spaces, tabs and newlines) from the beginning and end of the string (if you only provide ID). ID is the string you want to trim.
    start is the position at which you want the new string to start, anything to the left of this will be deleted from the string. Pass 1 if you don't want to cut anything from the start but just want to shorten the string. If start is past the end of the string, the string is blanked (this isn't an error).
    length is the size of the string you want, anything to the right of start+length will be deleted. It's not an error if start+length is beyond the end of the string or if length <= 0.

    $1 = "  this silly example \n "
    # \n is the newline character, if you remove the trimstring(1) now you'll see the text is two lines high
    trim string(1)
    show string(1)  # Shows "this silly example"
    wait(30)
    trim string(1, 3, 8)
    show string(1)  # Shows "is silly"

    replace substring (in string, replace what, with what, max replacements, case insensitive)

    Replace occurrences in string ID in string of a substring (ID replace what) with a different string (ID with what).
    By default, replaces all occurrences of replace what, but optionally you can limit the number of times to do the replacement by passing max replacements; there's no limit if it's < 0. Inserted text is not eligible for further replacements (see examples).
    If you pass true as the optional argument case insensitive (which defaults to false), then the search for replace what is case-insensitive. For example, "hi" matches "hi", "Hi", "HI" and "hI".
    Returns the number of replacements done.

    $1 = "This is an example of replace substring"
    # Shows '2'
    show value (replace substring (1, $2="is", $3="iiss"))
    wait for key
    # Note that although "iiss" contains "is", it isn't replaced again with "iiisss"
    show string (1)  # "Thiiss iiss an example of replace substring"
    wait for key
    
    $1 = "AaabaAaa"
    replace substring (1, $2="AA", $3="CA", 2, true)  # Do only 2 replacements, case insensitively
    # Again, Aaab becomes CAab but the new Aa isn't replaced, because part of it was a replacement
    show string (1)  # "CAabCAaa"
    

    append ascii (ID, char)

    Appends the character with ASCII code char to the string with ID ID. The font editor displays the character code of each character. For example numbers are 48 - 57, uppercase letters are 65 - 90, lowercase letters are 97 - 122.

    replace char (ID, position, char)

    Replaces the character at position in string #ID with a character with ascii code char. The first position of the string is 1, and the last position of the string is the same as string length.

    delete char (ID, position)

    This deletes the character at position in string #ID, causing all the following characters to move over a slot. The first position of the string is 1, and the last position of the string is the same as string length.

    ascii from string (ID, position)

    Returns the ascii code of the character at position in string #ID. The first position of the string is 1, and the last position of the string is the same as string length. If you pass 0 as the position or a position past the end of the string, 0 will be returned.


    String Functions → Get/Set Names of Things

    This section is a catch-all for commands that get or set bits of game data that are strings, however a number of such commands, like get menu item caption live elsewhere, in more sensible sections!

    get hero name (ID, hero)

    This command will take the name of the hero in the party slot #hero, and stick it in string #ID, overwriting its contents.

    [Notice]Remember that this command expects the hero's position in the party, not the hero:name constants nor the hero's position in the walkabout party. If you want to get the name of a hero according to their position in the walkabout party, you should use hero by rank and find hero
    # This example gets the name of the leader and stores it in string ID 1
    
    get hero name (1, find hero (leader))
    

    set hero name (ID, hero)

    This command changes the name of the hero in party slot #hero (as returned by find hero) to the contents of string #ID. The length is not limited by the hero's Max Name Length setting.

    get enemy name (enemyid, stringid)

    Documented in the Enemy and Formation Functions section.

    set enemy name (enemyid, stringid)

    Documented in the Enemy and Formation Functions section.

    get map name (ID, map)

    This command will take the name of map #map and stick it in string #ID, overwriting its contents.

    get stat name (ID, stat)

    Gets the name of a stat and puts it in string #ID. The stat index can be a constant like stat:hp for stats 0-11 (but beware the names of these change to match the stats so are no use for portable scripts) or an in-battle register stat (stats 12-15 for poison, regen, stun and mute registers).
    Safe to use with an out-of-range stat: returns false and sets a blank string without showing an error. Otherwise returns true.

    Documented in the Attack Data section.

    read attack name (str ID, attack)

    Documented in the Attack Data section.

    get attack caption (str ID, attack)

    Documented in the Attack Data section.

    get song name (ID, song)

    Gets the name of song #song and puts it in string #ID.

    string from textbox (ID, textbox, line, ignored)

    Documented in the Text Boxes section.

    textbox line (string ID, textbox, line, expand, strip)

    Documented in the Text Boxes section.


    String Functions → Showing Plotstrings

    These commands are an old (and largely obsolete) method of showing strings on the screen. They're completely separate to, and superceded by Text Slices. The show string command is yet another separate way to display a string.

    show string (ID)

    Documented in the Basic Display Commands section.

    show string at (ID, x, y)

    Displays string #ID on the screen, positioning its top left corner at the given (x,y) coordinates. Unlike show string, changes to the string will be displayed in real-time. The string will not auto-wrap at the edge of the screen, but it can contain new lines (\n).

    center string at (ID, x, y)

    Displays string #ID on the screen, positioning its top-middle at the given (x,y) coordinates. Unlike show string, changes to the string will be displayed in real-time. x,y are optional: if they are missing then the string is centered in the center of the screen.

    [Notice] The string is not re-centered automatically if its length changes. If you change the string and want to keep it centered, call showstringat again. Otherwise, its top-left corner will stay fixed.
    [Warning] The string position will be miscalculated if it contains newlines (\n characters).

    hide string (ID)

    Makes a string previously displayed with show string at or center string at disappear. Has no effect on strings displayed with show string

    string is visible (ID)

    Returns true if a string is being displayed by show string at or center string at. Otherwise, returns false. Is not effected by show string

    string style (ID, style)

    Changes the appearance of a string. Use this in conjunction with (before or after) show string at or center string at. Choice of style is string:outline and string:flat. string:outline is the style of string you are familiar with in textboxes: they are outlined with colour 0 (black). string:flat have no outline but can have a solid rectangular background of any colour displayed behind the string.

    string color (ID, foreground color, background color)

    Changes the color of a string. Use this in conjunction with (before or after) show string at or center string at. Foreground color is the colour of the text itself. Background color has no meaning for style:outline strings (the outline is always black). For style:flat strings, it is the color of the solid background if 1 to 255, or causes no background if 0. If you omit background color, the background will be transparent. Omit foreground color as well to reset the color to default ('Text' User-interface color).

    positionstring (ID, x, y)

    Positions the top left corner of string #ID at the given x,y coordinates. Unlike show string at, this command will not affect the visibility of a string.

    string X (ID)

    Returns the horizontal X position of the top left corner of string #ID

    string Y (ID)

    Returns the vertical Y position of the top left corner of string #ID


    String Functions → Obsolete Commands

    string to globals (ID, starting global, length)

    This command will fill global variables (starting with #starting global), up to length globals, with the ascii values of the characters in string #ID. If the string is not long enough, the rest of the globals in this "field" are padded with the value 256. If the string is too long, then only part of it is saved.

    [Notice] This command is deprecated. The Saved Game Settings menu now has an option to store strings in saved games. There is no reason to use this command in new games, unless you're using import globals/export globals.

    globals to string(ID, starting global, length)

    This command is the opposite of string to globals. It will build a new string in slot #ID, using the ascii values from the global variables #starting global and length globals thereafter. Pass the same value for length as you did to string to globals if you don't know the length of the string. If a global has a value greater than 255, the value will be ignored.

    [Notice] This command is deprecated. The Saved Game Settings menu now has an option to store strings in saved games. There is no reason to use this command in new games, unless you're using import globals/export globals.


    Extra Data Array Functions

    [Back to top-level index]

    Certain types of objects (slices, NPCs, zones, menu items) have "extra data", which is an array of data fields with no builtin meaning which you can use for whatever you want. (Menu item extra data is also passed as arguments to any script triggered by the item.) For example you could write a script to randomly play ambient sound effects while inside a zone, and store the sound effect numbers in the zone's extra data in the zone editor.
    These functions can be used on any objects with a resizable "extra data" array. (To operate on zones you need to use get zone to get a zone handle.)

    set extra (handle, extra, value)

    Sets one of the extra data variables on an object, which have no builtin meaning, they are only for use in your scripts. By default all new objects that support extra data start with a length 3 extra data array containing zeroes.
    handle is an object handle. extra is an extra array index, typically a value from 0 to 2. Use resize extra if you want more than 3 extra values.
    This command is a generic alternative to set slice extra, set zone extra, set NPC extra, and set menu item extra.

    get extra (handle, extra)

    Retrieve a value of an object's extra data array (e.g. one previously stored with set extra).
    handle is an object handle. extra is the extra array index to read.
    This command is a generic alternative to get slice extra, get zone extra (using get zone not a zone ID), NPC extra, and get menu item extra. But it can't be used to replace get attack extra.

    append extra (handle, value)

    Increases the length of an object's extra data array by 1 and puts value in the new slot at the end. handle is the object handle.
    The return value is the new array length.
    Equivalent to:

    resize extra(handle, extra length(handle) + 1)
    set extra(handle, -1, value)   # Index -1 is the last element of the array

    insert extra (handle, index, value)

    Insert a value into a new position anywhere in an extra data array, moving up the index of all the data after it, and increasing the length by 1.
    handle is the object handle.
    index is an extra array index where to put the new element. As usual negative indices count from the end.
    value is the value to insert.

    # starting extra array 0,0,0
    insert extra(handle, 0, 111) # 111,0,0,0
    insert extra(handle, 2, 222) # 111,0,222,0,0
    [Notice] Inserting an element means all the elments after it have to be moved. If you are using an extra array as a stack, and are concerned about high performance, it is better to push to the end with append extra(handle, value) rather than insert at the beginning with insert extra(handle, 0, value)

    find extra (handle, value, start index)

    Search an object's extra data array for value and returns the index of the first item from the beginning equal to value, or -1 if not found. You could write a for loop instead but this command is much faster.
    handle is the object handle.
    start index, defaulting to 0, is an optional extra array index where to start searching from; the search looks from there until the end of the array. (If it's beyond the end, the return value is always -1.) Use this if there might be multiple copies of the value and you want to find them all: set start index equal to the previous return value + 1.

    # Deletes every occurrence of 'value' from an extra array.
    script, remove extra, obj, value, begin
    	variable (idx)
    	while (true) do (
    		idx := find extra (obj, value)
    		if (idx == -1) then (exit)   # All deleted
    		delete extra (obj, idx)
    		# Normally we'd do "idx += 1" to look for the next occurrence of 'value'
    		# after idx, but because we deleted it we don't need to.
    	)
    end

    extra length (handle)

    Returns the length of an object's extra data array. This is 3 by default, and can be changed with resize extra. handle is the object handle.

    resize extra (handle, length)

    Changes the length of an object's extra data array. handle is the object handle. The new length can be between 0 and 5,000,000. For backwards compatibility it's 3 by default for all newly created slices, zones, NPCs and menu items. Values will either be removed from the end of the array, or zeroes added to the end to meet the new length. The rest of the existing contents of the array will be preserved.

    delete extra (handle, index)

    Delete an element from an extra data array at a specific index, moving down the index of all the data after it, and decreasing the length of an object's extra data array by 1.
    handle is the object handle.
    index is the extra array index of the element to delete and return.
    The return value is the value that was found at the index which was removed.

    # starting extra array 11,12,13
    delete extra(handle, 1) # returns 12, remaining extra data is 11,13
    delete extra(handle, -1) # returns 13, remaining extra data is 11
    [Notice] If you want to delete by value rather than by index, use the remove extra script from the example to find extra.
    [Notice] Deleting an element means all the elments after it have to be moved. If you are using an extra array as queue, and are concerned about high performance, it is better to pop from the end with delete extra(handle, -1) rather than popping from the beginning with delete extra(handle, 0)

    delete extra range (handle, from index, to index)

    Delete a range of elements from an extra data array starting from one index (inclusive) to another (exclusive). All the data after it will be moved down, and the length of an object's extra data array will be decreased by the same amount, which is to index -- from index elements (after converting negative indices to positive).
    handle is the object handle.
    from index is the extra array index of the starting element to delete. It's the one returned. You can use negative indices as usual.
    to index is the extra array index of the first element after the deleted range: it is exclusive.
    The return value is the item that was at from index, unless from index == to index (an empty range) in which case nothing happens and nothing is returned.

    delete extra range(handle, 2, 2) # Will not delete anything because the indices are the same
    delete extra range(handle, 2, 3) # Will delete just the element at index 2, same as delete extra(handle, 2)
    
    # starting extra array 50,51,52,53,54,55
    delete extra range(handle, 2, 5) # delete elements 2, 3, and 4
    # remaining extra array 50,51,55
    
    # delete from element 1 to the end of the extra array, leaving behind only element 0
    delete extra range(handle, 1, extra length(handle))
    [Notice] Deleting elements means all the elments after them have to be moved. Using delete extra range to delete a bunch of elements at once is more efficient than calling delete extra many times in a row, because the elements after only need to be moved once.


    Shop Functions

    [Back to top-level index]

    use shop (shop)

    Documented in the Triggering Stuff section.

    is shop buy menu empty (shop id)

    Returns true if the shop specified by shop id has no available items. This could be because no items are defined, or they might all be out of stock or disabled by tags. You can use constants in the form of shop:Shop Name.

    is shop hire menu empty (shop id)

    Returns true if the shop specified by shop id has no available heroes for hire. This could be because no hireable heroes are defined, or they might all be out of stock or disabled by tags. You can use constants in the form of shop:Shop Name.

    inn screen (price, skip fade)

    Documented in the Opening Built-in Menus section.


    Menu Functions

    [Back to top-level index]

    open menu (ID, allow duplicate)

    Opens the menu specified by ID. You can also use the constants defined in your HSI file in the form menu:name. The menu will be opened on top of any menus that are already open.
    The optional second argument allow duplicates (defaulting to false) can be true if you want to be able to open more than one copy of the same menu at the same time. If allow duplicates is false and the menu is already open, then the existing menu (the top-most one, if there's more than one) is brought to the top.
    The return value is a menu handle that you should store in a variable for use with other menu-related commands. (If an existing menu was brought to top, its handle is returned
    If ID isn't a valid menu, this acts like create menu.

    [Warning] If menu 0 does NOT have the "Allow gameplay & scripts" bit set, then your script will pause as soon as the menu opens, until either it's closed or another menu with that bit ON is opened. And once the menu has closed the menu handle is invalid!

    create menu

    Create a new empty menu. You can add menu items to it with the add menu item command. The return value is a menu handle that you should save in a variable for use with other menu related commands. Menus created with this command have the "Allow gameplay and scripts" bitset turned on by default.

    close menu(menu handle, run close script)

    Close a menu. The first argument is a menu handle (for example, the one returned by open menu or top menu). The second argument run close script, which defaults to false, states whether to run the menu's on-close script, if there is one.

    top menu

    Return a menu handle for the topmost menu. Returns false if no menus are open.

    bottom menu

    Return a menu handle for the bottom menu (the menu underneath all other open menus). Returns false if no menus are open.

    previous menu(menu handle)

    Return a menu handle for the menu beneath the one specified by menu handle, or false if there is no menu underneath.

    variable(menu)
    menu := topmenu
    while(menu) do, begin
     # do things to each menu
     menu := previous menu(menu)
    end

    next menu(menu handle)

    Return a menu handle for the menu on top of the one specified by menu handle, or false if there is no menu on top

    variable(menu)
    menu := bottom menu
    while(menu) do, begin
     # do things to each menu
     menu := next menu(menu)
    end

    bring menu forward(menu handle)

    Given a menu handle, move the menu to the top of all other open menus.

    find menu ID(menu ID)

    Given a menu ID number or a constant in the form of menu:name, check to see if it is already open, and if so return a menu handle to it. Otherwise returns false.

    menu is open(menu handle)

    Given a menu handle, checks to see whether it is still open, and returns true if it is, or false if it has been closed.

    parent menu(menu item handle)

    Given a menu item handle, return a menu handle for the menu that the menu item belongs to.

    get menu ID(menu handle)

    Given a menu handle, return the ID number of the menu, or -1 if the men was created with the create menu command.


    Menu Functions → Menu Items

    add menu item(menu handle)

    Given a menu handle, adds a new blank menu item to the end of the menu. Returns a menu item handle, which you can store in a variable for use with commands like set menu item caption or set menu item type.

    delete menu item(menu item handle)

    Given a menu item handle, delete the menu item from the menu. (The change does not affect other copies/instances of the same menu if this menu was created in the menu editor.)

    swap menu items(handle1, handle2)

    Given two menu item handles switch the positions of the two menu items. Note that this works both to rearrange menu items within one menu, or to move menu items between different menus.

    select menu item(menu item handle)

    Given a menu item handle, move the menu selection cursor to point to that menu item. This works even if the menu item is in a menu that's not top-most/selected, but the menu won't become selected. Unselectable menu items (see menu item selectable) can't be selected; if you try to select one this command silently fails and returns false; normally it returns true.

    selected menu item(menu handle)

    Returns the handle for the selected menu item in the topmost menu if the optional menu handle is omitted, or, with a menu handle returns the selected item in that menu. Returns false if no menus are open, or if the topmost or specified menu has no selection (which happens if it's empty, or all menu items are unselectable or hidden).

    menu item disabled(menu item handle)

    Given a menu item handle, returns whether that menu item is disabled (true or false). Menu items can be disabled for a range of reasons such as tag conditions.

    menu item visible(menu item handle)

    Given a menu item handle, returns whether that menu item is visible (true or false). A menu item is hidden only if it's disabled and has the "Hide if disabled" bit set.

    menu item selectable(menu item handle)

    Given a menu item handle, returns true or false, telling whether that menu item is visible and can be selected by normal controls, (rather than being skipped over).
    Currently only hidden menu items and Labels which "Can't be selected" return false.

    use menu item(menu item handle)

    Given a menu item handle, activate the menu item. This will cause whatever actions (text box, menu, script, tag changes, etc.) that have been configured for this menu item to be triggered.

    first menu item(menu handle)

    Given a menu handle, return a menu item handle for the menu item at the top of the menu, or 0 (false) if there are no visible menu items.

    [Notice] This is NOT the handle for the first menu item defined in the menu editor. Use menu item by true slot(menu, 0) to get that one.

    last menu item(menu handle, visible only)

    Given a menu handle, by default returns a menu item handle for the last visible menu item, at the bottom of the menu. visible only defaults to true. If you pass false as the visible only argument, then returns the last visible or invisible menu item (last as seen by menu item by slot or next menu item).

    [Notice] last menu item(menu, false) does NOT return the handle for the last menu item that appears in the menu editor, because menu items are sorted based on visibility: all invisible items to the end. Use menu item by true slot(menu, menu item count(menu) -- 1) to get that one.

    next menu item(menu item handle, visible only)

    Given a menu item handle, return a menu item handle for the menu item below the specified one, or false there is no next menu item. You can optionally include invisible items by using the optional argument visible only, which defaults to true.

    [Notice] Invisible menu items are always at the end of the menu, after the last visible menu item, not in the order in which they are defined in the menu editor! See menu item by true slot if that's undesirable.
    variable(mi)
    mi := first menu item
    while(mi) do, begin
      # do things to each visible menu item
      mi := next menu item(mi)
    end
    

    previous menu item(menu item handle, visible only)

    Given a menu item handle, return a menu item handle for the menu item above the specified one, or false there is no previous menu item. You can optionally include invisible items by using the optional argument visible only, which defaults to true. Note that invisible menu items are always at the end of the menu, after the last visible menu item. See menu item by true slot if that's undesirable.

    variable(m)
    m := previous menu item(selected menu item)

    menu item count(menu handle)

    Returns the total number of menu items in a menu, both visible and invisible (disabled).

    visible menu item count(menu handle)

    Returns the number of visible menu items in a menu.

    See also:

    menu item by true slot(menu handle, slot)

    Given a menu handle, return a menu item handle for the menu item at the position specified by slot. The first slot in the menu is 0. This command uses the ordering of menu items as they appear in the Menu Editor in Custom. The "true order" doesn't change as menu items are hidden or unhidden, unlike the slot returned by menu item slot.

    menu item true slot(menu item handle)

    Given a menu item handle, return the slot number of the menu item, as it appears in the Menu Editor. The first slot in the menu is 0. The "true order" doesn't change as menu items are hidden or unhidden, unlike the slot returned by menu item slot.

    menu item by slot(menu handle, slot, visible only)

    Given a menu handle, return a menu item handle for the menu item at the position specified by slot. The first slot in the menu is 0. You can optionally include invisible items by using the optional argument visible only, which defaults to true. Note that invisible menu items are always at the end of the menu, after the last visible menu item -- menu items are NOT in the same order as they appear in the Menu Editor! This means menu item slot numbers change as menu items are hidden or unhidden. Use menu item by true slot if you want to use the order shown in the Menu Editor.

    menu item slot(menu item handle)

    Given a menu item handle, return a the slot number of the menu item. The first slot in the menu is 0. Menu item slot numbers change as menu items are hidden or unhidden. Use menu item true slot if you want to know the slot number as it appears in the Menu Editor.

    find menu item caption(menu handle, string ID, search after handle, visible only)

    Given a menu handle, and a string identified by string ID, Search the menu for a menu item with a label that is the same as the string, and return a handle to the matching menu item. The optional third argument search after handle is a menu item handle to start searching after instead of searching from the top of the menu (so it must belong to the same menu). The optional fourth argument visible only is a true or false value that determines whether or not to include hidden items. It defaults to true.

    variable(menu, mi)
    menu := open menu(menu:test menu)
    $0="Puppies"
    mi := find menu item caption(menu, 0)
    while(mi) do, begin
     # do something to each menu item labelled "Puppies"
     mi := find menu item(menu, 0, mi)
    end

    menu item at pixel(x, y)

    Given a position on the screen (for example menu item at pixel(mouse pixel X, mouse pixel Y)), returns the handle for the menu item at that position, or false if none. If multiple menus overlap at that location the top-most one is returned. You can find the menu that the menu item belongs to with parent menu.

    [Notice] The menu item might not actually be selectable. Check with menu item selectable.


    Menu Functions → Menu Items → Menu Item Data

    get menu item caption(menu item handle, string ID)

    Given a menu item handle, take the caption and copy it into the string identified by string ID.

    set menu item caption(menu item handle, string ID)

    Given a menu item handle, replace the caption with the string identified by string ID.

    get menu item type(menu item handle)

    Given a menu item handle, return the type of the menu item.

    set menu item type(menu item handle, new type)

    Given a menu item handle, change the type of the menu item to new type. Available constants are: menutype:label (aka menutype:caption), menutype:special, menutype:menu, menutype:textbox, and menutype:script.
    You will also need to call set menu item subtype to fully specify the action attached to the menu item. Setting just the item type does NOT change the subtype to a sensible value!

    get menu item subtype(menu item handle)

    Given a menu item handle, return the subtype of the menu item. The meaning of the subtype varies depending on the type (see set menu item subtype).

    set menu item subtype(menu item handle, new subtype)

    Given a menu item handle, change the subtype of the menu item to new subtype. The meaning of the subtype varies depending on the type of the menu item, which is changed with set menu item type:

    get menu item tag(menu item handle, whichtag)

    Given a menu item handle, and a tag number whichtag which can be 1 or 2, return the a tag required for the menu item to be available. The tag number will be positive if the tag needs to be ON, or negative if the tag needs to be OFF.

    set menu item tag(menu item handle, new tag, whichtag)

    Given a menu item handle, and a tag number whichtag which can be 1 or 2, set the tag required for the menu item to new tag. Use a positive number if the tag needs to be turned ON, and a negative number if the tag needs to be turned OFF.

    get menu item settag(menu item handle)

    Given a menu item handle, return the number of the tag that will be set when the menu item is selected. The tag number will be positive if the tag will be set ON, or negative if the tag will be set OFF.

    set menu item settag(menu item handle, new settag)

    Given a menu item handle, change the tag that will be set when the menu item is selected. Use a positive number if the tag should be turned ON, and a negative number if the tag should be turned OFF.

    get menu item togtag(menu item handle)

    Given a menu item handle, return the number of the tag that will be toggled when the menu item is selected. (The tag number will always be a positive number).

    set menu item togtag(menu item handle, new settag)

    Given a menu item handle, change the tag that will be toggled when the menu item is selected. (The tag number will always be positive).

    get menu item bit(menu item handle, bit)

    Given a menu item handle, and bit number bit, return true if the bitset is ON, and false if the bitset is OFF. See set menu item bit for the constants you can pass as the value of bit.

    set menu item bit(menu item handle, bit, value)

    Given a menu item handle, and bit number bit, set the bitset is ON or OFF depending on value. You can use the following constants for bit:

    get menu item extra(menu item handle, extra)

    Given a menu item handle, and an extra data number which can be 0, 1, or 2, return the the number stored in the extra data space. This extra data has no meaning of its own, and is just useful for advanced menu scripting.

    set menu item extra(menu item handle, extra, num)

    Given a menu item handle, and an extra data number which can be 0, 1, or 2, change the number stored in the extra data space to num. This extra data has no meaning of its own, and is just useful for advanced menu scripting.

    get menu item color(menu item handle)

    Given a menu item handle, get its normal color (when it isn't disabled). This will be a color code. 0 means the default for the menu is used, which is get menu textcolor.

    set menu item color(menu item handle, colorcode)

    Given a menu item handle, set its normal color (when it isn't disabled). This should be a color code. 0 means to use the default for the menu, which is get menu textcolor.

    get menu item disabled color(menu item handle)

    Given a menu item handle, get the color it uses when disabled. This will be a color code. 0 means the default for the menu is used, which is get menu disabled textcolor.

    set menu item disabled color(menu item handle, colorcode)

    Given a menu item handle, set its color it uses when disabled. This should be a color code. 0 means to use the default for the menu, which is get menu disabled textcolor.


    Menu Functions → Menu Data

    get menu bit(menu handle, bit)

    Given a menu handle, and bit number bit, returns true if the bitset is ON, and false if the bitset is OFF. For the bit bit number you should use one of the constants:

    set menu bit(menu handle, bit, value)

    Given a menu handle, and bit number bit, sets the bitset is ON or OFF depending on value. For the bit bit number you should use one of the menubit:... constants. See get menu bit for the available constants.
    Note that this command only changes an open instance of a menu, it doesn't change the menu definition, so if the menu is closed and reopened any edits are reverted.

    get menu boxstyle(menu handle)

    Given a menu handle, return a the boxstyle of the menu. This will be a number from 0 to 14.

    set menu boxstyle(menu handle, new box style)

    Given a menu handle, change the boxstyle of the menu. new box style will be a number from 0 to 14.

    get menu textcolor(menu handle)

    Given a menu handle, return the default text color of the menu items. This will be a color code. 0 means the default is used, which is the "Menu item" color (ui:menuitem) in the User Interface Colors menu.

    set menu textcolor(menu handle, new textcolor)

    Given a menu handle, change the default text color of its menu items. new textcolor should be a color code. 0 means the default is used, which is the "Menu item" color (ui:menuitem) in the User Interface Colors menu.

    get menu disabled textcolor(menu handle)

    Given a menu handle, return the default text color of disabled menu items. This will be a color code. 0 means the default is used, which is the "Disabled menu item" color (ui:disableditem) in the User Interface Colors menu.

    set menu disabled textcolor(menu handle, new textcolor)

    Given a menu handle, change the default text color of disabled menu items. new textcolor should be a color code. 0 means the default is used, which is the "Disabled menu item" color (ui:disableditem) in the User Interface Colors menu.

    get menu max rows(menu handle)

    Given a menu handle, return a max rows to display of the menu, or 0 if the menu is auto-sizing. If the actual number of menu items is larger than the max rows, the menu will be scrollable.

    set menu max rows(menu handle, new max rows)

    Given a menu handle, change the max rows to display of the menu to new max rows. Use 0 if you want the menu to be auto-sizing. If the actual number of menu items is larger than the max rows, the menu will be scrollable.

    get menu offset x(menu handle)

    Given a menu handle, return the x offset position of the menu's anchor point in pixels relative to the center of the screen.

    get menu offset y(menu handle)

    Given a menu handle, return the y offset position of the menu's anchor point in pixels relative to the center of the screen.

    set menu offset x(menu handle, new x)

    Given a menu handle, change the x offset position of the menu's anchor point in pixels relative to the center of the screen.

    set menu offset y(menu handle, new y)

    Given a menu handle, change the y offset position of the menu's anchor point in pixels relative to the center of the screen.

    get menu anchor x(menu handle)

    Given a menu handle, return the x anchor position of the menu. The return value will be align:center, align:left or align:right. (Not the edge: constants used by slices!)

    get menu anchor y(menu handle)

    Given a menu handle, return the y anchor position of the menu. The return value will be align:center, align:top or align:bottom. (Not the edge: constants used by slices!)

    set menu anchor x(menu handle, new anchor)

    Given a menu handle, change the horizontal x anchor position of the menu. The new anchor can be align:center, align:left or align:right.

    set menu anchor y(menu handle, new anchor)

    Given a menu handle, change the vertical y anchor position of the menu. The new anchor can be align:center, align:top or align:bottom. (Not the edge: constants used by slices!)

    get menu text align(menu handle)

    Given a menu handle, return the text alignment of the menu. The return value will be align:center, align:left or align:right. (Not the edge: constants used by slices!)

    set menu text align(menu handle, new align)

    Given a menu handle, change the text alignment of the menu. The new align can be align:center, align:left or align:right. (Not the edge: constants used by slices!)

    get menu min chars(menu handle)

    Given a menu handle, return the minimum width of the menu in chars, or 0 for menus that have their width autodetected.

    set menu min chars(menu handle, new min)

    Given a menu handle, change the minimum width of the menu in chars, or use 0 to make the menu width autodetected.

    get menu max chars(menu handle)

    Given a menu handle, return the maximum width of the menu in chars, or 0 for menus that do not have a maximum.

    set menu max chars(menu handle, new max)

    Given a menu handle, change the maximum width of the menu in chars, or use 0 for no maximum.

    get menu border(menu handle)

    Given a menu handle, return the border thickness of the menu in pixels. Positive numbers indicate a thicker border. Negative numbers indicate a thinner border.

    See also:

    set menu border(menu handle, new border)

    Given a menu handle, change the border thickness of the menu in pixels. Positive numbers will result in a thicker border. Negative numbers will result in a thinner border.

    See also:

    get menu on close script(menu handle)

    Given a menu handle, return a script ID for the script that will be run when the menu is closed, or false if there is none. This command is only useful with scripts that have the allow gameplay and scripts bitset turned on.

    variable(m, s)
    m := open menu(5)
    s := get menu on close script(m)
    run script by id(s)
    			

    set menu on close script(menu handle, script id)

    Given a menu handle, assign the script ID that will be run when the menu is closed, or false to disable any on-close script that has already been set. The script trigger only takes effect the next time you close the menu. If you re-open the menu again, you will need to re-set the on-close script again. This command is only useful with scripts that have the allow gameplay and scripts bitset turned on.

    variable(m, s)
    m := open menu(5)
    set menu on close script(m, @my menu exit handler)
    			

    get menu cancel button menu(menu handle)

    Given a menu handle, returns the action that happens when the player presses a cancel button. -1 means the menu simply closes. 0 or greater is a menu ID to open in its place

    set menu cancel button menu(menu handle, menu)

    Given a menu handle, sets the action that happens when the player presses a cancel button. menu can be either -1, in which the menu simply closes, or a menu ID to open in its place (which is 0 or greater).

    get menu item spacing(menu handle)

    Given a menu handle, returns the amount of extra spacing in pixels between menu items. 0 is the default.

    set menu item spacing(menu handle, spacing)

    Given a menu handle, sets the amount of extra spacing in pixels between menu items. 0 is the default.


    Slices

    [Back to top-level index]

    To learn what a slice is, read the Slices article on the wiki, or one of the other tutorials you can find there. Although there are many commands here for manipulating slices, it's much easier to create slices in the Slice Collection Editor and then use load slice collection.
    Slices are referred to with slice handles.

    set parent (handle, parent handle)

    Moves a slice handle to a different parent handle. A slice is connected to its parent, and is positioned based on its parent's position. When you move a slice to a new parent, it will become that parent's last child, meaning it will be drawn on top of any other children that the parent already had. Because a slice is positioned relative to its parent, using this command can cause the slice to move. If you would like to change a slice's parent without changing its screen position, see the gently reparent command instead.

    gently reparent (handle, parent handle)

    Moves a slice handle to a different parent handle, but preserves the slice's current screen position. This means that the slice's x and y position relative to its new parent might be changed. When you move a slice to a new parent, it will become that parent's last child, meaning it will be drawn on top of any other children that the parent already had. If you would like to change a slice's parent without changing its position relative to its parent (which could change its screen position), see the set parent command instead.

    slice is valid (value)

    Returns true if the given value is a valid slice handle to some existing slice, or false if the value isn't a slice handle (e.g. if it's false or is any other type of handle such as an NPC reference or menu item handle) or if it refers to a slice that's been deleted. This command never throws an error.

    [Notice] Previously this command was considered dangerous because it could return true even if the slice had been deleted because its handle could be reused for a different slice. But starting in the ichorescent release this is mostly solved. Now in ichorescent slice handles won't get reused unless you create and delete at least a million slices. If you create millions of slices and want to be sure, set your slice handles to 0 when you delete the slice (see examples) rather than using this command.
    When you want to check whether the result of a slice command is a valid slice, you can just test whether the handle is false, as this example shows:
    variable(sl)
    # Let's find a slice.
    sl := lookup code(sl:textbox portrait box)
    # Does this special slice exist?
    # You could write if(slice is valid(sl)) then (....),
    # and it would be correct to do so, but it's pointless.
    # You should just write this instead:
    if (sl) then (....)
    # All commands that normally return a slice handle and might fail will return 'false',
    # so there is never a need to use sliceisvalid in that situation.
    				
    The following example shows how to be safe when deleting a slice:
    global variable (1, bullet slice)
    
    ###### Suppose one script creates a slice:
    
    plotscript, fire bullet, begin
    	bullet slice := create rect (3, 3)
    	...
    end
    
    ###### And somewhere else (say, inside our main loop) we want to use it:
    
    	# Test for collision with the player
    	if (slice collide (bullet slice, get hero slice(me))) then (
    		...
    
    		# Bullet is destroyed
    		free slice (bullet slice)
    	)
    
    ###### Wait! First we need to test if there is a bullet slice at all, or we have an error.
    ###### You could use sliceisvalid:
    
    	if (slice is valid (bullet slice)) then (
    		# Test for collision with the player
    		if (slice collide (bullet slice, get hero slice(me))) then (
    			...
    		)
    	)
    
    ###### Or you could make sure to set the variable bulletslice to 0 in every single place you delete
    ###### it so there are no invalid slice handles.
    ###### Some of other places aren't obvious! They include leaving the map, or loading a saved game!
    
    	if (bullet slice) then (     # <--- This works only because we do the needed bookkeeping
    		# Test for collision with the player
    		if (slice collide (bullet slice, get hero slice(me))) then (
    			...
    			# Bullet is destroyed
    			free slice (bullet slice)
    			bullet slice := 0     # <---
    		)
    	)
    				

    dump slice tree (slice)

    Documented in the Debugging section.

    free slice (handle)

    Deletes a slice and any child slices. This works on any type of slice. This removes the slice from the screen and removes it from memory. You should free your slices after you are completely done with them.
    Freeing the same slice handle twice shows a warning (if slice error reporting is enabled, e.g. while testing your game). However, free slice (0) is fine, showing no warning. It's good practice to set a variable containing a slice handle to 0 after you free it, so that the script can easily test whether the slice exists or not without needing to use slice is valid.

    [Notice] You can't delete a protected slice, which includes most slices created by the engine such as NPCs and heroes.
    script, simple example, begin
      variable(sl)
      sl := load hero sprite(0)
      wait(20)
      free slice(sl)
    end
    
    script, example with children, begin
      variable(box, sl)
      
      # create a box
      box := create rect(100, 60)
      
      # center a hero as a child of the box
      sl := load hero sprite(0)
      set parent(sl, box)
      center slice(sl)
      
      wait(20)
      
      # when you free the box, the hero will be freed too
      free slice(box)
    
      # The sprite is gone now, so if you use the handle that used to point
      # to it, you will get an error message in your g_debug.txt file
      position sprite(sl, 25, 25)
    end
    
    script, wrong way to free in a loop, begin
      # this loop is the WRONG way to remove all sprites that show frame number 1
      # because removing a slice inside a loop will interfere with the "next sibling"
      # command causing the loop to end early
      variable(sl)
      sl := first child(sprite layer)
      while(sl) do, begin
        if(slice is sprite(sl)) then, begin
          if(get sprite frame(sl) == 1) then(free slice(sl))
        end
        sl := next sibling(sl)
      end
    end
    
    script, right way to free in a loop, begin
      # this loop is the right way to remove all sprites that show frame number 1
      # by waiting until AFTER the "next sibling" command, we can free the slice
      # without ending the loop early
      variable(sl, deleteme)
      sl := first child(sprite layer)
      while(sl) do, begin
        deleteme := 0
        if(slice is sprite(sl)) then, begin
          if(get sprite frame(sl) == 1) then(deleteme := sl)
        end
        sl := next sibling(sl)
        if(deleteme) then(free slice(deleteme))
      end
    end
    

    free slice children (handle)

    Frees all the children of a slice, but not the slice itself. See free slice for more details.

    See also:

    clone slice (handle, recurse)

    Copies (clones) a slice. If the optional argument recurse is true (which is the default), then all its children and descendents are copied too. Returns the slice handle for the copy, which has the same parent, and becomes the previous sibling to handle.
    You can copy a protected slice (such as an NPC); the result isn't protected. Any slices with special lookup codes (those listed in lookup slice) won't have their lookup codes copied; they'll be set to 0 instead. If the slice is a Template then the copy won't be marked as a template, but the copies of any descendents it has still will be. Passing the root slice or a Map slice as handle is an error. Trying to clone a slice which has a Map slice as a descendent is OK, the Map slices just won't be copied. Any slices of type Special (such as the textbox or script layers) will be copied as plain Container slices (there isn't really any difference between them).

    [Notice] Ongoing slice movement (e.g. velocity) and sprite dissolves are copied into the clone too, so you might need to reset those.

    reparent to npc (handle, npc)

    Reparent a slice handle so that it is attached to an NPC's sprite. The npc argument can be an ID number or an NPC reference. The slice will be parented to the NPC's sprite component. If you want it to be parented to the NPC's container slice you should use set parent(handle, get npc slice(npc)) instead.

    reparent to hero (handle, hero)

    Reparent a slice handle so that it is attached to an hero's walkabout caterpillar sprite. The hero argument is the hero's rank in the caterpillar party. The slice will be parented to the hero's sprite component. If you want it to be parented to the hero's container slice you should use set parent(handle, get hero slice(hero)) instead.


    Slices → Getting Slices

    This section describes commands to find existing slices or load them from a defined slice collection. Commands to create slices are in other sections.

    load slice collection (id)

    Loads a collection of slices that you have defined in the slice collection editor.
    The argument is the id number of the collection.
    The return value is a handle to the container that holds the loaded collection. If the collection doesn't exist (it's marked as BLANK in the editor), then the return value is false (0).

    lookup slice (lookup code, root slice)

    Search for a slice that's tagged with a slice lookup code, and return a handle to it, or 0 if it is not found.
    root slice is optional, if you don't specify it the whole slice tree will be searched, otherwise only descendents of that slice (a subtree) will be searched. root slice itself will be returned if it matches.

    [Notice] You can use a number as a lookup code, but usually you use a builtin code constant, starting with sl: (see below), or name a code in the slice editor, in which case the constant will start with sli:. Don't mix them up!
    [Notice]Although the user-defined slice lookup codes are always safe to use for any purpose, there is a lot of potential mischief that you can do with a handle to a special slice. If you do anything dubious, like reordering, reparenting, or god forbid freeing the special slice, don't expect your scripts to work in later versions of the engine, which are likely to impose stricter restrictions! Deleting or reparenting special slices generally won't work. You may parent your own slices to these special slices, though.
    [Notice] When there is more than one slice with the same lookup code this command will only return the first one it finds (in depth-first search order). If you need to find multiple slices with the same lookup code, use lookup next slice.
    Also, if you want to find a slice based on something other than lookup code, search for it using next slice in tree.
    You may set parent a slice to a map layer (or to sl:map overlay which is above all map layers) to make it move with the camera just like heroes and NPCs do.
    # this example loads a saved slice collection,
    # and gets a handle to a slice in it that you
    # have marked with a slice lookup code name.
    variable(collection, sl)
    collection := load slice collection(5)
    sl := lookup slice(sli:my special slice, collection)
    
    # this example gets a handle to the portrait of the currently displaying
    # text box (if any) and allows you to manipulate it.
    variable(portrait)
    portrait := lookup slice(sl:textbox portrait)
    if(portrait) then(
      replace portrait sprite(portrait, 5)
    )
    
    # This is a list of special slice lookup codes
    lookup slice(sl:root)
    lookup slice(sl:textbox text)
    lookup slice(sl:textbox portrait)
    lookup slice(sl:textbox choice0)
    lookup slice(sl:textbox choice1)
    lookup slice(sl:textbox box)
    lookup slice(sl:textbox portrait box)
    lookup slice(sl:textbox choice box)
    lookup slice(sl:textbox root)
    lookup slice(sl:script layer)
    lookup slice(sl:sprite layer)  # Same as lookup slice(sl:script layer)
    lookup slice(sl:textbox layer)
    lookup slice(sl:string layer)
    lookup slice(sl:reserve)
    lookup slice(sl:maproot)
    lookup slice(sl:obsolete overhead)
    lookup slice(sl:map overlay)
    lookup slice(sl:walkabout layer)
    lookup slice(sl:hero layer)
    lookup slice(sl:npc layer)
    lookup slice(sl:walkabout sprite)
    lookup slice(sl:walkabout sprite component)  # Same as lookup slice(sl:walkabout sprite)
    lookup slice(sl:walkabout shadow)
    lookup slice(sl:walkabout shadow component)  # Same as lookup slice(sl:walkabout shadow)
    lookup slice(sl:backdrop)
    lookup slice(sl:map layer0)
    lookup slice(sl:map layer1)
    lookup slice(sl:map layer2)
    lookup slice(sl:map layer3)
    lookup slice(sl:map layer4)
    lookup slice(sl:map layer5)
    lookup slice(sl:map layer6)
    lookup slice(sl:map layer7)
    lookup slice(sl:map layer8)
    lookup slice(sl:map layer9)
    lookup slice(sl:map layer10)
    lookup slice(sl:map layer11)
    lookup slice(sl:map layer12)
    lookup slice(sl:map layer13)
    lookup slice(sl:map layer14)
    lookup slice(sl:map layer15)
    lookup slice(sl:pathfind dest display)
    

    lookup next slice (lookup code, current slice, root slice)

    Find the next slice after current slice that has a certain slice lookup code and return it, or 0 if there are no more matching slices.
    The first matching slice after current slice (in the order that slices are shown in the slice editor/debugger, called the "depth first search order"), will be returned. current slice is actually optional, if it's 0 then this command is equivalent to lookup slice. (In that case, if root slice has the lookup code you're searching for, it's returned first.) current slice can be any descendent of root slice, it doesn't have to have the lookup code.
    root slice is optional, if you don't specify it the whole slice tree will be searched, otherwise only descendents of that slice (a subtree) will be searched.

    [Notice] You can delete slices while you're iterating over them, as long as you don't pass a handle to a deleted slice to this command.
    # Suppose you've scripted a slice-based GUI or menu, attached to the sprite layer,
    # and every clickable thing the sli:selectable lookup code, and now you want to undo any
    # highlighting of text or buttons you might have added previously due to mouse-over.
    variable(sl)
    sl := lookup slice (sli:selectable, sprite layer)
    while (sl) do (
      if (slice is sprite (sl)) then (set sprite frame (sl, 0))  # Reset button appearances
      if (slice is text (sl)) then (set text color (sl, ui:text))  # Reset text highlighting
      sl := lookup next slice (sli:selectable, sl, sprite layer)
    )
    # An alternative way to write the above
    variable(sl)
    while (true) do (
      sl := lookup next slice (sli:selectable, sl, sprite layer)
      if (sl == 0) then (break)
      if (slice is sprite (sl)) then (set sprite frame (sl, 0))  # Reset button appearances
      if (slice is text (sl)) then (set text color (sl, ui:text))  # Reset text highlighting
    )

    lookup ancestor (lookup code, slice)

    Search for a slice's ancestor that's tagged with a slice lookup code, and return a handle to it, or 0 if no ancestor slice has the lookup code. Starts by checking the parent, and goes up to the root.

    script layer

    Returns a slice handle for the slice (also called the 'sprite layer') which is the default parent of all new script-created slices, such as created by load hero sprite and create rect. You can move slices elsewhere in the slice tree with set parent. You can use scriptlayer together with first child if you want to loop through all your slices (that you haven't reparented) without knowing their handles. Another way to get this slice is to use lookup slice: lookup slice(sl:script layer).

    variable(sl)
    sl := first child(sprite layer)
    while (sl) do, begin
     if (slice is sprite(sl)) then, begin
       # do an operation on each sprite
     end
     sl := next sibling(sl)
    end
    

    spritelayer

    An alias for script layer.

    get slice lookup (handle)

    Returns the slice lookup code of a slice, or false if it has none. You can compare the result with the sli: slice lookup values in your hsi file, or with the sl: special builtin lookup values

    set slice lookup (handle, code)

    Changes the lookup code of a slice. The first argument is the slice handle, the second is the new slice lookup code. You can pass false as the lookup code to remove it. The code can be either a lookup code you named in the slice editor, which is available as a constant with a sli: prefix added (e.g. "menubg" becomes sli:menubg), or any positive number - you don't have to give a name to a lookup code before using it! (The values of sli: codes count up from 1, so use large numbers for unnamed lookup codes, to avoid clashing).
    You can't use sl: special builtin lookup codes, nor can you modify the lookup code of slices that already have special lookup codes. Only user-defined lookup codes can be changed. Built-in special lookup codes cannot.

    get slice lookup name (string id, code, use default name)

    Documented in the Debugging section.

    get hero slice (rank)

    Get a hero walkabout container slice (the parent of all slices for the hero). rank is the hero's rank in the walkabout caterpillar, from 0-3, e.g. me for the leader. Returns 0 if there is no hero in that rank in the active party, but still returns the slice even if the caterpillar party is disabled (the slice will be hidden). You can use get hero slice by slot instead, which works for heroes in the reserve party too.
    You won't be able to manually reposition this slice (e.g. put slice does not work) - use put hero instead.
    Once you have this slice you can access any other slices attached to the hero, such as the sprite slice (e.g. lookup slice(sl:walkabout sprite component, get hero slice(rank)), which is equivalent to get hero sprite(rank)), or attach other slices to a hero walkabout. See lookup slice for the different walkabout components.

    get hero slice by slot (slot)

    Get a hero walkabout container slice (the parent of all slices for the hero), from the slot in the hero party. Returns 0 if there is no hero in that slot.
    This is an alternative to get hero slice, see that command for more info.
    slot can even be in the reserve party: all heroes have slices. Slices for heroes in the reserve party are parented to the special 'Reserve' slice (lookup slice(sl:reserve)) instead of to a walktabout layer.

    get hero sprite (rank)

    Get the walkabout sprite slice for a hero. rank is the hero's rank in the walkabout caterpillar (0-3), e.g. me for the leader. This is equivalent to lookup slice(sl:walkabout sprite component, get hero slice(rank)).

    get hero sprite by slot (slot)

    Get the walkabout sprite slice for a hero. slot is the hero's slot in the party, including reserve party slots. This is equivalent to lookup slice(sl:walkabout sprite component, get hero slice by slot(slot)).

    hero rank from slice (handle)

    The opposite of get hero slice: Given a slice handle, check whether it's the walkabout container slice of some hero, and if so, returns the hero rank in the party (always a number between 0 and 3 if the hero is in the active party). If it doesn't belong to any hero, returns -1, not 0/false, like npc reference from slice does!
    This also returns -1 for slices parented to a hero slice, such as the 'walkabout sprite component'.
    This command is useful if you've detected a collision between two slices (e.g. using find colliding slice), such as a projectile and another slice, and you want to check whether the projectile hit a hero, and which one.

    hero slot from slice (handle)

    The opposite of get hero slice by slot: Given a slice handle, check whether it's the walkabout container slice of some hero, and if so, returns the hero's party slot (0 or higher). If it doesn't belong to any hero, returns -1, not 0/false, like npc reference from slice does!
    See hero rank from slice for more information.

    get npc slice (npc)

    Get an NPC walkabout container slice (the parent of all slices for the NPC). The argument is an NPC reference or NPC ID. If the NPC is tag-disabled, it has no slice so this command returns 0/false. If there are no copies of an NPC ID on the map, an error is thrown. You will not be able to manually reposition this slice (e.g. put slice does not work) - use put NPC instead.
    Once you have this slice you can access any other slices attached to the npc, such as the sprite slice (e.g. lookup slice(sl:walkabout sprite component, get npc slice(npc)), which is equivalent to get npc sprite(npc)), or attach other slices to an npc walkabout.

    get npc sprite (npc)

    Get the walkabout sprite slice for a npc. npc is an NPC reference or NPC ID. This is equivalent to lookup slice(sl:walkabout sprite component, get npc slice(npc)).

    See also:

    npc reference from slice (handle)

    The opposite of get npc slice: Given a slice handle, check whether it's the walkabout container slice of some NPC, and if so, returns the NPC reference. If it doesn't belong to any NPC, returns 0.
    This also returns 0 for slices parented to the NPC's slices, such as the 'walkabout sprite component'.
    This command is useful if you've detected a collision between two slices (e.g. using find colliding slice), such as a projectile and another slice, and you want to check whether the projectile hit an NPC, and which one.


    Slices → Slice Sizing

    slice width (handle)

    Returns the width of any slice, for example a sprite.

    slice height (handle)

    Returns the height of any slice, for example a sprite.

    set slice width (handle, width)

    Changes the width of a slice. This command doesn't work (and shows an error) on sprite and map slices, on text slices that aren't set to wrap, and on slices set to Fill Parent, because they all have a fixed size.

    set slice height (handle, height)

    Changes the height of a slice. This command doesn't work (and shows an error) on sprite and map slices, on text slices that aren't set to wrap, and on slices set to Fill Parent, because they all have a fixed size.

    set slice size (handle, width, height)

    Changes the width and height of a slice. This command doesn't work (and shows an error) on sprite and map slices, on text slices that aren't set to wrap, and on slices set to Fill Parent, because they all have a fixed size.

    clamp slice (slice, within slice)

    Try to move slice so that its screen position will be inside the screen position of within slice. The size of the slices will not be changed, so if within sl isn't large enough to contain slice it will stick out at least one side (it's shifted to align with the nearest vertical and nearest horizontal edge of within slice). It does not matter whether the slices are related.

    See also:

    fill parent (handle, true_or_false)

    Make a slice handle automatically fill its parent. This will change the position and size of the slice so that it completely fills the parent (minus the parent's padding). You can also disable filling with this command by passing false as the second argument, such as fill parent(handle, false). If a slice is filling its parent, then any commands which modify the width or height of the slice will fail. You should resize the parent instead. This command only works on rects and containers. It will not work on sprites because they cannot change size.

    is filling parent (handle)

    Returns true if a slice handle is set to automatically fill its parent, or false if it is not. This command always returns false for sprite slice handles because sprites cannot be set to fill parent.

    See also:


    Slices → Positioning Slices

    slice x (handle)

    Returns the X position of any slice, for example a sprite. This position is relative to the slice's parent, and may depend upon the slice's Align settings.

    [Notice] If you want the global position of a slice (i.e. relative to top-left of the map), use the slice screen x example script.

    slice y (handle)

    Returns the Y position of any slice, for example a sprite. This position is relative to the slice's parent, and may depend upon the slice's Align settings.

    put slice (handle, X, Y)

    Changes the position of any slice, for example a sprite. This position is relative to the slice's parent, and may depend upon the slice's Align settings.

    set slice x (handle, X)

    Changes the X position of any slice, for example a sprite. This position is relative to the slice's parent. More exactly, it's the relative displacement between this slice's anchor point, and the selected align point on the parent. The position of the parent's align point also depends on the amount of padding the parent has.

    set slice y (handle, Y)

    Changes the Y position of any slice, for example a sprite. This position is relative to the slice's parent. More exactly, it's the relative displacement between this slice's anchor point, and the selected align point on the parent. The position of the parent's align point also depends on the amount of padding the parent has.

    slice screen x (handle)

    Returns the X position on the screen of the anchor point of a slice. This position is relative to the screen, so it is calculated based on not only the slice's X position, but also its alignment, and the position and size of its parents. However, the slice's anchor point setting doesn't affect this, because that specifies which point on the slice is attached to the anchor point.

    # slice screen x can be used to compute the position of a slice on the map, in pixels:
    variable (map x, map y)
    map x := slice screen x(sl) + camera pixel x
    map y := slice screen y(sl) + camera pixel y

    slice screen y (handle)

    Returns the Y position on the screen of the anchor point of a slice. This position is relative to the screen, so it is calculated based on not only the slice's Y position, but also its alignment, and the position and size of its parents. However, the slice's anchor point setting doesn't affect this, because that specifies which point on the slice is attached to the anchor point.

    put slice screen (handle, x, y)

    Change the screen position of any slice. The position of the slice relative to its parent will automatically be corrected. Alignment and anchor will not be changed. Note that this does not work when a slice is filling its parent.

    set slice screen x (handle, x)

    Change the screen X position of any slice. The position of the slice relative to its parent will automatically be corrected. Alignment and anchor will not be changed. Note that this does not work when a slice is filling its parent.

    set slice screen y (handle, y)

    Change the screen Y position of any slice. The position of the slice relative to its parent will automatically be corrected. Alignment and anchor will not be changed. Note that this does not work when a slice is filling its parent.


    Slices → Extra Data

    You can use any of the Extra Data Array Functions on slices.

    set slice extra (handle, extra, value)

    Sets one of the extra data variables on the slice handle. extra is an extra array index.
    This command is the same as set extra but only works on slices and is slightly faster.

    get slice extra (handle, extra)

    Retrieve an extra data value previously set on a slice handle with set slice extra. extra is an extra array index.
    This command is the same as get extra but only works on slices and is slightly faster.


    Slices → Visibility and Clipping

    set slice visible (handle, vis)

    Makes slice handle invisible or visible. vis is a true or false value. Slices are automatically visible when you load them, but you can make them invisible with set slice visible(handle, off). If the slice has children, they will become invisible too.

    set sprite visible

    An alias for set slice visible.

    get slice visible (handle)

    Returns the visibility setting for slice handle. This is true for visible, or false for invisible. Note that this only tells you if the slice is set to be invisible, it will not tell you if the slice is invisible for some other reason, such as if it is offscreen, or if it is the descendent of an invisible slice.

    set slice clipping (handle, clip)

    Changes whether or not a slice will clip its children if they overflow its edges. The first argument is a slice handle. The second argument is true to make the slice clip, or false to allow its children to overflow. (Newly created slices do not clip by default)

    get slice clipping (handle)

    Returns true if the slice handle is set to clip drawing its children, or false if child slices are allowed to be drawn overflowing its edges.


    Slices → Slice Blending

    set opacity (handle, percent)

    Set the opacity (the opposite of transparency) of a slice. handle is a blendable slice handle. percent is normally a value from 0 to 100; values outside this range are clipped to 0-100 without showing an error. Opacity 0 is completely invisible, and 100 is fully opaque (solid) if the blending mode is 'Normal'. If the blending mode is 'Add' or 'Multiply', the slice is never opaque, due to how those work.
    If percent < 100 then blending is automatically enabled (set blending enabled).

    [Notice] You have to use set rect opacity instead on Rect slices.

    get opacity (handle)

    Returns the opacity of any slice (from 0-100; see set opacity). handle is a slice handle; if it isn't a blendable slice handle or if blending is disabled for this slice, 100 is returned without showing an error.

    [Notice] You have to use get rect opacity instead on Rect slices.

    set blend mode (handle, blend mode)

    Set the blending mode (aka blend mode) of a slice, also enables blending (set blending enabled). handle is a blendable slice handle. blend mode is one of:

    See also:

    get blend mode (handle)

    Gets the blend mode of any slice (see set blend mode). handle is a slice handle; if it isn't a blendable slice handle or if blending is disabled for this slice, then this returns blend:normal without showing an error.

    See also:

    set blending enabled (handle, state)

    Set whether blending (opacity and blend mode) is enabled for a slice. handle is a blendable slice handle. state is a true or false value.

    [Notice] You normally don't need to use this command, because setting a slice's opacity or blend mode will automatically enable blending. This command is only useful if you want to temporarily disable blending and then reenable it later, because disabling it (including in the slice editor) preserves the other blending settings, even though they're hidden in the editor.

    get blending enabled (handle)

    Tells whether any slice has its blending settings, if any, enabled; returns true or false. handle is a slice handle; if it isn't a blendable slice handle then this returns false without showing an error.

    [Notice] You normally wouldn't use this command for anything. Even if blending is enabled, that doesn't tell whether the slice is transparent/blended or appears normally. To check that, instead of this command, write
    if (get opacity(sl) < 100 || get blend mode(sl) <> blend:normal)


    Slices → Alignment and Anchor Points

    slice edge x (handle, edge)

    Returns the x position of a particular edge of a slice. Use the constants edge:left, edge:center, edge:right. (Not the align: constants used by menus!)

    slice edge y (handle, edge)

    Returns the y position of a particular edge of a slice. Use the constants edge:top, edge:middle, edge:bottom. (Not the align: constants used by menus!)

    set slice edge x (handle, edge, value)

    Changes the X position of a specific edge of a slice. This is like set slice x, except that you can set by any edge regardless of the slice's anchor. Use the constants edge:left, edge:center, edge:right. (Not the align: constants used by menus!)

    set slice edge y (handle, edge, value)

    Changes the Y position of a specific edge of a slice. This is like set slice y, except that you can set by any edge regardless of the slice's anchor. Use the constants edge:top, edge:middle, edge:bottom. (Not the align: constants used by menus!)

    set horiz align (handle, edge)

    Changes the horizontal alignment of any slice relative to its parent. The available edges are edge:left, edge:center, edge:right. (Not the align: constants used by menus!) The default value is edge:left.

    set vert align (handle, edge)

    Changes the vertical alignment of any slice relative to its parent. The available edges are edge:top, edge:middle, edge:bottom. (Not the align: constants used by menus!) The default value is edge:top.

    set horiz anchor (handle, edge)

    Changes the horizontal anchor of any slice. The available anchor values are edge:left, edge:center, edge:right. (Not the align: constants used by menus!) The default value is edge:left.

    set vert anchor (handle, edge)

    Changes the vertical anchor of any slice. The available anchor values are edge:top, edge:middle, edge:bottom. (Not the align: constants used by menus!) The default value is edge:top.

    get horiz align (handle)

    Returns the horizontal alignment of any slice relative to its parent. The return value will be one of edge:left, edge:center, edge:right. (Not the align: constants used by menus!)

    get vert align (handle)

    Returns the vertical alignment of any slice relative to its parent. The return value will be one of edge:top, edge:middle, edge:bottom. (Not the align: constants used by menus!)

    get horiz anchor (handle)

    Returns the horizontal anchor that a slice uses to position itself relative to its parent. The return value will be one of edge:left, edge:center, edge:right. (Not the align: constants used by menus!)

    get vert anchor (handle)

    Returns the vertical anchor that a slice uses to position itself relative to its parent. The return value will be one of edge:top, edge:middle, edge:bottom. (Not the align: constants used by menus!)

    realign slice (handle, horiz align, vert align, horiz anchor, vert anchor)

    A quick way to set the alignment and optionally the anchor of a slice with a single command. If you leave out the arguments for the anchor then only the alignment will be changed.

    center slice (handle)

    A quick way to center the alignment and the anchor of a slice with a single command. Equivalent to realign slice(handle, edge:center, edge:center, edge:middle, edge:middle).

    gently realign slice (handle, horiz align, vert align, horiz anchor, vert anchor)

    A quick way to set the alignment and optionally the anchor of a slice with a single command, but to preserve the current screen position of the slice. This will alter a slices relative position, but keep its screen position the same as the alignment and anchor change. If you leave out the arguments for the anchor then only the alignment will be changed.


    Slices → Padding

    set padding (handle, pixels)

    Sets the padding value in pixels for all the edges of a slice handle. This is a positive number to move children attached to the edges towards the center of the slice, or a negative number to move attached children further from the center.

    get top padding (handle)

    Get the padding value in pixels for the top edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.

    set top padding (handle, pixels)

    Set the padding value in pixels for the top edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.

    get left padding (handle)

    Get the padding value in pixels for the left edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.

    set left padding (handle, pixels)

    Set the padding value in pixels for the left edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.

    get right padding (handle)

    Get the padding value in pixels for the right edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.

    set right padding (handle, pixels)

    Set the padding value in pixels for the right edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.

    get bottom padding (handle)

    Get the padding value in pixels for the bottom edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.

    set bottom padding (handle, pixels)

    Set the padding value in pixels for the bottom edge of a slice handle. This is a positive number to move children attached to this edge towards the center of the slice, or a negative number to move attached children further from the center.


    Slices → Moving Slices

    set slice velocity x (handle, pixels per tick, ticks)

    Cause slice handle to start moving horizontally. A negative value for pixels per tick moves left, and a positive value for pixels per tick moves right. The ticks argument is optional. If you do not specify the number of ticks, the slice will keep moving indefinitely. If you specify the number of ticks, the velocity will expire and be set back to zero automatically after that number of ticks has passed.
    Calling this command causes movement due to move slice by or move slice to to be cancelled.

    [Notice] Movement in horizontal and vertical directions is independent, and can timeout after different numbers of ticks. For example if you set a slice's x velocity to 10 for 5 ticks, and y velocity to 10 for 2 ticks, it'll move diagonally down-right for 2 ticks and then right for 3 ticks.

    set slice velocity y (handle, pixels per tick, ticks)

    Cause slice handle to start moving vertically. A negative value for pixels per tick moves up, and a positive value for pixels per tick moves down. The ticks argument is optional. If you do not specify the number of ticks, the slice will keep moving indefinitely. If you specify the number of ticks, the velocity will expire and be set back to zero automatically after that number of ticks has passed.
    Calling this command causes movement due to move slice by or move slice to to be cancelled.

    [Notice] Movement in horizontal and vertical directions is independent, and can timeout after different numbers of ticks. For example if you set a slice's x velocity to 10 for 5 ticks, and y velocity to 10 for 2 ticks, it'll move diagonally down-right for 2 ticks and then right for 3 ticks.

    get slice velocity x (handle)

    Returns a number representing the horizontal velocity of slice handle. The return value is in pixels per tick. A negative value means the slice is moving left, and a positive value means the slice is moving right.

    get slice velocity y (handle)

    Returns a number representing the vertical velocity of slice handle. The return value is in pixels per tick. A negative value means the slice is moving up, and a positive value means the slice is moving down.

    set slice velocity (handle, horiz pixels per tick, vert pixels per tick, ticks)

    Cause slice handle to start moving. This is similar to using both set slice velocity x and set slice velocity y at the same time (except that those let you use different ticks for the X and Y velocities). The ticks argument is optional. If you do not specify the number of ticks, the slice will keep moving indefinitely. If you specify the number of ticks, the velocity will expire and be set back to zero automatically after that number of ticks has passed.
    Calling this command causes movement due to move slice by or move slice to to be cancelled.

    stop slice (handle)

    Cause slice handle to stop moving. This cancels any previous slice velocity and move slice commands.

    move slice to (handle, x, y, ticks)

    Instruct slice handle to move in a straight line to a specific x and y position over a given number of ticks. (As always, the position is an offset relative to its parent. See move slice to screen pos if you want to use screen coordinates instead)
    If the slice had velocity set with set slice velocity, set slice velocity x or set slice velocity y it will be cancelled.

    [Notice] If you change the slice's position manually during that time (eg. with put slice), it'll continue to move towards the original target in a straight line (but now with a different velocity), until ticks is up. Use set slice velocity instead if you don't want this.

    move slice to screen pos (handle, x, y, ticks)

    Instruct slice handle to move in a straight line to a specific x and y screen position over a given number of ticks. (Unlike move slice to the position is relative to the screen, regardless of the slice's parentage)
    If the slice had velocity set with set slice velocity, set slice velocity x or set slice velocity y it will be cancelled.

    [Notice] If you change the slice's position manually during that time (eg. with put slice), it'll continue to move towards the original target in a straight line (but now with a different velocity), until ticks is up. Use set slice velocity instead if you don't want this.

    move slice by (handle, relative x, relative y, ticks)

    Instruct slice handle to move in a straight line to an x and y offset relative to its current position over a given number of ticks.
    A negative relative x moves left.
    A positive relative x moves right.
    A negative relative y moves up.
    A positive relative y moves down.
    If the slice had velocity set with set slice velocity, set slice velocity x or set slice velocity y it will be cancelled.

    [Notice] If you change the slice's position manually during that time (eg. with put slice), it'll continue to move towards the original target in a straight line (but now with a different velocity), until ticks is up. Use set slice velocity instead if you don't want this.

    wait for slice (handle)

    Cause the script to wait until slice handle has stopped moving. This only applies to commands that operate over time like set slice velocity x or set slice velocity or move slice to or move slice by. There is no reason to use this command for instantaneous slice moving commands like put slice or set slice x or set slice y.

    slice is moving (handle)

    Returns true if the slice handle is moving (has velocity or has been instructed to move to some point). Returns false if the slice is not moving.

    move slice with wallchecking (sl, relative x, relative y, friction%)

    Documented in the Wall Checking section.


    Slices → Moving Around the Slice Tree

    slice child (handle, number)

    Returns a handle for the nth child of a slice, counting from 0. Returns false if number is too large (last child(handle) is equivalent to slice child(handle, child count(handle) -- 1)). Note that you will need to use first child and next sibling to iterate over the children of a slice, rather than this command, when you are moving the children around.

    child count (handle)

    Returns the number of children that slice handle has.

    slice child index (handle)

    Returns an integer that that indicates which number this slice is among its sibling slices that share the same parent. The first slice will return index 0, the second slice 1, the third slice 2, etc...

    See also:

    first child (handle)

    Returns a slice handle for the first child of a given slice handle. Returns false if the slice has no children. You can use this to loop through all the children of a slice.

    variable(sl)
    sl := first child(sprite layer)
    while (sl) do, begin
     if (slice is sprite(sl)) then, begin
       # do an operation on each sprite
     end
     sl := next sibling(sl)
    end
    

    last child (handle)

    Returns a slice handle for the last child of a given slice handle. Returns false if the slice has no children.

    next sibling (handle)

    Returns a slice handle for the next sibling of a given slice handle. Returns false if the given slice is the last sibling of its parent. This is useful when looping through slices.

    variable(sl)
    sl := first child(sprite layer)
    while (sl) do, begin
     if (slice is sprite(sl)) then (
       # ...do an operation on each sprite
     )
     sl := next sibling(sl)
    end
    
    # The above loop can be written more simply as:
    sl := first sprite child(sprite layer)
    while (sl) do, begin
     # ...do an operation on each sprite
     sl := next sprite sibling(sl)
    end
    

    previous sibling (handle)

    Returns a slice handle for the previous sibling of a given slice handle, the inverse of next sibling . Returns false if the given slice is the first sibling of its parent. This is useful when looping through slices.

    parent slice (handle)

    Alias:

    slice parent (handle)

    Returns a slice handle for the parent of slice handle, or 0 if handle is the root slice.

    next slice in tree (current slice, root slice, visit children)

    Returns the next slice after current slice in the slice tree or a slice subtree. This can be used for iterating over a tree of slices using a while loop, in the order that they appear in the slice collection editor (from top to bottom): first go to the first child if any, and then any other descendents and children, then go across to the next sibling if any, then finally go up and look for a sibling of the parent, then of the grandparent, etc. Finally, returns false if current slice is the last descendent of root slice.
    root slice tells the sub-tree to iterate over: every descendent of it starting with root slice itself. root slice is optional, if it's omitted (or 0) then iterate over the entire slice tree.
    On the first iteration you can pass 0 or false as current slice, in which case the return value is root slice. current slice can actually be any slice, but should normally be in the subtree defined by root slice.
    visit children is optional, defaulting to true. If false, then skip over all the children and descendents of this slice.
    Unless you use visit children = false each slice in the sub-tree is visited exactly once, provided that you don't add, delete, or reorder slices.

    variable(root, sl)
    root := sprite layer
    sl := root
    # If you want to skip over the root slice itself, write instead:
    #sl := first child(root)
    
    while (sl) do, begin
      # Reset all text slices to default text color, e.g. to unhighlight all menu items in a slice-based menu
      if (slice is text(sl)) then (set text color(sl, ui:Text))
      sl := next slice in tree(sl, root)
    end
    
    This example shows how to delete slices while you're iterating over them:
    variable(root, sl, next)
    root := sprite layer
    sl := root
    
    while (sl) do, begin
      next := next slice in tree(sl, root)
      # Delete all the hidden slices
      if (get slice visible(sl) == false) then (
        free slice (sl)
      )
      sl := next
    end
    

    check parentage (handle, ancestor handle)

    Checks to see if handle is a descendent of ancestor handle. Returns true or false. The result is false if handle == ancestor handle.


    Slices → Moving Around the Slice Tree → Type-specific Iteration Commands

    first child of type(handle, type)

    Returns a slice handle for the first child of a given slice handle which has the given type. type is one of the slicetype: constants, such as slicetype:sprite. See slice type for the full list. Returns false if the slice has no children of that type. Children of other types will be ignored. This is useful when looping through slices.

    See also:

    next sibling of type (handle, type)

    Returns a slice handle for the next sibling of a given slice handle which has the given type. type is one of the slicetype: constants, such as slicetype:sprite. See slice type for the full list. Returns false if there are no more children of that type. Children of other types will be ignored. This is useful when looping through slices.

    See also:

    first container child (handle)

    An alias for first child of type(handle, slicetype:container).

    next container sibling (handle)

    An alias for next sibling of type(handle, slicetype:container).

    first rect child (handle)

    An alias for first child of type(handle, slicetype:rect).

    next rect sibling (handle)

    An alias for next sibling of type(handle, slicetype:rect).

    first sprite child (handle)

    An alias for first child of type(handle, slicetype:sprite).

    next sprite sibling (handle)

    An alias for next sibling of type(handle, slicetype:sprite).

    first text child (handle)

    An alias for first child of type(handle, slicetype:text).

    next text sibling (handle)

    An alias for next sibling of type(handle, slicetype:text).

    first ellipse child (handle)

    An alias for first child of type(handle, slicetype:ellipse).

    next ellipse sibling (handle)

    An alias for next sibling of type(handle, slicetype:ellipse).

    first grid child (handle)

    An alias for first child of type(handle, slicetype:grid).

    next grid sibling (handle)

    An alias for next sibling of type(handle, slicetype:grid).

    first scroll child (handle)

    An alias for first child of type(handle, slicetype:scroll).

    next scroll sibling (handle)

    An alias for next sibling of type(handle, slicetype:scroll).

    first select child (handle)

    An alias for first child of type(handle, slicetype:select).

    next select sibling (handle)

    An alias for next sibling of type(handle, slicetype:select).

    first panel child (handle)

    An alias for first child of type(handle, slicetype:panel).

    next panel sibling (handle)

    An alias for next sibling of type(handle, slicetype:panel).

    first line child (handle)

    An alias for first child of type(handle, slicetype:line).

    next line sibling (handle)

    An alias for next sibling of type(handle, slicetype:line).


    Slices → Reordering Slices

    slice to front (handle)

    Sort a slice handle so that it is drawn in front of other slices with the same parent. This is done by moving it to the end of its parent's child list. If you use this command inside a loop that iterates through slices using next sibling be careful not to accidentally create an endless loop.

    script, simple example, begin
      # As long as you are not looping with the "next sibling" command
      # then "slice to front" is safe and easy to use.
      variable(sl)
      sl := first child(sprite layer)
      slice to front(sl)
    end
    
    script, dangerous sorting, begin
      # this is an example of the WRONG way to move all rect slices to the
      # front in a loop. Because moving a slice to the front adds it to the
      # end of the list, the loop will go on forever.
      variable(sl)
      sl := first child(sprite layer)
      while(sl) do, begin
        if(slice is rect(sl)) then, begin
          slice to front(sl)
        end
        sl := next sibling(sl)
      end
    end
    
    script, safe sorting, begin
      # This is an example of the right way to move all rect slices to the
      # front in a loop. By remembering which slice was last before the
      # loop starts (or by using "previous sibling") it is safe to move slices
      # to the end of the sibling list.
      # We also ensure the rects stay in the same relative order by writing
      # the loop so that we move the last slice to front if it is a rect.
      variable(sl, last, prev)
      last := last child(sprite layer)
      sl := first child(sprite layer)
      while(sl && sl <> last) do, begin
        prev := sl
        sl := next sibling(sl)			    
        if(slice is rect(prev)) then(slice to front(prev))
      end
    end
    
    script, easier safe sorting, begin
      # If you need to sort slices in a loop, you might find it easier
      # to avoid the "slice to front" command and use "set sort order"
      # and "sort children" instead.
      variable(sl)
      sl := first child(sprite layer)
      while(sl) do, begin
        if(slice is rect(sl)) then, begin
          set sort order(sl, 1)
        end
        sl := next sibling(sl)
      end
      sort children(sprite layer)
    end
    

    slice to back (handle)

    Sort a slice handle so it will be drawn behind other slices with the same parent. If you use this command inside a loop, be careful not to accidentally create an endless loop. Moving a slice to the back also moves it to the first position of its parent's sibling list.

    script, simple example, begin
      # As long as you are not looping with the "next sibling" command
      # then "slice to back" is safe and easy to use.
      variable(sl)
      sl := load hero sprite(0)
      slice to back(sl)
    end
    
    script, dangerous sorting, begin
      # This is an example of the WRONG way to move all rect slices to the
      # back in a loop. Because moving a slice to the back moves it to the
      # top of the list, the loop will be restarted each time
      variable(sl)
      sl := first child(sprite layer)
      while(sl) do, begin
        if(slice is rect(sl)) then, begin
          slice to back(sl)
        end
        sl := next sibling(sl)
      end
    end
    
    script, safe but incorrect sorting, begin
      # This is an example of a safe way to move all the rect slices to the
      # back. HOWEVER the order in which all the rects will be drawn will
      # be reversed! That might be alright for your need.
      # By moving the slice AFTER using the "next sibling" command we avoid 
      # re-starting the loop.
      variable(sl, moveme)
      sl := first child(sprite layer)
      while(sl) do, begin
        moveme := 0
        if(slice is rect(sl)) then, begin
          moveme := sl
        end
        sl := next sibling(sl)
        if(moveme) then(slice to back(moveme))
      end
    end
    
    script, correct sorting, begin
      # This is an example of one right way to move all rect slices to the
      # back with a loop and preservw relative ordering between the rects.
      # Note that we ensure the rects stay in the same relative order by writing
      # the loop so that we also move the 'first' slice to back if it is a rect.
      variable(sl, first, prev)
      first := first child(sprite layer)
      sl := last child(sprite layer)
      while(sl && sl <> first) do, begin
        prev := sl
        sl := previous sibling(sl)			    
        if(slice is rect(prev)) then(slice to back(prev))
      end
    end
    
    script, easier safe sorting, begin
      # If you need to sort slices in a loop, you might find it easier
      # to avoid the "slice to back" command and use "set sort order"
      # and "sort children" instead.
      variable(sl)
      sl := first child(sprite layer)
      while(sl) do, begin
        if(slice is rect(sl)) then, begin
          set sort order(sl, -1)
        end
        sl := next sibling(sl)
      end
      sort children(sprite layer)
    end
    

    move slice above (handle, above what handle)

    Given a slice handle, move it so that it is the next sibling of another slice given by above what handle (changing its parent if necessary). This will cause it to be drawn immediately after that slice.

    move slice below (handle, below what handle)

    Given a slice handle, move it so that it is the previous sibling of another slice given by below what handle (changing its parent if necessary). This will cause it to be drawn immediately before that slice.


    Slices → Reordering Slices → Sorting Slices

    Y sort children (handle)

    Given a slice handle, sort all of its children according to their Y position. This means that sibling slices lower on the screen will be drawn over siblings higher on the screen.

    See also:

    set sort order (handle, order)

    Assign a sort order value to a slice handle. This can be any arbitrary number that will be used to sort the slice relative to its sibling slices the next time that sort children is called. Give a slice a low number to sort it to the back or a high number to sort it to the front. This means it functions like (or can be used as) a z-depth. If you give two sibling slices the same sort order number they will be sorted to the same depth, and they will remain in their original order in relation to one another.

    See also:

    get sort order (handle)

    Retrieve the sort order value previously set on a slice handle with get sort order. Note that calling sort children by default resets all the sort order values to zero, unless false is passed as wipe.

    sort children (handle, wipe)

    Given a slice handle, sort all of its children according to the sort order that you previously set with the set sort order command. If no sort order values have been set then no changes will be made to the order of the slices. wipe is an optional argument, defaulting to true, which specifies whether to zero out the sort order value for each slice after they have been sorted. This zeroing out behaviour is intended to let you use temporary sort values to perform some sorting operation on sibling slices (see especially the examples to slice to front and slice to back).

    plotscript, reverse Y sort, begin
      variable(sl)
      sl := first child(sprite layer)
      while(sl) then, begin
        set sort order(sl, slice y(sl) * -1)
        sl := next sibling(sl)
      end
      sort children(sprite layer)
    end
    

    get child autosort (handle)

    Get slice handle's "autosort children" setting, which is one of the following constants:

    Every tick immediately before the screen is redrawn the children of the slice will be sorted according to the autosort setting. This is useful for emulating 3D (or "2.5D") environments, causing slices for objects that are closer to the "view" (the bottom of the screen) to be drawn on top of ones further away.

    set child autosort (handle, setting)

    Change a slice handle's "autosort children" setting. setting should be one of the autosort: ... settings; see get child autosort.


    Slices → Slice Types

    For a description of the different slice types, see the Slices article on the wiki.

    [Notice] There are two types of slice used by the engine for which there are no commands: 'special' slices (such as spritelayer), and 'map' slices (which are map layers). However you can use lookup slice to find each instance of these. Special slices are nothing but container slices with special purposes (but not special behaviour). None of these kinds of slices can be created or manipulated in the slice collection editor either.


    Slices → Slice Types → Checking Slice Type

    slice type (handle)

    Returns the type of the given slice handle, one of the constants: slicetype:Special, slicetype:Container, slicetype:Rect, slicetype:Line, slicetype:Ellipse, slicetype:Sprite, slicetype:Text, slicetype:Map, slicetype:Grid, slicetype:Scroll, slicetype:Select, slicetype:Panel, slicetype:Layout.

    slice is container (handle)

    Returns true if the given slice handle is a container, or false for any other type. It's an error to provide an invalid handle.

    slice is sprite (handle)

    Returns true if the given slice handle is a sprite, or false for any other type. It's an error to provide an invalid handle.

    slice is rect (handle)

    Returns true if the given slice handle is a rect, or false for any other type. It's an error to provide an invalid handle.

    slice is line (handle)

    Returns true if the given slice handle is a line, or false for any other type. It's an error to provide an invalid handle.

    slice is ellipse (handle)

    Returns true if the given slice handle is a ellipse, or false for any other type. It's an error to provide an invalid handle.

    slice is text (handle)

    Returns true if the given slice handle is a text slice, or false for any other type. It's an error to provide an invalid handle.

    slice is grid (handle)

    Returns true if the given slice handle is a grid, or false for any other type. It's an error to provide an invalid handle.

    slice is select (handle)

    Returns true if the given slice handle is a select slice, or false for any other type. It's an error to provide an invalid handle.

    slice is scroll (handle)

    Returns true if the given slice handle is a scroll slice, or false for any other type. It's an error to provide an invalid handle.

    slice is panel (handle)

    Returns true if the given slice handle is a panel slice, or false for any other type. It's an error to provide an invalid handle.

    slice is map layer (handle)

    Returns true if the given slice handle is a map layer, or false for any other type. It's an error to provide an invalid handle.


    Slices → Slice Types → Container Slices

    create container (width, height)

    Create a new container slice and return a handle to it. Containers are invisible slices used only for grouping other slices. You can optionaly specify a width and height for the container.

    variable(holder, sl)
    holder := create container(200,100)
    sl := load hero sprite(0)
    set parent(sl, holder)
    set horiz align(sl, edge:left)
    sl := load hero sprite(1)
    set parent(sl, holder)
    set horiz align(sl, edge:right)
    
    The example above creates a container and then puts two hero sprites inside it, one aligned left and one aligned right. If you move or resize the container, the sprites inside it will also be moved.

    slice is container (handle)

    Documented in the Checking Slice Type section.


    Slices → Slice Types → Sprite Slices

    Unlike the other types of slices, sprite slices come in different subtypes for each of the different sprite sizes. A sprite slice of one subtype can be turned into another subtype with the replace*sprite commands.

    slice is sprite (handle)

    Documented in the Checking Slice Type section.

    load sprite (sprite type, num, palette)

    Creates a sprite slice by loading a sprite of the given sprite type (use a constant like spritetype:walkabout; see get sprite type for more), with sprite set number num and with given palette. Returns a handle for the slice. You may omit palette, in which case the default palette for that sprite will be loaded. palette is ignored for spritetype:backdrop. You must free it with free sprite when you are done.

    create sprite

    An alias for load sprite.

    replace sprite (slice, sprite type, num, palette)

    Change an existing sprite slice into a different sprite, loading a sprite of the given sprite type (use a constant like spritetype:walkabout; see get sprite type for more), with sprite set number num and with given palette. You may omit palette, in which case the default palette for that sprite will be loaded. palette is ignored for spritetype:backdrop. The handle for the slice doesn't change, and everything except the size of the slice stays the same. You must free it with free sprite when you are done.

    load hero sprite (num, palette)

    Loads hero battle sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace hero sprite!

    replace hero sprite (handle, num, palette)

    Given an existing sprite handle, changes it to hero battle sprite #num with palette palette. As with load hero sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load hero sprite.

    load walkabout sprite (num, palette)

    Loads walkabout sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace walkabout sprite!

    replace walkabout sprite (handle, num, palette)

    Given an existing sprite handle, changes it to walkabout sprite #num with palette palette. As with load walkabout sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load walkabout sprite.

    load small enemy sprite (num, palette)

    Loads small enemy sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace small enemy sprite!

    replace small enemy sprite (handle, num, palette)

    Given an existing sprite handle, changes it to small enemy sprite #num with palette palette. As with load small enemy sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load small enemy sprite.

    load medium enemy sprite (num, palette)

    Loads medium enemy sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace medium enemy sprite!

    replace medium enemy sprite (handle, num, palette)

    Given an existing sprite handle, changes it to medium enemy sprite #num with palette palette. As with load medium enemy sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load medium enemy sprite.

    load large enemy sprite (num, palette)

    Loads large enemy sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace large enemy sprite!

    replace large enemy sprite (handle, num, palette)

    Given an existing sprite handle, changes it to large enemy sprite #num with palette palette. As with load large enemy sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load large enemy sprite.

    load attack sprite (num, palette)

    Loads attack battle sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace attack sprite!

    replace attack sprite (handle, num, palette)

    Given an existing sprite handle, changes it to attack battle sprite #num with palette palette. As with load attack sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load attack sprite.

    load weapon sprite (num, palette)

    Loads weapon battle sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace weapon sprite!

    replace weapon sprite (handle, num, palette)

    Given an existing sprite handle, changes it to weapon battle sprite #num with palette palette. As with load weapon sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load weapon sprite.

    load border sprite (num, palette)

    Loads border battle sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace border sprite!

    replace border sprite (handle, num, palette)

    Given an existing sprite handle, changes it to border battle sprite #num with palette palette. As with load border sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load border sprite.

    load portrait sprite (num, palette)

    Loads portrait battle sprite #num with palette palette, and returns a slice handle.. You may omit palette, in which case the default palette for that sprite will be loaded. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace portrait sprite!

    replace portrait sprite (handle, num, palette)

    Given an existing sprite handle, changes it to portrait battle sprite #num with palette palette. As with load portrait sprite, you may omit palette, in which case the default palette for that sprite will be loaded. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load portrait sprite.

    load backdrop sprite (num)

    Loads backdrop #num as a sprite, and returns a slice handle.. You must free it with free sprite when you are done.

    [Warning]If you want to replace an existing sprite (or other slice) either use free sprite first, or use replace backdrop sprite!

    replace backdrop sprite (handle, num)

    Given an existing sprite handle, changes it to backdrop #num. You must free it with free sprite when you are done. This function is used when you merely wish to change the image, but not move it or anything. You must free it with free sprite when you are done.

    [Notice]You may use this on any sprite, not just ones loaded with load backdrop sprite.

    free sprite (handle)

    Deletes a sprite slice (e.g. created by load ... sprite commands). Identical to free slice except it shows an error when used on a non-sprite, for additional error checking. This removes the sprite from the screen, and deletes any children it has. It is a good idea to free sprites when you are completely done with them.

    [Notice] You can't delete a protected slice, which includes most slices created by the engine such as NPC and hero sprites.
    See also:

    clone sprite (handle)

    Duplicates a sprite slice, returning a handle to it. The new sprite inherits only the sprite-related data; in all other ways it is like a freshly created new slice. For example, the parent of the new slice is spritelayer and it starts out visible, with default anchoring, is at position 0,0, has no children, etc.. If you clone a sprite, remember that you will need to call free sprite on both the original and the clone.

    [Notice] If you want to copy a non-sprite slice, copy all the properties of the slice, or copy its children, then use the clone slice command instead.

    put sprite (handle, x, y)

    Moves sprite handle to position (x, y). This can only be used on sprites, use put slice in general.

    place sprite

    An alias for put sprite.

    get sprite type (handle)

    Gets the type of sprite slice handle, or returns -1 if the slice is not a sprite. You can compare the result with the following constants:

    set sprite set number (handle, record)

    Changes the record number of the spriteset of a sprite slice handle.

    get sprite set number (handle)

    Gets the record number of the spriteset of a sprite slice handle.

    set sprite palette (handle, num)

    Changes the palette of sprite slice handle to be num. If num is -1 or omitted, the default palette for that sprite is loaded.

    get sprite palette (handle)

    Returns the palette of sprite slice handle, or returns -1 if the sprite is set to use the default palette (use get sprite default pal to figure which that is).

    get sprite default pal (handle)

    Returns the default palette of sprite slice handle. You don't need to use this when you want to set a sprite to its default palette, because setting the palette number to -1 will have that effect. This command is for finding out the real palette number that would be used if the palette is set to -1.

    set sprite frame (handle, num)

    Changes the frame of sprite slice handle to be num.

    See also:

    get sprite frame (handle)

    Returns the current frame number of sprite slice handle.

    sprite frame count (handle)

    Returns the total number of available frames for a given sprite slice handle. For example a backdrop has just one frame, an attack sprite has three.

    horiz flip sprite (handle, flip)

    Flips a sprite slice handle horizontally. You can also unflip a previously flipped sprite using horiz flip sprite(handle, false)

    vert flip sprite (handle, flip)

    Flips a sprite slice handle vertically. You can also unflip a previously flipped sprite using vert flip sprite(handle, false)

    sprite is horiz flipped (handle)

    Returns true if a sprite slice handle is flipped horizontally, or false if it is not.

    sprite is vert flipped (handle)

    Returns true if a sprite slice handle is flipped vertically, or false if it is not.

    get sprite trans (handle)

    Given a sprite slice handle, returns true if the sprite is drawn with transparency (that is, color 0 is transparent). All sprites default to transparent.

    See also:

    set sprite trans (handle, drawtransparent)

    Given a sprite slice handle, sets whether it should be drawn with transparency (that is, color 0 is transparent). All sprites default to transparent, so you are unlikely to have any use for this command.

    See also:

    dissolve sprite (handle, dissolve type, total ticks, start tick, backwards, automatic)

    Dissolve a sprite using pre-defined dissolve animations. The first argument is a sprite slice handle. The second argument is the dissolve type. There are dissolve:name constants with the same names as the enemy dissolve animations.
    The valid dissolve type constants are: dissolve:random scatter, dissolve:crossfade, dissolve:diagonal vanish, dissolve:sink into ground, dissolve:squash, dissolve:melt, dissolve:vaporize (or dissolve:vaporise), dissolve:phase out, dissolve:squeeze, dissolve:shrink, dissolve:flicker. dissolve:shrink to center, dissolve:fade, dissolve:ghostly fade, dissolve:fade to white, dissolve:puff, dissolve:fade up, dissolve:blip.
    The third argument is the total number of ticks that the animation should run. You can use dissolvetime:default or -1 for the default number of ticks, which is equal to the sprites (width + height) / 10 (this is not the same as the default length for enemy dissolves!) The fourth argument is the tick to start on, or 0 to start from the beginning. The fifth argument is false for a normal dissolve, or true for a backwards dissolve. The sixth argument is true for an automatic dissolve (the default), or false to prevent the dissolve animation from proceeding automatically, in case you want to manually control it.

    cancel dissolve (handle)

    If a sprite slice handle is currently dissolving, cancel the dissolve animation, restoring the sprite to normal.

    sprite is dissolving (handle)

    Returns true if a sprite slice handle is currently dissolving, or false if it is not. Checks for both automatically dissolving sprites, and sprites that have been manually set to a partially dissolved state.

    wait for dissolve (handle)

    Pauses the current script until the sprite slice handle has finished dissolving. This command only waits if the dissolve is automatic. This command will not wait for sprites that have been manually set to a partially dissolved state.


    Slices → Slice Types → Rect Slices

    create rect (width, height, style)

    Create a new rectangle slice and return a handle to it. You can provide an optional width and height, and an optional style. The style is text box style number from 0 to 14, or -1 for an unstyled box. The default is box style 0. Like all slice types, a rect slice can be used as a container for other slices with set parent

    slice is rect (handle)

    Documented in the Checking Slice Type section.

    get rect style (handle)

    Given a rect slice handle, return the style it is using. This will be a number from 0 to 14 representing a text box style, or -1 if the rect is not using a standard style. Using any of the set rect fgcol, set rect bgcol, set rect border or set rect raw border commands causes this command to return -1.

    See also:

    set rect style (handle, style)

    Given a rect slice handle, change the box style it uses. The style should be a number from 0 to 14 representing a box style (edited in the "Edit Box Styles" menu). Setting the style changes the foreground (box) and background (edge) colors and the border.

    get rect bgcol (handle)

    Given a rect slice handle, return the background color it is using, which is the color inside the box (unless the box is totally transparent!) This will be a number from 0 to 255 representing a color from the master palette.

    set rect bgcol (handle, color)

    Given a rect slice handle, change the background color it uses, which is the color of the box. The color should be a number from 0 to 255 representing a color from the master palette.

    get rect fgcol (handle)

    Given a rect slice handle, return the foreground color it uses for its simple border. This only matters when the rect has no graphical border, or when the graphical border allows the simple border to show through. This will be a number from 0 to 255 representing a color from the master palette.

    set rect fgcol (handle, color)

    Given a rect slice handle, change the foreground color it uses for its simple border. This only matters when the rect has no graphical border, or when the graphical border allows the simple border to show through. The color should be a number from 0 to 255 representing a color from the master palette.

    get rect border (handle)

    Given a rect slice handle, return the style number of the graphical border it uses. This will be a number from 0 to 14 representing a text box border style, or border:line for a simple line border only, or border:none for no border at all, or border:raw if the box uses a "raw" box border spriteset number instead (in that case you need to call get rect raw border to find out which it is).

    get rect raw border (handle)

    Given a rect slice handle, return the spriteset ID number of the graphical border it uses, or border:line if it has a simple line border only, or border:none for no border at all. If the border is being determined by a box style number (e.g. due to set rect style or set rect border), then this command returns the actual box border spriteset instead of the box style number.

    set rect border (handle, border)

    Given a rect slice handle, change the graphical border it uses. The border should be a box style number from 0 to 14 representing a text box border style, or border:line for a simple line border only, or border:none for no border at all. (You can't use border:raw.) This command overrides both set rect style and set rect raw border.

    [Notice] border is not a box border spriteset number, it's a box style number! If you want to specify the box border spriteset directly, use set rect raw border.

    set rect raw border (handle, border)

    Given a rect slice handle, change the graphical border it uses. The border should be a border spriteset number (not a box style number), or border:line for a simple line border only, or border:none for no border at all. (You can't use border:raw.) This command overrides both set rect style and set rect border.

    get rect trans (handle)

    Given a rect slice handle, returns a constant like trans:fuzzy telling the background drawing mode; see set rect trans for the different constants. Returns trans:hollow if the rect's opacity/fuzziness is 0, and trans:solid (equal to false) if it's 100.

    set rect trans (handle, transparency setting)

    Given a rect slice handle, change how its background (the part that's not the border) is drawn. For transparency setting, pass in one of the constants:

    When changing to trans:fuzzy and trans:blend the fuzziness/opacity defaults to 50% if it hasn't been previously set. Otherwise the previous value is restored:
    set rect opacity(rect, 70)   # Becomes 70% opaque
    set rect trans(rect, trans:solid)  # Becomes opaque
    set rect trans(rect, trans:fuzzy)  # Becomes fuzzy with 70% fuzziness
    [Notice] This command is less powerful than set rect fuzziness and set rect opacity, which together can change to any of the four trans: types, and also control the amount of transparency.

    get rect fuzziness (handle)

    Alias:

    get rect opacity (handle)

    Given a rect slice handle, returns the percentage fuzziness or opacity of the slice, from 0 to 100: 0 if the rectangle is hollow, 100 if it is opaque, and a value between 1 and 99 if it is 'fuzzy' or 'blended (transparent)' (which share the same opacity value). Rectangles set to trans:fuzzy or trans:blend using set rect trans default to 50% opacity.

    set rect fuzziness (handle, percent)

    Makes a rect slice handle 'fuzzy', and optionally sets the percent fuzziness/opacity (defaults to 50). A percent of 0 is equivalent to set rect trans(handle, trans:hollow), a percent of 100 is equivalent to set rect trans(handle, trans:opaque), and anything in between 1 and 99 implicitly does set rect trans(handle, trans:fuzzy) as well as setting the percentage.

    get rect fuzzy zoom (handle)

    Given a rect slice handle returns the zoom amount for its fuzzy background, if it has one. See set rect fuzzy zoom. The zoom is a value 1 or higher.

    set rect fuzzy zoom (handle, zoom)

    Sets the zoom amount for the fuzzy background of a rect slice handle which has had its background set to trans:fuzzy using e.g. set rect trans. If the rectangle doesn't have a fuzzy background then this setting has no effect. zoom must be 1 or higher, measuring the size of each 'block' in the fuzzy pattern in pixels.

    get rect stationary pattern (handle)

    Given a rect slice handle returns true or false, telling whether its fuzzy background pattern (if it has one) is set to be 'stationary'. See set rect stationary pattern.

    set rect stationary pattern (handle, value)

    Set whether a rect slice handle with a fuzzy background pattern is 'stationary', meaning that as you move the slice around the pattern doesn't shift. This is especially useful when two fuzzy rects overlap. value should be true or false. If the rectangle doesn't have a fuzzy background then this setting has no effect.

    set rect opacity (handle, percent)

    Makes a rect slice handle (truly) transparent, and optionally sets the percent opacity (defaults to 50). A percent of 0 is equivalent to set rect trans(handle, trans:hollow), a percent of 100 is equivalent to set rect trans(handle, trans:opaque), and anything in between 1 and 99 implicitly does set rect trans(handle, trans:blend) as well as setting the percentage.


    Slices → Slice Types → Line Slices

    Line slices are slighty different; their size doesn't exactly define the size of the rectangular part of the screen which they stretch across, but is instead used as the offset between their ends. Both ends are drawn inclusively. For example a width 10 height 0 Line slice positioned at x=50,y=20 will draw a line from 50,20 to 60,20, as a rectangle that's actually 11 pixels long and 1 pixel high. The line thickness is always 1 pixel. A width=0 height=0 line slice is a single pixel.
    So you can give line slices a negative width or height too, to draw a line at any angle. The "top-left" alignment point of a line slice is its start point, and the "bottom-right" is its end point.

    create line (width, height, color)

    Create a new line slice and return a handle to it. You can provide an optional width and height and an optional color (all default to 0). Like all slice types, an line slice can be used as a container for other slices with set parent.

    slice is line (handle)

    Documented in the Checking Slice Type section.

    get line color (handle)

    Given an line slice handle, return its color. This will be a number from 0 to 255 representing a color from the master palette, or less than 0 for a UI color.

    See also:

    set line color (handle, color)

    Given an line slice handle, change its color. The color should be a number from 0 to 255 representing a color from the master palette.

    See also:


    Slices → Slice Types → Ellipse Slices

    create ellipse (width, height, border color, fill color)

    Create a new ellipse slice and return a handle to it. You can provide an optional width and height, an optional border color and an optional fill color. The ellipse will be hollow if you do not specify a fill color. Like all slice types, an ellipse slice can be used as a container for other slices with set parent

    slice is ellipse (handle)

    Documented in the Checking Slice Type section.

    get ellipse border col (handle)

    Given an ellipse slice handle, return the color it uses for its border. This will be a number from 1 to 255 representing a color from the master palette, or 0 meaning transparent.

    set ellipse border col (handle, color)

    Given an ellipse slice handle, change the color it uses for its border. The color should be a number from 1 to 255 representing a color from the master palette. color 0 means 'transparent', which is not very useful.

    get ellipse fill col (handle)

    Given an ellipse slice handle, return the color it uses for its fill. This will be a number from 1 to 255 representing a color from the master palette, or 0 meaning transparent fill (hollow).

    set ellipse fill col (handle, color)

    Given an ellipse slice handle, change the color it uses for its fill. The color should be a number from 1 to 255 representing a color from the master palette, or 0 meaning transparent fill (hollow).


    Slices → Slice Types → Text Slices

    create text

    Creates a new blank text slice and returns a slice handle to it. A text slice holds a string of text, but it can be positioned and handled just like any other slice. Use the set slice text command to copy a string into the text slice.

    See also:

    slice is text (handle)

    Documented in the Checking Slice Type section.

    set slice text(handle, string id)

    Copy a string specified by string id into the text slice specified by handle. Afterwards, there is no link between the text slice and the string; they have different contents.

    get slice text(string id, slice handle)

    Copy the contents of the text slice specified by slice handle into a string specified by string id. Afterwards, there is no link between the text slice and the string; they have different contents.

    expand strings in slices(handle, saveslot)

    Starting with the slice handle, search for all child slices, and if any of them are text slices, then expand any text codes such as ${H1} ${V2} or ${S5}. This does the same thing that textboxes do automatically. The saveslot argument is optional. If you leave it out, the codes will be expanded based on the currently running game state. If you specify a save slot number from 1-1000 then the string will be expanded based on hero names, variables, and strings in that save slot.

      variable (col)
      col := load slice collection(1)
      expand strings in slices(col)
    
    See also:

    get text color(handle)

    Given a text slice handle, returns the current color of the text.

    See also:

    set text color(handle, color)

    Given a text slice handle, change color used to display the text.

    See also:

    get text bg(handle)

    Given a text slice handle, returns the current background color of the text. Note that this only matters if the text slice is not displaying an outline.

    set text bg(handle, color)

    Given a text slice handle, change the background color used to display the text. This only matters if the text slice is set to not use an outline.

    get outline(handle)

    Given a text slice handle, true if the text slice is configured to display an outline, or false if it is configured not to display and outline.

    See also:

    set outline(handle, outline)

    Given a text slice handle, change whether or not it will be displayed with an outline. If the second argument is omitted or true, change the slice to show an outline, if the second argument is false change the slice to show no outline.

    See also:

    get wrap(handle)

    Given a text slice handle, true if the text slice is configured to wrap, or false if it is configured not to wrap.

    See also:

    set wrap(handle, wrap)

    Given a text slice handle, change whether or not it will wrap. If the second argument is omitted or true, change the slice to wrap-mode, if the second argument is false change the slice into non-wrapping mode.

    See also:


    Slices → Slice Types → Grid Slices

    create grid (width, height, rows, columns)

    Creates a new grid slice, and returns a slice handle to it. Grid slices are special containers that automatically arrange their children into rows and columns. No manual child positioning is required. The first two arguments are the width and height of the whole grid. The next two arguments are the number of rows and columns that should appear in the grid. If rows or columns are left out, the grid with be a boring 1x1 (a single large cell).

    [Notice] Beware that the order of the rows, columns args is reversed from what you might expect: they affect the height and width of each cell, not width and height.

    slice is grid (handle)

    Documented in the Checking Slice Type section.

    set grid columns (handle, columns)

    Changes the number of columns in a grid slice. Child slices will be automatically repositioned. 1 is the minimum number of columns. If you attempt to set columns to zero, nothing will happen.

    get grid columns (handle)

    Returns the number of columns in a grid slice.

    set grid rows (handle, rows)

    Changes the number of rows in a grid slice. Child slices will be automatically repositioned. 1 is the minimum number of rows. If you attempt to set the rows to 0, nothing will happen.

    get grid rows (handle)

    Returns the number of rows in a grid slice.

    show grid (handle, shown)

    Grid slices are normally invisible, but they can optionally display gridlines. This command takes a grid slice handle and a true or false value. This command has no effect on the visibility of the grid's children. Don't confuse this command with set slice visible.

    See also:

    grid is shown (handle)

    This command takes a grid slice handle and returns true if the grid is showing its optional grid lines. If the grid is in its normal invisible state, this command returns false. Don't confuse this command with get slice visible.

    See also:


    Slices → Slice Types → Select Slices

    create select (width, height)

    Creates a new select slice, and returns a slice handle to it. Select slices are special containers that automatically Manage the visibility of their children. Only one child of a select slice can ever be visible at the same time. The two arguments are the width and height of the select slice.

    slice is select (handle)

    Documented in the Checking Slice Type section.

    set select slice index (handle, index)

    Changes the currently selected (visible) child of a select slice. The first argument is the handle of the select slice. The second argument is the index number of the child slice (not a handle or a lookup code!) this will be 0 for the first child, 1 for the second child, 2 for the third child, and so-on. An invalid index number means no child slices will be visible at all.
    Use set selected child instead if you want to set the selected child by its slice handles instead of index.

    get select slice index (handle)

    Returns the index number of the currently selected (visible) child of a select slice. The first argument is the handle of the select slice. The return value the index number of the child slice (not a handle or a lookup code!) this will be 0 for the first child, 1 for the second child, 2 for the third child, and so-on.
    Use get selected child instead if you want a slice handle for the selected child instead of its index.

    set selected child (select, child)

    Given a select slice handle select and a slice handle for one of its children, child, selects that child.
    This is just a convenience wrapper around set select slice index.

    get selected child (handle)

    Given a select slice handle, returned the slice handle of the currently selected child. Returns false/0 if the selected index is out of range (including when slice has no children).
    This is just a convenience wrapper around get select slice index.


    Slices → Slice Types → Scroll Slices

    create scroll (width, height)

    Creates a new scroll slice, and returns a slice handle to it. Scroll slices are special containers that automatically draw a scrollbar on ther right and bottom edges if their children do not fit inside them. The two arguments are the width and height of the scroll slice.

    slice is scroll (handle)

    Documented in the Checking Slice Type section.

    set scroll bar style (handle, style)

    Changes the style of a scroll slice's scrollbar. The first argument is the handle of the scroll slice. The second argument is the style number. Scroll bar styles use the same colors as text box styles. The background color is used for the entire scrollbar, and the foreground color is used for the position indicator in the scrollbar.

    get scroll bar style (handle)

    Returns the current style number of a scroll slice's scrollbar. The first argument is the handle of the scroll slice. Scroll bar styles use the same numbering as text box styles.

    set scroll check depth (handle, depth)

    Changes the number of generations of descendents that a scroll slice cares about. The first argument is the slice handle of the scroll slice. The second argument is the desired depth, or 0 to check the entire slice subtree. For example, a depth of 1 means the scroll only considers children. 2 means it considers children+grandchildren. 3 means it considers children+grandchildren+greatgrandchildren.

    get scroll check depth (handle)

    Returns the number of generations of descendents that a scroll slice cares about, or 0 if it considers the slice subtree. The first argument is the slice handle of the scroll slice. For example, a return value of 1 means the scroll only considers children. 2 means it considers children+grandchildren. 3 means it considers children+grandchildren+greatgrandchildren.

    scroll to child

    An alias for scroll to slice.

    scroll to slice (parent, sl, apply padding)

    Causes all the children of the parent slice to be shifted by the same offset so the screen position of sl (which may be any descendent of parent) fits inside the parent.
    If apply padding is true (the default is false), then sl is scrolled within the area of parent with padding subtracted (the area covered by a child set to Fill Parent).

    [Notice] This is mainly intended for scroll slices, such as those created with the create scroll command, but it can be used on any type of slice. (Children that are set to fill their parents, or children that are automatically positioned by a grid parent will be unaffected, and an error or warning may be shown.)
    [Notice] This works for all descendent slices sl, not just children! It only changes the positions of the children of parent, but that causes the screen position of sl to also change.


    Slices → Slice Types → Panel Slices

    Panel slices split up their area between their first two children in various ways, and don't display any other children.

    create panel (width, height)

    Creates a new panel slice, and returns a slice handle to it. Panel slices are special containers that automatically move and resize their first two children. The first two children will fill the panel slice's area (while others aren't drawn). For example, a panel slice might be used to make to child slices share a 60%/40% split of an area regardless of the size or shape of that area. The two arguments are the width and height of the panel slice.

    slice is panel (handle)

    Documented in the Checking Slice Type section.

    get panel is vertical (handle)

    Returns true if the given panel slice handle is configured to orient its children vertically, or false if it orients them horizontally.

    set panel is vertical (handle, value)

    Changes how the given panel slice handle orients its children. If the value is true, they will be oriented vertically, or if false it will orient them horizontally.

    get panel primary index (handle)

    Returns 0 or 1 to indicate whether the first or second child of the given panel slice handle is the primary one. The primary child gets its size based on the panel slices's percentage and pixels, while the other child slice takes the remaining space.

    set panel primary index (handle, zero or one)

    Changes whether the first or second child of the given panel slice handle is the primary one. The primary child gets its size based on the panel slices's percentage and pixels, while the other child slice takes the remaining space.

    get panel percent as int (handle)

    Given a panel slice handle, returns an integer from 0 to 100 to indicate what percentage of the panel should be filled by the primary child slice

    set panel percent (handle, percent)

    Given a panel slice handle, changes the percentage of the panel that should be filled by the primary child slice. The panel's percentage size and pixel size will be added together to compute the actual size of the primary child.

    get panel pixels (handle)

    Given a panel slice handle, returns the number of pixels of space that the panel will reserve for its primary child

    set panel pixels (handle, pixels)

    Given a panel slice handle, changes the number of pixels of space that the panel will reserve for its primary child. The panel's percentage size and pixel size will be added together to compute the actual size of the primary child.

    get panel padding (handle)

    Given a panel slice handle, returns the number of pixels of padding that will be left between the primary and secondary children

    set panel padding (handle, padding)

    Given a panel slice handle, changes the number of pixels of padding that the panel will leave between the primary and secondary children.


    Slices → Slice Types → Map Layer Slices

    Map Layer slices (also called Map slices) are special slices which display one of the tilemap layers of the current map. You can't create them; they always exist. Use lookup slice to get a handle for one of the map layer slices. They don't have any special attributes that you can access (use the map script commands to modify the map instead), and you can't resize them or change their parent, but you can do anything else, such as move them about to create parallax effects, make them invisible, reorder them, change their autosort mode, and so forth.

    slice is map layer (handle)

    Documented in the Checking Slice Type section.


    Slices → Slice Collision Testing

    [Notice] For the purposes of collision testing, all slices are treated as solid rectangles, even if they are text slices, sprites, ellipses, lines or invisible. A point right on the boundary of this rectangle counts as a collision.

    slice collide point (handle, x, y)

    Return true if a given x and y coordinate point lies inside the bounding rectangle for slice handle's screen position. x and y are pixel coordinates relative to the screen, such as the ones returned by mouse pixel X and mouse pixel Y (but can also be off the screen).

    [Notice] Unlike slice at pixel, this command ignores slice clipping.
    See also:

    slice collide (handle1, handle2)

    Given a pair of slice handles, return true if their screen positions overlap with one another (even if one or both are off the edge of the screen or hidden or clipped by one of their ancestors). Parent/child relationships have nothing to do with this test; it doesn't matter whether the slices are related or what their children are.

    slice contains (handle1, handle2)

    Return true if the screen position of slice handle2 is completely inside slice handle1 (even if one or both are off the edge of the screen or hidden). Parent/child relationships have nothing to do with this test; it doesn't matter whether the slices are related or what their children are.

    See also:

    slice at pixel (parent, x, y, number, check descendants, visible only)

    Searches through all the descendants of parent for a slice containing the given x, y pixel screen position. To search all your slices, you can often use spritelayer as parent, since that is the default parent of new slices.
    number is an optional argument indicating which slice to return if there is more than one at that point; the bottom-most one (returned by default) is number 0, next up is 1, etc. Alternatively, -1 is the topmost one, -2 is the second from the top, etc. slice at pixel returns 0 if number is out of range (number < -count or larger than or equal to the number of overlapping slices). If you pass get count as number the number of slices at that pixel is returned instead of a slice handle.
    check descendants is an optional argument defaulting to true. If false, then only parent's children will be checked, not all its descendants.
    visible only is an optional argument defaulting to false. If true, then only visible slices are counted or returned. (That is, slices marked not-visible are ignored while searching for slices, but whether parent itself is visible doesn't have any effect.) For example, pass true for visibleonly in order to avoid finding the children of Select slices which are not selected (and therefore invisible).
    This command never returns Special slices, such as the spritelayer slice.

    [Notice] A point on the left or top edge of a slice counts as inside the slice, while one on the bottom or right edges counts as outside. If a slice has zero width or zero height, then there are no points inside it, and slice at pixel will never return it!
    [Notice] If a slice clips its children, then any parts of those children that are clipped off are ignored when looking for x, y. However, it doesn't matter whether parent or any of its ancestors are set to clip; it's assumed that they don't.
    You can also use this to speed up the search, since all the children of a clipping slice will be skipped if that slice itself doesn't contain x, y.

    find colliding slice (parent, slice, number, check descendants, visible only)

    Searches through all the descendants of parent for a slice colliding (intersecting) with the given slice (by screen position). (Children of slice are ignored.) To search all your slices, you can often use spritelayer as parent, since that is the default parent of new slices. number is an optional argument indicating which slice to return if there is more than one at that point; the bottom most one (returned by default) is number 0, next up is 1, etc. 0 is returned if number is too large (larger than or equal to the number of overlapping slices). If you pass get count as number the number of overlapping slices is returned instead. check descendants is an optional argument defaulting to true. If false, then only parent's children will be checked, not all its descendants. (That is, slices marked not-visible are ignored while searching for slices, but whether parent itself is visible doesn't have any effect.) Pass true for visibleonly in order to avoid finding the children of Select slices which are not selected (and therefore invisible). visibleonly defaults to false.
    This command never returns Special slices, such as the spritelayer slice, nor will it return slice or any of its descendants.

    [Notice] If a slice clips its children, then any parts of those children that are clipped off are ignored when checking collisions. However, it doesn't matter whether parent or any of its ancestors are set to clip; it's assumed that they don't.
    You can also use this to speed up the search, since all the children of a clipping slice will be skipped if that slice itself doesn't collide with slice.
    # Example for the player picking up fruit by moving onto them using normal
    # tile-based player movement, but you can use whatever 'player' slice you want)
    
    global variable (1, fruit container)
    global variable (2, collected fruits)  # Number picked up
    
    # Create 10 randomly placed fruit slices on the map
    plotscript, create fruit, begin
      # Where to put the fruit
      fruit container := lookup slice(sl:walkabout layer)
    
      variable (i, fruit)
      for (i, 1, 10) do (
        fruit := load walkabout sprite(42)   # Sprite set 42
        put slice(fruit, random(0, 500), random(0, 500))
        set parent(fruit, fruit container)
      )
    end
    
    # Call this from somewhere, such as an each-step script, or each tick from a loop, e.g.:
    #   "while(true) do(pickup fruit, wait(1))"
    plotscript, pickup fruit, begin
      variable (player, fruit)
      player := get hero slice(me)
      while (true) do (
         fruit := find colliding slice(fruit container, player)
         if (fruit == false) then (break)
         free slice (fruit)
         collected fruits += 1
       )
    end
    
    # If you need to skip some colliding slices (e.g. other NPCs), or don't immediately free them on
    # collision, use this version instead
    plotscript, pickup fruit, begin
      variable (player, fruit, index)
      player := get hero slice(me)
      while (true) do (
         fruit := find colliding slice(fruit container, player, index)
         if (fruit == false) then (break)
         # Example of rejecting certain slices as not fruit
         if (slice is sprite(fruit) == false || get sprite set number(fruit) <> 42) then (
           index += 1
           continue  #skip
         )
    
         free slice (fruit)
         collected fruits += 1
       )
    end
    

    move slice with wallchecking (sl, relative x, relative y, friction%)

    Documented in the Wall Checking section.

    check wall collision x (x, y, width, height, relative x, relative y, friction%)

    Documented in the Wall Checking section.


    Time Functions

    [Back to top-level index]

    days of play

    Returns the number of days that the game has been played

    set days of play (days)

    Sets the number of days that the game has been "played" to days, as long as days is greater than 0. Useful if there are times that shouldn't count towards the play time, or for penalizing bad players >:)

    hours of play

    Returns the number of hours that the game has been played, 0 to 23

    set hours of play (hours)

    Sets the number of hours that the game has been "played" to hours, as long as hours is within the 0-23 range.

    minutes of play

    Returns the number of minutes that the game has been played, 0 to 59

    set minutes of play (min)

    Sets the number of minutes that the game has been "played" to min, as long as min is within the 0-59 range.

    seconds of play

    Returns the number of seconds that the game has been played, 0 to 59

    set seconds of play (sec)

    Sets the number of seconds that the game has been "played" to sec, as long as sec is within the 0-59 range.

    system year

    Returns the current real-world year

    system month

    Returns the current real-world month, 1 to 12

    system day

    Returns the current real-world day, 1 to 31

    system hour

    Returns the current real-world hour, 0 to 23

    system minute

    Returns the current real-world minute, 0 to 59

    system second

    Returns the current real-world second, 0 to 59

    milliseconds

    Documented in the Advanced Functions section.

    microseconds

    Documented in the Advanced Functions section.

    override tick milliseconds (ms)

    Changes the number of milliseconds in a game tick. The ms argument is a number of milliseconds in the range of 16 to 200

    cancel override tick milliseconds (ms)

    Resets the number of milliseconds in a game tick to whatever default is set up in the "Edit General Game Settings" menu.


    Tweaking Maps

    [Back to top-level index]

    current map

    Returns the number (ID) of the current map.

    max map id

    Returns the number (ID) of the highest numbered map that exists in the game.

    map width (map)

    Returns the width of a map in tiles. map, the map ID, is optional; the width of the current map is returned if it is not specified.

    map height (map)

    Returns the height of a map in tiles. map, the map ID, is optional; the height of the current map is returned if it is not specified.

    get map tileset

    Returns the ID number of the default tileset for the map. load tileset does not affect the value returned by this function, but change tileset does. Use layer tileset instead to find the actual currently in-use tileset(s).

    layer tileset (layer)

    Returns the ID number of the tileset that a certain tilemap layer is currently using.

    load tileset (tileset, layer)

    Temporarily loads a different default or layer tileset for the currently displaying map.
    Use load tileset (with no arguments) to restore the old tilesets after using load tileset (this has no effect after change tileset).
    Use load tileset (tileset) to load a new default tileset. tileset is the ID number of the tileset to load. This changes the tileset for all layers that are set to 'Tileset: default'.
    Use load tileset (tileset, layer) to load in a new a tileset for a single layer. layer is the layer number to target.

    [Notice] This command has a temporary effect: even if the map state is saved, the new tilesets will not persist if you leave the map and come back. change tileset is a more permanent alternative command.

    change tileset (tileset, layer)

    An alternative to load tileset: Changes and loads in the default or a map layer tileset for the current map. Unlike load tileset, this command's effects last to the next time you come back to this map if you save the map state (in General Map Settings, or mapstate:mapsettings with save map state). To undo the effects, you'll need to use reset map state. tileset is the ID number of the tileset to load. You can use the constant tileset:default to set a layer to use the map's default tileset. layer is the layer number to change, or the constant tileset:default which changes the map's default tileset. It defaults to tileset:default if omitted. change tileset with no arguments undoes any changes to tilesets made using load tileset (not change tileset).

    [Warning] Any call to change tileset undoes all changes (to all map layers) made by load tileset.

    last layer id

    Returns the ID number of the last map layer that exists on the current map. This is the topmost layer that is drawn on top of all the other layers.

    layer id under walkabouts

    Returns the ID number of the map layer directly beneath the layer where hero and NPC walkabouts are drawn. This is the topmost layer that is not drawn on top of walkabouts.


    Tweaking Maps → Tilemap, Wallmap and Foemap

    read map block (x, y, layer)

    Returns the value of a map tile on the current map at the specified X,Y position. Normal map tiles return values from 0-159, animating maptiles from set 1 return 160-207 and animating maptiles from set 2 return 208-255. The optional layer argument defaults to 0 for the bottom layer, but can be any layer number that is valid for the current map.

    write map block (x, y, value, layer)

    Writes a new tile to the specified X,Y position on the current map. This change will only persist until you leave the map or fight a battle. The optional layer argument defaults to 0 for the bottom layer, but can be any layer number that is valid for the current map.

    read wall bit (x, y, bit)

    Check the value of a single bit of one tile of the wallmap of the current map. Returns true or false.
    x, y is the position in tiles.
    bit can be north wall, east wall, south wall, or west wall to check of the four possible walls on the tile, or vehicle A, vehicle B, harm tile or overhead tile to check one of the other bits.
    See read pass block for an example.

    See also:

    write wall bit (x, y, bit, value)

    Set the value of a single bit of one tile of the wallmap of the current map.
    x, y is the position in tiles.
    bit can be north wall, east wall, south wall, or west wall to set the presense of the four possible walls on the tile, or vehicle A, vehicle B, harm tile or overhead tile.
    value is optional should be either false or true (or any other non-zero value). The default is true.

    See also:

    read pass block (x, y)

    Returns the value of a passability (wallmap) tile on the current map at the specified x, y position. The return value will be from 0 to 255 and consists of eight flag bits.

    bit 1 = north wall
    bit 2 = east wall
    bit 4 = south wall
    bit 8 = west wall
    bit 16 = vehicle A
    bit 32 = vehicle B
    bit 64 = harm tile
    bit 128 = overhead tile

    To check the value of a specific bit, use the and operator as in the following example, or just use the read wall bit command instead.

      variable (pass)
      pass := read pass block(hero X(me), hero Y(me))
      if (pass, and, harm tile) then (
        # The hero is standing on a harm tile
      )
    
      # The following is equivalent:
      if (read wall bit(hero X(me), hero Y(me), harm tile)) then (
        # The hero is standing on a harm tile
      )
    

    write pass block (x,y,value)

    Writes a new passability (wallmap) information to the specified x, y position on the current map. This change will only persist until you leave the map or fight a battle. The value is a number from from 0 to 255 that consists of eight flag bits.

    bit 1 = north wall
    bit 2 = east wall
    bit 4 = south wall
    bit 8 = west wall
    bit 16 = vehicle A
    bit 32 = vehicle B
    bit 64 = harm tile
    bit 128 = overhead tile

    You can add the constants together (but it might be easier to use write wall bit instead). For example:

    variable (pass)
    pass := northwall+southwall+eastwall+westwall
    write pass block(15,3,pass)
    # this makes the fifteenth tile in the third column
    # impassable on all directions
    
    write pass block(15,3,none)
    # Use 0 or none to remove walls from a tile
    See also:

    read foemap (x, y)

    Reads and returns a formation set number (which is a value 0-255) from the foemap at tile position x,y. The foemap is used to trigger random battles. 0 means no formation set at that position.


    Tweaking Maps → Tilemap, Wallmap and Foemap → Tile Animations

    current display tile (tile number, layer)

    Returns the tile number from the tileset, in the range 0-159, that a given tile (read with read map block, which returns a value greater than 159 for animated tiles) is currently displayed as, taking the tile animation patterns into account. Because different layers can have different tilesets, you might need to specify the layer the tile is from; otherwise layer 0 is assumed.

    animation start tile (tile number, layer)

    Returns the tile number on the tileset (in the range 0-159) that this tile is displayed as at the start of its animation pattern (offset 0) if it is animated, else just returns the tile number. The tile number argument is typically returned from read map block. In effect, the result is what the tile number would be if you had not set the tile as animated in the tilemap editor. Because different layers can have different tilesets, you might need to specify the layer the tile is from; otherwise layer 0 is assumed.

    get tile animation offset (animation pattern, layer)

    Returns the offset from the starting tile that the animation pattern (either 0 or 1) of the tileset in use by the layer (0 to 2) is currently at. For example, if the pattern has stepped 1 to the right, the offset is 1, if it has moved down 2 and 1 to the left, it is 31 (2 * 16 - 1). Because different layers can have different tilesets, you might need to specify the layer with the tileset to examine; otherwise layer 0 is assumed.

    [Notice]Layers that use the same tileset do NOT have different copies of the tileset. Layers with the same tileset will always have the same tile animation offsets.

    set tile animation offset (animation pattern, offset, layer)

    Sets the offset from the starting tile that an animation pattern (either 0 or 1) of a tileset in use by a layer (0 to 2) is currently at. If there is a pattern defined, it will continue to step left, right, up and down from the offset you give it, until the end of the animation is reached, when the offset is reset to 0. Because different layers can have different tilesets, you might need to specify the layer with the tileset to examine; otherwise layer 0 is assumed.

    [Notice]Layers that use the same tileset do NOT have different copies of the tileset. Layers with the same tileset will always have the same tile animation offsets, you can not change them independently.


    Tweaking Maps → Tilemap, Wallmap and Foemap → Wall Checking

    read pass block (x, y)

    Documented in the Tilemap, Wallmap and Foemap section.

    check hero wall (who,direction)

    Documented in the Moving Heroes section.

    check NPC wall (who, direction)

    Documented in the Moving and Positioning NPCs section.

    check wall collision x (x, y, width, height, relative x, relative y, friction%)

    check wall collision y (x, y, width, height, relative x, relative y, friction%)

    Check how far an object (with a rectangular "hitbox") could move in a straight line on the map before hitting a wall (and possibly sliding along that wall). Provide the starting x and y map position in pixels of the top left corner of the hitbox (relative to the top-left of the map), its width and height in pixels, and the relative x/y offset of the target position of the object (for example relative x is 20 for one tile to the right). See move slice with wallchecking for information about what the optional friction% argument (which defaults to 100) does.
    The return value is the maximum x or y offset (for check wall collision x or y respectively) that the object could move in a straight line towards the target before hitting a wall. If there are no walls in the way, then the return value is relative x or relative y.
    For example, to check whether the hero can walk a full tile north (-20 pixels in the 'y' direction), you could write

    if (check wall collision y(hero pixel x(me), hero pixel y(me), 20, 20, 0, -20) == -20) then (...)
    (The check hero wall command is a much easier way to check the same thing, but only works if the hero is tile-aligned.)
    These commands work on hitboxes of any size (as long as the size isn't negative), even several tiles wide. Even a one-pixel-wide overlap with the end of a wall counts as a collision, and edge-on walls count as obstructions too, as do tiles past the edge of the map (unless the map wraps around). However, if the hitbox starting position already overlaps any walls they will be ignored.
    [Notice] move slice with wallchecking is a more convenient way to check walls if you want to move a slice, e.g. when scripting a platformer.
    [Notice] If you're moving diagonally, you'll need to call both check wall collision x and check wall collision y with identical arguments to find the x,y position of the collision point.
    [Danger] This command hasn't been updated to support one-way walls yet. Running into a one-way wall edge-on will give strange results.

    move slice with wallchecking (sl, relative x, relative y, friction%)

    Instantly moves a slice sl as far as possible in a straight line towards a point until it hits a wall in the map's wallmap (and possibly slides along that wall). relative x/y provide the point to move to, relative to the slice's current position. This command can be used on any slice, regardless of whether it is parented to a map layer. Its position on the map is calculated based on its on-screen position (slice screen x, etc). The slice's "colliding box" (or "hitbox") is, as you expect, the same as its size.
    It works on slices of any size (as long as the size isn't negative), even several tiles wide. Even a one-pixel-wide collision with the end of a wall will stop the slice, and edge-on walls count as obstructions too, as do tiles past the edge of the map (unless the map wraps around). However, if the slice already overlaps any walls they will be ignored.
    friction% is an optional percentage value from 0 to 100 which defaults to 100. When it's 100, movement stops as soon as a wall is hit. If it's less than 100 then the slice slides down the wall with part of its remaining movement (relative x/y), reduced by friction% percent. For example if relative x == 15, relative y == 3, friction% == 30 and the slice travelled right 5 pixels before hitting a wall to the north (x = 10, y = 2 movement remaining to go), then y movement gets set to 0 (because we hit a wall to the north) and x movement gets reduced by 30% to 7, and the slice slides up to another 7 pixels to the right (unless it hits another wall).
    If you're creating a platformer or zelda-like, you probably want friction to be 0% or a low value.
    The return value is a bitmask giving the directions in which the slice was blocked by a wall. The value is 0 if there was no collision. You can use the constants north wall, south wall, east wall, west wall and the bitwise-and operator to 'test' the bitmask. For example bitmask, and, southwall 'tests' whether sl hit and is now resting against a wall on its south side (useful for a platformer).
    Diagonally hitting the corner or end of a wall exactly (including thin wall segments) is a special case. In that case the slice stops at the corner/end of the wall but is only touching it diagonally, and the return value is equal to one of the special constants northeast corner, northwest corner, southeast corner, southwest corner, all of which 'test' false when checked with north wall, south wall, east wall, west wall. That's because the slice isn't actually resting against any walls, although it stopped! Use ==, not and, to check for these values.
    You can check for walls without needing a slice using the alternative check wall collision x/y commands.

    [Danger] This command hasn't been updated to support one-way walls yet. Running into a one-way wall edge-on will give strange results.
    # This script creates a rectangle slice which follows the mouse
    # but doesn't pass through walls.
    plotscript, box follows mouse, begin
      variable (xgo, ygo, box)
      box := create rect(14, 14)
      set rect border(box, border:line)
    
      while(true) do (
        # Calculate the offset from the center of the box to the mouse,
        # and divide by three to move a third of the way there.
        xgo := (mouse pixel x -- (slice screen x(box) + 7)) / 3
        ygo := (mouse pixel y -- (slice screen y(box) + 7)) / 3
        move slice with wallchecking(box, xgo, ygo)
        wait
      )
    end


    Tweaking Maps → Zonemaps

    [Notice] All zone commands accept zone handles (returned by get zone) in place of zone IDs.

    write zone (zone id, x, y, value)

    Sets whether the tile at (x,y) is part of the specified zone. zone id is a valid ID number (see read zone) or zone handle, and value is interpreted as either true (non-zero) or false (zero).

    [Notice] Only up to 15 zones may overlap at each tile. If you try to place 16 zones at one tile, write zone will fail, returning false. Normally it returns true. If you choose to "Show all warnings" in General Game Settings in Custom, you will also get a warning message.
    [Notice] Changes to zones are not stored in saved games, and are erased when you leave the map unless "Tile Data State" is "saved when leaving" (in the General Map Data settings).
    See also:

    read zone (zone id, x, y)

    Returns true if the tile at (x,y) is part of the specified zone. The zone id is an ID number from 1 to 9999 for zones defined in the map editor, or a zone handle, or can be the ID one of these special zones:

    zone at spot (x, y, count)

    Used to get the set of all IDs of zones that contain the tile at (x,y). Since zones may overlap, count is used to specify which zone ID to return: 0 is the first, 1 the second, and so on. count may also be the constant get count, in which case the total number of zones which overlap there is returned. If count too large (greater than or equal to the number of zones), 0 (false) is returned.

    [Notice] The order in which the ID numbers are returned is completely arbitrary. Also note this returns IDs, not zone handles.
    See also:

    get zone name (string id, zone id)

    Places in the string with id number string id the name of zone zone id.

    get zone extra (zone id, extra num)

    Returns the value in one of a zone's "extra data" fields, which you can set in the Zone Info editor. extra num is an extra array index.
    This command is the same as get extra but only works on zones, and accepts zone IDs as well as zone handles.

    set zone extra (zone id, extra num, value)

    Sets the value of one of a zone's "extra data" fields. extra num is an extra array index.
    Extra data has no builtin meaning or effect, so you're free to use it for whatever you want.
    This command is the same as set extra but only works on zones, and accepts zone IDs as well as zone handles. See append extra and resize extra for more ways to modify zone extra data.

    [Notice] Changes to zones are not stored in saved games, and are erased when you leave the map unless "Tile Data State" is saved when leaving in the General Map Data settings.

    zone number of tiles (zone id)

    Given a zone id (from 1 to 9999 or a special id) or zone handle, returns the number of tiles that the zone contains.

    get zone (zone id)

    Given a zone id (from 1 to 9999 or a special ID), returns a "zone handle", which is a value that can be passed to any of the Extra Data Array Functions to access the zone's extra data. It can also be used in place of the zone ID in any zone command, but it does nothing useful in that case. For example, you can also pass a zone handle to this command and it returns it unchanged.

    [Notice] Zone handles are just numbers that can be recognised by the engine as referring to a zone -- because what is 5? Is it a zone ID, NPC ID, party slot, map number, ...?? There's no way to or necessity to destroy a zone handle after use.
      # Resize to 5 extra data slots
    resize extra(get zone(10), 5)
    # Set the last (10th) extra data field to 42
    set extra(get zone(10), -1, 42) # Can also be written as  set zone extra(10, -1, 42)
    				


    Tweaking Maps → General Map Settings

    allow minimap (setting)

    Sets whether the Map option appears in the menu. Give no argument or true to enable, or false to disable. The effect goes away if you change maps or fight a battle.

    See also:

    allow save anywhere (setting)

    Sets whether the Save option appears in the menu. Give no argument or true to enable, or false to disable. The effect goes away if you change maps or fight a battle.

    See also:

    set harm tile damage (amount)

    Sets the amount of damage taken when you step on a harm tile. The effect goes away if you change maps or fight a battle.

    set harm tile flash (color)

    Sets the color (from the master palette) which the screen flashes when you step on a harm tile. Call with no argument to disable the flash. The effect goes away if you change maps or fight a battle.

    set foot offset (offset)

    Sets the foot offset in pixels, the vertical displacement of npc and hero sprites from the base of the tiles on which they stand. The effect goes away if you change maps or fight a battle.

    get foot offset

    Returns the map's foot offset.

    draw NPCs above heroes (setting)

    Sets whether NPCs are drawn above, beneath or together (Y-sorted) with heroes. The effect goes away if you change maps or fight a battle (unless saved by save map state). setting is one of:

    set map edge mode (mode, default tile)

    Sets the behaviour at the edge of the map. Use the constants crop, wrap and default tile. When the behaviour is default tile, you should give a second argument specifying which tile should be displayed off the boundaries of the map, otherwise ignore the second argument. The effect goes away if you change maps or fight a battle.

    get map edge mode

    Returns the map's edge mode. Use the constants crop, wrap and default tile to compare with the value returned.


    Tweaking Maps → Map State

    save map state (whichdata, customid)

    Saves the state of the current map to a temporary file which will be loaded (unless the map is set to ignore that particular data) when you reenter the current map, in the same way as a map set to save (remember) NPC or tile data: the saved state will be used instead of the map data in the RPG file. Both arguments are optional and are only for advanced uses.
    Map state is not saved in saved games, and the temporary files will be deleted when you load or start a new a game!
    whichdata is an or'd combination of the following constants, which specify exactly what you want to save:

    The default is mapstate:all.
    If customid is passed, it is used to save the state in a separate state file with an id number of customid which can only be loaded with load map state. There are 32 available slots for use: 0 - 31.
    Note that mapstate:mapsettings (also saved by mapstate:all) is special in that if you save it, it will always be loaded when the map is loaded regardless of settings. It saves all the settings found in the General Map Settings menu like the ambient music, footoffset, map trigger scripts, and so forth, and also the tileset for each layer.
    plotscript, generic menu screen, begin
      variable (remember map, remember x, remember y)
      remember map := current map
      remember x := hero x
      remember y := hero y
      # we want NPCs and things to stay in the same place after we come back from the menu
      save map state
    
      fade screen out
      wait
      teleport to map (map:generic menu)
      fade screen in
      wait
    
      # menu code here
      #...
      #...
    
      fade screen out
      wait
      teleport to map (remember map, remember x, remember y)
      # assume the map is set to load state only, the default (otherwise, use load map state)
      fade screen in
      wait
    
      # we want the map to go back to resetting whenever you enter/exit it (like normal)
      delete map state
    end

    load map state (whichdata, customid)

    Load temporary map state data previously saved either by save map state or when leaving a map set to remember state. The two arguments are optional and for advanced use. whichdata is a set of bits in the save map state format to determine what exactly to load. The default is mapstate:all. customid is a number between 0 and 31 of a slot in which a custom save was made. Data from a different map can be loaded, but only tile data from a map of the same size! If you attempt to load state data which has not been saved then it will be loaded from the game files instead, unless you are using customid, in which case nothing will be loaded.

    reset map state (whichdata)

    Reloads original unaltered map data from the RPG file. whichdata is a set of bits in the save map state format to determine what exactly to load. It is optional and the default is mapstate:all (which doesn't reset global NPC definitions). This does not remove temp state files for the map, so they could still be loaded instead when you next enter the map, use delete map state to remove them if wanted.

    delete map state (whichdata, custom id)

    Deletes temporary map state for the current map saved either with save map state or by leaving a map set to save state. By default (if both arguments are omitted), if the map is set to load NPC or tile data it will instead load the original data from the game files when it is entered.
    whichdata is an optional set of bits in the save map state format to determine what exactly to delete. The default is mapstate:all. customid is an optional number between 0 and 31 of a slot in which a custom save was made.


    Timers

    [Back to top-level index]

    set timer (id, count, speed, trigger, string, flags)

    Changes the settings for a given timer, and starts it. id is the number of a timer -- by default, there are 16 timers, numbered 0 to 15 but you can change the number of available timers with allocate timers. All other parameters are optional, or you can pass timer: default as any of them. This will leave the parameter unchanged (from the last time you set it or from the default initial value), it will NOT cause that timer setting to be reset to the default initial value. Count is the length of the timer. While it's running, the count will go down by one every speed game ticks (frames). I.e., if you set speed to 18, it will count down once every 18 ticks, close to one second if using the default framerate of 18.3fps. Use a speed of 1 to count down in ticks. Changing the timer's count (as opposed to passing timer:default as the second argument) will cause the timer to restart from the new value.
    trigger is what happens when the timer runs out. You can use the constant timer: game over to indicate that the game should end (the gameover script is not called), or specify a plotscript (in the form @my script) to have that run. A plotscript will get passed the id of the timer that triggered it as its first argument, if it has one, unless you specify the arguments using set timer args. If the timer runs out during a battle then the effect happens after the battle ends.
    You can bind a timer to a string using the string parameter to create a countdown that shows up on screen. Pass it the id of a string, and that string will be updated every time the timer counts down. You are responsible for displaying and positioning the string.
    A timer also has a few other options in the form of flags. You can pass any combination of these flags (by oring them together; see the example):


    [Notice] Timers start counting down not from the current game 'tick', but from next one. So if you want to trigger something next tick (eg. run a script every frame) you need to pass count as 0 and speed as 1. A timer count set to 1 would counter-intuitively trigger in 2 ticks time.
    [Notice] Timer settings are not saved in saved games.
    # This starts a 300 second (5 minute) timer that counts down once every 18 ticks (approximately one second).
    # If it runs out during battle, the battle won't end but a game-over will happen afterwards.
    set timer (0, 300, 18, timer: game over, 0, (timerflag: battle, or, timerflag: menu))
    See set timer args for a larger example.

    set timer args (id, args...)

    Sets the arguments that a timer will pass to the script it triggers. (If the timer isn't set to call a script this shows an error, so you have to call set timer before set timer args.)
    This overrides the default first argument to the script, which is the timer ID. So if you want the timer ID to be first argument you have to write something like
    set timer args(id, id, 20) # Script gets args 'id, 20'
    If you call this with no arguments (set timer args(id)) then all the script's arguments default to 0. If the script doesn't take as many args as you pass it the extra ones will be ignored without error.

    [Warning] After the script runs the arguments will still be remembered for next time the timer is run (you can re-start a timer by calling set timer(id, count)), unless the script ID is changed (or set to 0).
    [Danger] Due to a bug, the script's default arguments will be ignored, and missing arguments are instead set to 0. This happens whether you use set timer args or not, and affects all triggered scripts. This will be fixed in some future version.
    # This script changes the tile at x,y on tilemap 'layer' between tile IDs 'tile'
    # and 'othertile' in the tileset every 5 ticks, repeating until the map changes.
    script, blink tile, x, y, layer, tile, othertile, timerid, whichmap = -1, begin
    
      # Remember which map we started running on, and stop if the map changes
      if (whichmap == -1) then (
        whichmap := current map
      ) else (
        if (whichmap <> current map) then (exit script)
      )
    
      write map block (x, y, tile, layer)
    
      # Cause this script to run again in 10 ticks, but this time
      # swap 'tile' and 'othertile'
      set timer (timerid, 0, 10, @blink tile)
      set timer args (timerid, x, y, layer, othertile, tile, timerid, whichmap)
    end
    
    # Some timer IDs
    define constant (10, timer:blink1)
    define constant (11, timer:blink2)
    
    # This is an auto-run script for a map
    plotscript, blinky map, begin
      blink tile (4, 5, 0, 0, 1, timer:blink1)   # Blink x=4,y=5,layer=0 between tiles 0 & 1
      blink tile (11, 10, 1, 5, 10, timer:blink2) # Blink x=11,y=10,layer=1 between tiles 5 & 10
    end
    See also:

    stop timer (id)

    Stops a timer by setting its speed to 0. All of its other settings remain the same. You can resume it by calling set timer(id, timer:default, speed) if you know the original speed.

    See also:

    allocate timers (number)

    Changes the number of available timers. The range of valid timer IDs becomes 0 to number-1. You can reduce the number of timers down to zero, and increase it up to 100000 (not recommended, each timer must be processed continuously). All existing timers that are not removed continue to run. The default number of timers is 16.

    read timer (id)

    Returns the "count" of a given timer. A timer's count is at first equal to the count argument to set timer (or zero, if the timer hasn't been used). After speed ticks since set timer was called, the count is reduced by one.
    The timer is triggered when the count becomes negative. Normally a timer that has finished has a count of -1, unless it had a negative count to begin with, most likely to happen if you restart a timer by passing timer:default as the count argument to set timer. (So if you keep repeating it that way, each time its count will reduce further: -1, -2, -3, ...)

    See also:


    Script Triggers

    [Back to top-level index]

    set death script (id)

    Changes the script that is run when you die in battle. The argument is the script's ID number, NOT the script's name. Calling set death script with no argument disables the death script.

    get death script

    Returns the ID number of script that is run when you die in battle.

    set load script (id)

    Changes the script that will be run when you load this game after it is saved. The argument is the script's ID number, NOT the script's name. Calling set load script with no argument disables the load script.

    [Warning] This command has no effect if the "Save gameover/loadgame script IDs" Preference Bitset is turned off!
    [Notice] Setting the load script and then loading an existing saved game has no effect, because the load game script already stored in that saved game is used instead. Unless "Save gameover/loadgame script IDs" is off, in which case the default one is used.

    get load script

    Returns the ID number of script that is run when you load a saved game.

    set on keypress script (id)

    Changes the script that is run when you press a key. The argument is the script's name preceded by an @ sign. You can also use the ID number for old-style scripts. Calling set on keypress script with no argument disables the keypress script. The effect goes away if you change maps or fight a battle.

    set on keypress script(@keyhandlerscript)

    get on keypress script

    Returns the ID number of script that is run when you press a key.

    set each step script (id)

    Changes the script that is run when you take a step. The argument is the script's name preceded by an @ sign. You can also use the ID number for old-style scripts. Calling set each step script with no argument disables the each step script. The effect goes away if you change maps or fight a battle.

    get each step script

    Returns the ID number of script that is run when you take a step.

    set instead of battle script (id)

    Changes the script that is run instead of a random battle when one is triggered. The argument is a reference to the script in the form @scriptname. Calling set instead of battle script with no argument disables the instead of battle script. The effect goes away if you change maps or fight a battle.

    get instead of battle script

    Returns a reference to the script that is run instead of battles.

    get current map autorun script

    Returns a reference to the script that is run automatically when you load the current map.

    get current map autorun script argument

    Returns the argument value that will be automatically passed to the autorun script on the current map. Is this useful? Not very!


    General Game Settings

    [Back to top-level index]

    These commands access data in the General Game Settings menu.

    set caterpillar mode (state)

    Sets whether or not to display the whole party in "caterpillar" style. This sets the "Enable Caterpillar Party" general preference bitset. If the argument is off then only the leader will be displayed. If the argument is on then the whole active (battle) party will be displayed and will normally walk behind the leader.

    [Warning] Do not confuse this with the suspend caterpillar and resume caterpillar commands, which only apply when caterpillar mode is ON.

    set HP level up restore (state)

    Sets whether or not a hero regains full HP after a level-up. If the argument is on then HP is restored on a level-up. If the argument is off then the hero's HP is not restored on a level-up.

    set MP level up restore (state)

    Sets whether or not a hero regains full MP after a level-up. If the argument is on then MP is restored on a level-up. If the argument is off then the hero's MP is not restored on a level-up.

    set inn revive mode (state)

    Sets whether or not inns restore dead heroes to life. If the argument is on then dead heroes are restored by inns. If the argument is off then dead heroes remain dead in inns.

    set full hero swap mode (state)

    Sets whether or not you can swap heroes in and out of your active party from the menu. If the argument is off then the "Order" menu will be available. If the argument is on then the "Team" menu will be available.

    set debug keys disable (state)

    Sets whether or not the debugging keys are allowed. If the argument is off then debugging keys are allowed. If the argument is on then debugging keys are disabled.

    extended scancodes enabled

    Returns the state of the "Disable better scancodes for scripts" backcompat bitset, returning true if it's off. This means that numpad keys are distinguishable from Home, Up, etc. keys. See scancode.

    get screen width

    Returns the width of the screen in pixels.

    get screen height

    Returns the height of the screen in pixels.

    See also:

    read preference bit (bitnum)

    Returns the value (true or false) of one of the bits in the Preference Bitsets, Active-time Battle Bitsets or Backwards-compatibility Bitsets menus (in the General Game Settings menu). You can use this command if there isn't a dedicated command to read the bit, such as extended scancodes enabled. Get the value of bitnum from the list below or by checking this list on the wiki (which might possibly be more up-to-date).

    [Warning] Some bits have names which are opposite above/on the wiki and in the editor! If that's the case, you need to set the bit off instead of on and vice versa. They might also have slightly different names. For example to check whether "Randomize initial ready meters" is on, use read preference bit(22) == off, because bit 22 is documented as "Don't randomize battle ready-meters". In the above list, any bit will an inverted name is (hopefully) shown with part of the description in bold.

    write preference bit (bitnum, value)

    Sets the value (true or false) of one of the bits in the Preference Bitsets, Active-time Battle Bitsets or Backwards-compatibility Bitsets menus (in the General Game Settings menu). You can use this command if there isn't a dedicated command to write the bit, such as set battle wait mode. Get the value of bitnum from the list at read preference bit or by checking this list on the wiki (which might possibly be more up-to-date).

    [Warning] Some bits are shown with the opposite names here/the wiki and in the editor! If that's the case, you need to set the bit off instead of on and vice versa. They might also have slightly different names. For example to turn on "Randomize initial ready meters", use write preference bit(22, off), because bit 22 is documented as "Don't randomize battle ready-meters".
    [Danger] Use common sense. Some bits, such as "Limit maximum tags to 999" might be disastrous to change in the middle of a game! Or they might have no effect.


    General Game Settings → Battle System Settings

    These commands access data either in the Battle Settings submenu in General Game Settings menu, or in the Preference Bitsets submenu.

    set battle wait mode (state)

    Set whether or not battles pause on spell and item menus. If the argument is off then enemies continue to attack while menus are up, if the argument is on then enemies wait while menus are up.

    get active battle pause on all menus

    Returns true if active-time battles are configured to pause on all menus.

    set active battle pause on all menus (value)

    Changes whether active-time battles will pause on all menus. The argument should be true to pause, or false to not pause. This option has no effect on turn-based battles. This option is not stored in save-games, so changing it only lasts until the game is quit and reloaded.

    set turn based battle mode

    Changes the battle mode to turn based. This option is not stored in save-games, so changing it only lasts until the game is quit and reloaded.

    get turn based battle mode

    Return true if the battle mode is currently turn based.

    set active time battle mode

    Changes the battle mode to active time. This option is not stored in save-games, so changing it only lasts until the game is quit and reloaded.

    get active time battle mode

    Return true if the battle mode is currently active time.

    show battle ready meter (state)

    Sets whether or not the ready meter appears in battle, or will be hidden. state should be true or false.

    show battle health meter (state)

    Sets whether or not the health meter appears in battle, or will be hidden. state should be true or false.

    set dead heroes gain experience (state)

    Sets whether or not dead heroes gain experience from battles. If the argument is false then only living heroes gain experience. If the argument is true then dead heroes get it too.


    General Game Settings → Caps

    get damage cap

    Returns the current damage cap, or 0 if there is none.

    set damage cap (cap)

    Sets the current damage cap to cap. Use 0 for no cap.

    get level cap

    Returns the current level cap.

    set level cap (cap)

    Sets the level cap. cap must be a value from 0 to 99. Heroes with level equal to or greater than the level cap can't gain experience through battles, give experience, or set experience, and the status screen doesn't show their experience to next level. You however can use set hero level to set a hero's level above the level cap. The level cap does not change the amount of experience needed to gain a level, nor the stat increases at level-up.


    Saved Games

    [Back to top-level index]

    load menu (reallyload, show new game)

    Documented in the Opening Built-in Menus section.

    autosave

    Transparently saves the game to the last save slot saved to or loaded from (see last save slot), or if playing a new game which has not been saved yet, calls save menu. Returns the number of the save slot saved to, or if the user cancelled the save menu, returns false.

    See also:

    save in slot (slot)

    Saves in the specified save slot (1 to 1000, regardless of how many are visible on the save and load menus). If a saved game already exists in the slot, it will be overwritten. If you want to make sure that no save game will be overwritten, use save slot used. To display the save game menu instead, use save menu.

    load from slot (slot, args...)

    Loads a saved game from a save slot as if it had been loaded from the load game menu. slot is a slot number from 1 to 1000, (regardless of how many are displayed on the Load and Save menus). This command will end the current game (and fade out and in again) if it successfully loads. If the load fails because the slot has never been saved in, the script will continue. Anything that you want to happen after loading a saved game needs to be put in the 'load game' script instead (specified in Special Plotscripts). You can pass any number of additional optional args to the loadgame script. (slot is also always passed as the first argument to the loadgame script, so args are the 2nd and later arguments.)

    [Danger] The default arguments of a loadgame script (and all other triggered scripts) are currently ignored. If you don't pass enough args, then the remaining arguments default to zero, so don't use defaults other than zero!
    # This example shows automatically loading the last save when you die,
    # and does something special after loading by passing an argument to the loadgame
    # script. You could accomplish the same thing with a global variable instead.
    
    # "slot" is the save slot number
    # "is quickload" defaults to 0 (false) if the game is loaded from the regular load menu, and
    # can be something else if we use "load from slot"
    plotscript, my loadgame script, slot, is quickload, begin
      if (is quickload) then (
        show textbox(42)  # "You died and have been restored from the last save point!"
        wait for textbox
      )
    end
    
    plotscript, my gameover script, begin
      fade screen out(63, 0, 0)  # fade to red
      wait(10)
      fade screen out(0, 0, 0)   # fade to black
      if (last save slot) then (
        # On death, reload the last save automatically, and tell the loadgame script we're doing so
        load from slot(last save slot, true)
      ) else (
        # The player hasn't saved yet... too bad!
        game over
      )
    end

    delete save (slot)

    Deletes a saved game in the specified save slot (1 to 1000, regardless of how many are displayed on the Load and Save menus). The save will no longer be visible on the load game menu or loadable with load from slot.

    See also:

    last save slot

    Returns the last save slot either loaded or saved to (whichever happened last) or false if this is an unsaved new game. Save slots are numbered starting at 1.
    save menu(false) and load menu(false) (which show the menus but don't actually save or load) don't change the last save slot.
    last save slot returns the last save slot used, even if the save in it has since been deleted (e.g. with delete save).

    [Warning] In versions before Callipygous, save in slot didn't change the value returned by last save slot, but save menu(false) and load menu(false) did.

    set last save slot (slot)

    Sets the value returned by last save slot. This changes the slot used by autosave. slot can be any slot from 1 to 1000, or 0 for none, even if the number of save slots visible to the player in the load/save menu is less.

    save slot used (slot)

    Returns whether a game has been saved in the save slot. For example, you can use this if you don't want to overwrite a saved game with save in slot. This returns false if the slot has never been saved to normally, but has been written to using export globals (which will create a nearly-empty .rsav file containing just globals, if it doesn't already exist).

    send email (save slot, subject string id, message string id)

    Documented in the Debugging section.

    get load script

    Documented in the Script Triggers section.

    set load script (id)

    Documented in the Script Triggers section.

    import globals (slot, first, last)

    import globals (slot, id)

    import globals (slot)

    Loads a range of globals from a saved game, overwriting the current globals in that range. slot is the save slot number, from 1 to 1000. Note that only slots 1-4 appear by default on the save/load menus. first and last are the id numbers of the globals at the beginning and end of the range (inclusive). If you leave out both of first and last all global variables will be imported.
    To read a single global from a save slot without modifying any of your globals, use the form var := import globals (slot, id). This is NOT the same thing as import globals (slot, id, id), which does modify the global variable.
    import globals and export globals can be used to save and retrieve info about a saved game without loading it, and also to store variables that any game the player starts can use, such as high scores and other "global" data, like in the following example:

    global variable (100, game completed)
    global variable (101, hours to complete)
    global variable (102, minutes to complete)
    
    plotscript, game finished, begin
      game complete := true
      hours to complete := hours of play
      minutes to complete := minutes of play
      export globals (5, 100, 102) #special slot that the player can not load, which we can use for anything
    end
    
    plotscript, check game finished, begin
      import globals (5, 100, 102) #copy saved values into globals 100, 101, 102
      if (game completed) then (
        show textbox (105) #"you have previously finished this game in ${V101} hours and ${V102} minutes"
      ) else (
        show textbox (106) #"you have yet to complete the game!"
      )
      wait for textbox
    end
    [Notice] You can import globals from an empty save slot; it's not an error to do so. This reads the value of all of the globals as zero. You can also export/import globals to/from an empty save slot that doesn't have a full saved game in it; see export globals.

    export globals (slot, first, last)

    Writes a range of globals to a save game slot, overwriting the saved game's globals. slot is the save slot number, from 1 to 1000, regardless of how many save slots enabled in the save/load menus. first and last are the id numbers of the globals at the beginning and end of the range. first defaults to 0, and last defaults to 50000. Therefore, if you pass no range, all the globals will be written.

    [Notice] You can export globals to an empty slot! This doesn't create a visible save game that the player can load (and save slot used will still return false for that slot), however you will be able to read them with import globals. You can delete these globals using delete save.
    [Danger] Unlike importglobals, export globals (slot, first) does NOT export a single global variable!


    Advanced Functions

    [Back to top-level index]

    run script by ID (id, argument1, argument2, argument3...)

    The run script by id command allows you to run a script using its script ID. You can get the ID of a script by writing @ (the 'reference' operator) in front of its name, see the example. You can not run a built-in command like wait; they aren't scripts. Arguments after the ID will be passed to the script. The return value of this command is whatever value the script returns. A run-time error is displayed and -1 is returned if the script does not exist. You can pass up to 31 arguments to the script.
    The advantage of this command as opposed to just calling the script directly is that the ID may be stored in a variable, or it could be the function return value of another script. For example, using set slice extra you might want to store the ID of a script that should be run when the player clicks on a slice.

    [Danger] If you pass too few arguments, the unspecified ones will have value zero regardless of any default values given in the script declaration. This bug will be fixed in some future version.
    If you pass too many (which does not cause an error), the extra ones are ignored.
    plotscript,scriptcallingtest,begin
      show value (run script by id (@sum, 1, 2, 3))
    end
    
    script,sum,a,b,c,begin
      return(a+b+c)
    end

    run game(file string id)

    Quit the current game and switch to a different .rpg file/.rpgdir. When that game is quit, the program either exits or goes to the game browser as usual. So if you want to return to the original game you need to call run game a second time from that game instead of using game over.) file string id is the ID of a string that contains the filename of the game to load. If the game is not in the same directory, then you need to provide a relative path, like "bonus content\Prequel.rpg" or "../selectmenu.rpg". The path is case-insensitive and / and \ are interchangeable.

    # load another game in the same directory
    $0 = "part2.rpg"
    run game(0)

    check game exists (file string id)

    Check whether an .rpg file/.rpgdir directory exists, returning true or false. This is useful before calling run game, which will show an error if the game doesn't exist. See run game for more information about the filename.

    See also:

    milliseconds

    Use to measure time intervals accurately. Subtract two values returned by milliseconds at different times to find the number of ms (1000ths of a second) elapsed in between. A single value is useless (the computer's up-time or any random value).

    See also:

    microseconds

    An alternative to milliseconds which measures millionths of a second. This command only exists for accurate benchmarking.

    save screenshot

    Saves a screenshot, as if the player pressed F12. A popup will appear telling the filename of the screenshot.

    [Warning] The screenshot might be taken either of the previous frame or the next one. To be safe, if you're displaying something and then taking a screenshot of it, put a wait(1) in between.

    pathfind into extra as hero (extra, start x, start y, dest x, dest y, maxdepth, append, skip first)

    Perform pathfinding between 2 points, using the wall+obstruction rules for heroes. Store the results into extra data (for example, on a slice or an npc) The x and y values of each step in the path will be put into the extra data with 2 values for each, X,Y,X,Y,X,Y to the end of the path. All values are in tile coordinates. If you need pixel coordinates, multiply by 20. The function return value will be true of the destination was reachable, or false if the pathfinding had to give up before reaching the destination. (If it gave up, the extra data will still be filled with the path leading to the closest reachable tile) The first argument extra is the slice handle or npc reference to put the extra data into. The next 4 arguments are the X,Y of the start position, and the X,Y of the destination. Current hero positions don't matter, but if you wanted to pathfind based on the leader hero's current positions, you could use hero x(me), hero y(me) for the start x and y. The maxdepth argument is the maximum search depth in tiles to seach before giving up. The default value of 0 means no maximum (search the entire map) The append argument can be set to true if you want to append data to the existing extra data. The default value of false means that the existing extra data will be replaced. The skip first argument can be set to true if you want to exclude the start position from the path (this can be useful if you are appending multiple paths together, or in other situations where it may be convenient)

    pathfind into extra as npc (extra, npc ref, start x, start y, dest x, dest y, maxdepth, append, skip first)

    Perform pathfinding between 2 points, using the wall+obstruction rules for a specific NPC. Store the results into extra data (for example, on a slice or an npc) The x and y values of each step in the path will be put into the extra data with 2 values for each, X,Y,X,Y,X,Y to the end of the path. All values are in tile coordinates. If you need pixel coordinates, multiply by 20. The function return value will be true of the destination was reachable, or false if the pathfinding had to give up before reaching the destination. (If it gave up, the extra data will still be filled with the path leading to the closest reachable tile) The first argument extra is the slice handle or npc reference to put the extra data into. The second argument npc ref is the NPC reference of the NPC who will be used for pathfinding. You can also use an NPC ID, but this will use the first copy of that NPC on the map, which might matter for the pathfinding, because an NPC can path through itself, but cannot (by default) path through other copies of the same NPC ID. The next 4 arguments are the X,Y of the start position, and the X,Y of the destination. Current NPC position does not matter, but if you wanted to pathfind based on the NPCs current position, you could use npc x(npc ref), npc y(npc ref) for the start x and y. The maxdepth argument is the maximum search depth in tiles to seach before giving up. The default value of 0 means no maximum (search the entire map) The append argument can be set to true if you want to append data to the existing extra data. The default value of false means that the existing extra data will be replaced. The skip first argument can be set to true if you want to exclude the start position from the path (this can be useful if you are appending multiple paths together, or in other situations where it may be convenient)


    Advanced Functions → Debugging

    trace (string)

    Writes string #string to "g_debug.txt", located in the same directory as the RPG file or game.exe. For debugging you will nearly always use trace value instead, which is much easier.

    variable (i)
    i := random (1, 1000)
    $1 = "i = "
    append number (1, i) # string 1 is "i = ????"
    trace (1) # writes "TRACE: i = ????" to g_debug.txt

    trace value (expression, ...)

    trace value of (expression, ...)

    Prints one or more expressions and their values to "g_debug.txt". The number of arguments to this command is variable; each is printed as source text along with its value. You can't print strings with this command; use trace instead.
    trace value of is an alias to trace value.

    variable(i)
    i := random (1, 1000)
    trace value (i)  # writes "TRACE: i = ????" to g_debug.txt
    
    # This writes something like "TRACE: hero X (me) = 14, hero Y (me) = 53" to g_debug.txt
    trace value (hero X (me), hero Y (me))

    dump slice tree (slice)

    Prints out a brief description of a slice and all its descendents to "g_debug.txt". slice is optional; if omitted the whole tree is printed out.
    This is also available as "List slices to g_debug.txt" in the F8 Debug Menu.

    [Notice] Most of the slice data isn't printed; if you want to inspect it the easiest way to do so is either to press Shift+F4 to view the slice editor/debugger, or to call script error at the exact moment you want to check the slice tree; you can then enter the slice debugger from the Script Error menu.

    script error (string id)

    Shows an error message, like any other script error. This allows you to open the script debugger. (Use breakpoint to skip the menu straight to the debugger.) The optional string id argument gives the error message to display.

    if (x < 0 || x >= map width || y < 0 || y >= map height) then (
      $0="Coordinates went off the edge of the map"
      script error(0)
    )

    breakpoint

    Open the script debugger; this is slightly simpler than using `script error`. You can temporarily add this to a script you're trying to debug if you want to examine its state at a certain point.

    debug menu

    Opens the debug menu, which you can open by pressing F8 if debug keys are enabled; this is useful if debug keys are disabled, or on handhelds/consoles without an F8 key.

    assert (expression)

    If expression is false, then writes the script filename, line number and expression into the string given by the constant or global variable named assert expression string, and then calls the script named assert failure. You can use this to detect bugs in your scripts, by checking that your assumptions about the state of the game are correct.

    # The following...
    assert (check tag (tag:initialised) == OFF)
    # ...is equivalent to something like
    if (not (check tag (tag:initialised) == OFF)) then (
      $assert expression string="myscripts.hss:123: check tag (tag:initialised) == OFF"
      assert failure
    )
    # Suggested usage:
    define constant(31, assert expression string)
    script, assert failure, begin
      script error(assert expression string)
    end
    
    # later...
    assert (check tag (tag:initialised) == OFF)  # something ought to be true at this moment
    

    get slice lookup name (string id, code, use default name)

    Lookup the codename of a slice lookup code ID (either user-defined or builtin). string id is the ID of a string to put the name into and code is a slice lookup code like sl:map layer 2.
    The sl: or sli: prefix (for builtin and user codes respectively) isn't prefixed to the codename. For example, might set the string to "map layer2". use default name is optional, defaulting to true. When true, if there is no codename with that code, the produced codename is e.g. "Lookup40"; when false, the string is set to "". But if code == 0 then the string is always set to "".

    get script name (string id, script id)

    Fetches the name of a script given its script ID number and places it in a string. It's an error to pass an invalid script ID. You can get the ID number of a script by writing @scriptname.

    get calling script id (depth)

    Returns the ID number of the script which called this one. The optional depth argument, which defaults to 1, allows returning the ID of a deeper ancestor script instead: 1 is the parent, 2 is the grandparent, etc. If there is no calling script (the script was triggered instead), then the return value is 0. You can get the ID number of a script by writing @scriptname.

    See also:

    send email (save slot, subject string id, message string id)

    [Warning] This command is only implemented on Android! Calling it on other platforms does nothing.
    This asks the player if they want to send an email to you, optionally with a save file attached. The purpose is to make it easy for players to send bug reports or feedback, especially on Android, where it might otherwise be a nuisance to send saved games. When called on Android, a standard system menu is brought up asking the player which email client they want to use. If they don't cancel, that client is opened with an email already filled out, which they can edit as usual:
    The email is sent to the address set in the Distribute Game->Distribution Info menu.
    subject string id is optional; it is the id of a string containing the email subject line. If you leave it out or set it to -1 then the default subject line is "[Name of the game] feedback".
    message string id is optional; it is the id of a string containing the email body text. If you leave it out or set it to -1 then it defaults to "(Please include a helpful description of the problem here)".
    The save slot argument is optional, and is either an existing save slot number, or false (the default) to not attach a save. You can use save in slot with a large slot number to create a temporary save of the current game. If you attach an save file two other files are also attached: g_debug.txt and g_debug_archive.txt. g_debug.txt is useful for tracking down OHRRPGCE engine bugs, but you can also write to it using trace and trace value. You can also check it for error messages, such as script errors (errors will start with a ! at the beginning of the line). g_debug_archive.txt contains backups of g_debug.txt from previous times the game was played.
    To load the .rsav file, rename it if necessary (e.g. 0.rsav for the first save slot), and put it in the 'gamename.saves' folder.


    Platform Specific

    [Back to top-level index]

    window is focused

    Returns true if the game's window is the currently active (focused) one (or if it's fullscreen and active), or false if the user has switched to a different program. This is always true when running on a smartphone, because when the app is backgrounded the game is paused and scripts don't run.
    Use this command if you want to pause something when the player switches to another program.

    running on desktop

    This command returns true if the game is currently running on any Windows/Mac/Linux desktop computer. You should avoid using this command unless you really need it. Most games will never need this command.

    running on Windows

    This command returns true if the game is currently running on a Windows computer. You should avoid using this command unless you really need it. Most games will never need this command.

    running on Mac

    This command returns true if the game is currently running on a Macintosh computer. You should avoid using this command unless you really need it. Most games will never need this command.

    running on Linux

    This command returns true if the game is currently running on a GNU/Linux desktop computer (not including Android or other non-PC Linux-based OS). You should avoid using this command unless you really need it. Most games will never need this command.

    running on mobile

    This command returns true if the game is currently running on a mobile device such as an Android phone or tablet. You should avoid using this command unless you really need it. Most games can support mobile devices without ever using this command. See the "Platform-Specific Options" menu under "Edit General Game Data".

    running on console

    This command returns true if the game is currently running on an console. Currently supported consoles include OUYA, MOJO, GameStick, and FireTV. You should avoid using this command unless you really need it. Most games can support the consoles without ever using this command. See the "Platform-Specific Options" menu under "Edit General Game Data".

    running on web

    This command returns true if the game is currently running on a web browser. You should avoid using this command unless you really need it. Most games can support web without ever using this command.

    running on ouya

    This command returns true if the game is currently running on an OUYA console. Ouya is an obsolete console that is no longer generally available. You should avoid using this command unless you really need it. Most games can support the OUYA console without ever using this command, and even if you do need to do special scripting just for ouya, you should consider using running on console instead, since the only thing different about OUYA is its button names and in-app-purchase support. See the "Platform-Specific Options" menu under "Edit General Game Data".

    hide virtual gamepad

    If the game is running on a platform that supports a touchscreen virtual gamepad (such as Android) this command forces the virtual gamepad to become hidden, even if it would normally be visible. On other platforms, this command does nothing. The effects of this command can be cancelled by using the auto virtual gamepad command.

    show virtual gamepad

    If the game is running on a platform that supports a touchscreen virtual gamepad (such as Android) this command forces the virtual gamepad to become visible, even if it would normally be hidden. On other platforms, this command does nothing. The effects of this command can be cancelled by using the auto virtual gamepad command.

    auto virtual gamepad

    If the game is running on a platform that supports a touchscreen virtual gamepad (such as Android) this command cancels a previous show virtual gamepad or hide virtual gamepad command. The virtual gamepad will once again automatically show or hide itself automatically based on various factors such as textboxes, menus, battles, or suspend player. On other platforms, this command does nothing.


    Types and Handles

    [Back to top-level index]

    This section documents many of the different types of values that are used by various script commands, such as NPC references. Note that in HamsterSpeak everything is a number, so there are no types as in other programming languages; instead identifiers are used for everything. Values of different ID numbers and handles overlap: there's no way to tell if a number refers to an NPC or a slice or a map.

    NPC IDs

    An NPC ID refers to an NPC type (aka NPC definition), as defined in the Edit Local/Global NPCs menus. Local and global NPC pools both have ID numbers that count from 0 upwards, so the ID doesn't tell you whether it's a local or global NPC. Some commands such as NPC copy count take both an NPC ID and an NPC pool as separate arguments. But most NPC commands, such as walk NPC, don't take a pool argument. If you pass an ID to these, then it's interpreted as an ID in the local NPC pool.
    A copy of an NPC is referred to using an NPC reference.

    NPC pool numbers

    An NPC pool number tells whether an NPC ID refers to an NPC in the local or global NPC pools. (In future there may be more than two pools.) It can be either pool:local (which is 0; NPCs specific to one map) or pool:global (which is 1). Most commands that accept NPC IDs don't have an argument to tell the pool number. These always default to the local pool, and you need to first use the NPC reference or global NPC reference functions to get an NPC reference to pass to these commands if you want to refer to a global NPC by ID.

    NPC references

    What is an NPC reference? A reference is a number that uniquely identifies an NPC instance on the map. You can use an NPC reference to specify which NPC you are controlling in most NPC-related commands.
    NPC references are handles for NPC instances on the map, that is, a copy of an NPC definition. NPC references are always negative values, while NPC IDs count from 0 up. An NPC ID for a local NPC can always be used with any command that expects an NPC reference, in which case it refers to the first instance/copy of that NPC ID from the local NPC pool, not to the NPC definition itself. (If you want to refer to a global NPC, you need to first use global NPC reference.) So wait for NPC(5) is equivalent to wait for NPC(NPC reference(5, 0)).

    [Notice] If you want to loop over all NPC instances (that is, over all NPC references), use next NPC reference. An NPC reference historically was (and still is for now) a number between -1 and -300, but that will change in an upcoming version. So it's strongly recommended that you don't loop over values -1 to -300.
    [Warning] If you move to a different map you mustn't use the old references on the new map. If you set the map to save NPC data when leaving, the previous references will be valid when you get back to it.

    Slice handles

    Slices are referred to with slice handles. A slice handle is just a value that you can store in a variable, just like an NPC reference or a menu handle. A handle is valid if it currently refers to an existing slice. false (zero) is never a valid slice handle, so slice commands return 0 to indicate "no slice found" or similar failures.

    [Notice] slice lookup codes like "sl:map layer 0" or "sli:quit button" are NOT slice handles; they can only be used by the lookup slice command.

    Blendable slice handles

    A slice handle for a slice type which has blending settings (opacity and blend mode), which currently are Sprite and Map (map layer) slices. More slice types will become blendable in future versions.

    [Notice] Rectangle slices aren't blendable, however the background of a rect can be made transparent using set rect opacity instead of set opacity. This doesn't make the box border transparent, and get opacity will still return 100.

    Object handles

    Object handles are handles to things that have extra data arrays, they can be passed to Extra Data Array Functions. An object handle is either a slice handle, an NPC reference (NOT an NPC ID!), a zone handle (returned by get zone; NOT a zone ID!), or a menu item handle. Menu handles are distinct from all the others but don't (yet) count, because they don't have extra data. false (zero) is never a valid object handle.

    Slice lookup codes

    Slice lookup codes are used to search for a particular slice using lookup slice. There are two types. User defined slice lookup codes are defined (named) in the slice collection editor. You will find them as constants in your .hsi file with sli: prefixes, and they count up from 1. You can also use any non-negative value, even if you haven't named it in the editor. There are also many special slice lookup codes with names that start with sl: prefixes. See lookup slice for the list. They are always negative.

    Menu handles

    A handle for a currently open menu, for example, the one returned by open menu or create menu or top menu. Menu handle 0 (false) means none/invalid. Not the same thing as a menu ID (which is a menu defined in the menu editor). There can be multiple open copies of a single menu ID.

    Menu item handles

    A handle to one of the items in a currently open menu, for example, the one returned by selected menu item. Menu items in different menus are always different, so it's possible to lookup which menu its in with parent menu, and menu handles are never reused.

    Extra data array index

    An extra array index is a number telling which element of an NPC's, slice's, etc, extra data array to read/write. (An "array" is a list of values.) The first element of the array is index 0, the second is index 1, etc, up to extra length(handle) -- 1.
    By default all slices/NPCs/etc start with a length 3 extra data array, so extra is typically a value from 0 to 2. You may also use the obsolete constants extra 0, extra 1, extra 2 which have values 0, 1, 2, if you find them more readable.
    For convenience, negative indexing like Python is also supported: the last element is index -1, the second last is index -2, down to -1 * extra length(handle) which is the first element. Negative indexing is only supported by commands that explicitly say they accept an array index.

    Script IDs

    Script IDs are used to refer to scripts, for example for set death script. Get the ID of a script by writing @name of the script, which is a constant. You can call a script using its ID instead of the normal way with run script by ID. You used to have to manually assign IDs to scripts using define script, but that's now obsolete and IDs are automatically assigned. The ID number of a script will remain the same as long as it isn't renamed, so they're safe to store in saved games. The ID 0 means no script (e.g. no death script).

    See also:

    Color codes

    A number indicating a color in the master palette. A value from 1-255 is specifies the master palette index directly. The meaning of 0 depends on the particular script command: it might mean either 'transparent' or 'the default color' or 'color 0 in the palette'. Negative values are ui:... constants, for colors defined in the User-Interface Colors editor. (You can get the master palette index for a ui: constant with get ui color.)

    Scancodes

    A scancode is a constant referring to a keyboard key, a joystick button, or is a virtual scancode for a control like use key or any key (see control codes for the full list) which is an action that can be triggered by various keys or buttons.
    The scancodes are also listed in the scancode.hsi file included with the engine.

    key:Esc
    key:F1
    key:F2
    key:F3
    ...
    key:F15          # Mac keyboards usually have 15 instead of 12 F# buttons
    
    key:Num Lock     # Tells whether numlock is on, not whether the key is down.
    key:Caps Lock    # Tells whether capslock is on, not whether the key is down.
    key:Scroll Lock  # Unreliable across different OSes/backends, avoid.
    
    key:Print Screen # Unreliable across different OSes/backends, avoid
    key:Pause        # Works for "keypress" and "new keypress" but not "key is pressed"
    
    key:1
    key:Exclamation
    key:2
    key:At Sign
    key:3
    key:Hash
    key:4
    key:Dollar Sign
    key:5
    key:6
    key:Circumflex
    key:7
    key:Ampersand
    key:8
    key:Asterisk
    key:9
    key:Left Parenthesis
    key:0
    key:Right Parenthesis
    key:Minus
    key:Underscore
    key:Equals
    key:Plus
    key:Backspace
    
    key:A
    key:B
    key:C
    ...
    key:Z
    
    key:Left Bracket     # [
    key:Left Brace       # {
    key:Right Bracket    # ]
    key:Right Brace      # }
    key:Semicolon        # ;
    key:Colon            # :
    key:Quote            # '
    key:Doublequote      # "
    key:Apostrophe       # '
    key:Backquote        # `
    key:Tilde            # ~
    key:Backslash        # \
    key:Pipe             # |
    key:Comma            # ,
    key:Left Caret       # <
    key:Period           # .
    key:Right Caret      # >
    key:Slash            # /
    key:Question Mark    # ?
    key:Enter
    key:Space
    key:Tab
    
    key:Home
    key:End
    key:Page Up
    key:Page Down
    key:Insert
    key:Delete
    
    key:Up
    key:Left
    key:Right
    key:Down
    
    key:Meta           # Either Command/Windows key
    key:Win Logo       # Equal to key:Meta
    key:Command        # Equal to key:Meta
    key:Left Meta      # Left Command/Windows key
    key:Right Meta     # Right Command/Windows key
    key:Left Win Logo  # equal to key:Left Meta
    key:Right Win Logo # equal to key:Right Meta
    key:Left Command   # Macintosh, equal to key:Left Meta
    key:Right Command  # Macintosh, equal to key:Right Meta
    key:Context        # Context Menu key, next to right Windows key on PC keyboards
    
    key:Alt            # either Alt key pressed
    key:Left Alt
    key:Right Alt
    key:Filtered Alt   # either Alt key pressed, unless a key combinations like Alt+Tab is
                       # pressed, however key presses are delayed until key release.
    key:Ctrl           # either Ctrl key pressed
    key:Left Ctrl
    key:Right Ctrl
    key:Shift          # either Shift key pressed
    key:Left Shift
    key:Right Shift
    key:Any Enter      # either Enter or Numpad Enter key pressed
    
    key:Numpad 0
    key:Numpad 1
    key:Numpad 2
    key:Numpad 3
    key:Numpad 4
    key:Numpad 5
    key:Numpad 6
    key:Numpad 7
    key:Numpad 8
    key:Numpad 9
    key:Numpad Period
    key:Numpad Asterisk
    key:Numpad Slash
    key:Numpad Plus
    key:Numpad Minus
    key:Numpad Enter
    
    #  Joystick scancodes:
    # (The following button names are only correct for supported controllers that are gamepads)
    
    # Dpad, and also translates axis:X/Y (left thumbstick on a gamepad) to button presses
    # (unless "Map joystick (left) stick to dpad" is disabled)
    joy:Left
    joy:Right
    joy:Up
    joy:Down
    
    joy:A              # B button on a SNES controller!
    joy:Cross          # Equal to joy:A
    joy:B              # A button on a SNES controller!
    joy:Circle         # Equal to joy:B
    joy:X              # Y button on a SNES controller!
    joy:Square         # Equal to joy:X
    joy:Y              # X button on a SNES controller!
    joy:Triangle       # Equal to joy:Y
    
    # Translation of right stick (axis:RightX/Y) to button presses
    joy:RStick Left
    joy:RStick Right
    joy:RStick Up
    joy:RStick Down
    
    joy:L1             # Left shoulder
    joy:R1             # Right shoulder
    joy:L2             # Left trigger. Also axis:L2
    joy:R2             # Right trigger. Also axis:R2
    
    # The thumbsticks when pressed as a button
    joy:Left Stick
    joy:Right Stick
    # Center-left button: Select (NES, SNES, PS1-3), Back (Xbox), Share (PS4), View (Xbox)
    joy:Select
    joy:Back           # Equal to joy:Select
    # Center button: PS button (PS3), Xbox guide button
    joy:Logo
    joy:Guide          # Equal to joy:Logo
    # Center-right button: Start (NES, SNES, Genesis, N64, Saturn, PS1-3, Xbox), Options (PS4), Menu (XBox)
    joy:Start
    
    # Obsolete aliases
    joy:x left         # Aka joy:Left
    joy:x right        # Aka joy:Right
    joy:y up           # Aka joy:Up
    joy:y down         # Aka joy:Down
    
    # You can use button numbers instead of the above names:
    joy:button 1
    joy:button 2
    joy:button 3
    ...
    joy:button 16
    joy:button 17      # Warning: joy:button17 is not joy:button16 + 1! All other button codes are consecutive
    ...
    joy:button 32
    
    #  Virtual scancodes:
    any key            # Any keyboard key except Numlock, Capslock and Scrolllock, or any joystick button
                       # (including joystick left/right/up/down) that has a builtin meaning like 'use'
                       # (e.g. X/Y/L1/L2/R1/R2/Select aren't included),
                       # and also any mouse button if "'any key', etc, include mouse clicks" is turned on in
    		   # the Mouse Controls menu.
    up key             # Up key on the keyboard, or on any joystick
    down key           # ...ditto
    left key
    right key
    use key            # Space, Ctrl or Enter, or A button on any gamepad. Includes left clicks
                       # if "'any key', etc, include mouse" turned on in Mouse Controls menu.
    cancel key         # Alt or Esc, or B button on any gamepad. Optionally includes right clicks as above.
    menu key           # Alt or Esc, or B or Start button on any gamepad. Optionally includes right clicks as above.
    flee key           # Esc or Tab, or B button on any gamepad (Hold to flee (run) from battle)
    run key            # Alias for 'flee key'
    
    [Notice] Previously it was necessary to include, scancode.hsi to use the key: constants, but no longer.
    [Notice] Gamepad constants like joy:A only mean what they say if the controller is a gamepad and if you're using the default gfx_sdl2 backend. All the other backends number gamepad buttons and axes unpredictably.
    [Notice] If the "Map joystick controls to keyboard keys for scripts" general preference bitset is ON (which it is by default), then checking the key:up, key:down, key:left, key:right, key:esc, key:enter keys will report true if the corresponding button on any joystick is pressed.
    [Notice] Since Zenzizenzic, keyboard support has been improved: some keys (such as key:down and key:numpad 2) which were previously the same scancode are now distinct (read scancode.hsi for the complete list). However for backwards compatibility, the old behaviour is emulated (so you won't be able to tell the two keys apart even if recompile and use the new, distinct scancodes) unless you turn off "Disable better scancodes for scripts" in the Backwards-Compatibility settings menu (in the General Game Settings menu).

    Control Codes

    Documented in the Predefined Constants section.

    Player number

    Commands for reading keyboard or joystick/gamepad input (see below) take an optional player argument which you should completely ignore unless you're making a multiplayer game. These tell which player's joystick/gamepad to check and usually shouldn't be used when reading the keyboard. Player 0 (which is always the default argument) means check all joysticks and the keyboard, as applicable, and combine their input, while player 1 and up are specific joysticks: the first joystick is player 1, etc. Out of range player numbers are always OK to use, and just report no input without showing an error. (There's currently no way to get the number of joysticks or players!)
    The keyboard is also considered to be to player 1, so scancodes like key:ctrl will always return false for players 2 and up, but control codes like use key can be used with any player.
    For example, key is pressed(use key) checks the keyboard (ctrl, space, and enter keys) and the A button on any gamepad, while key is pressed(use key, 1) checks the keyboard and A button on the first gamepad, and key is pressed(use key, 2) checks only the A button on the second gamepad.


    Glossary

    [Back to top-level index]

    ancestor (of a slice)

    A slice's parent, grandparent, great-grandparent, etc., all the way to the root. Use check parentage to see if one slice is an ancestor of another.

    descendent (of a slice)

    Any child, or grandchild, or great-grandchild, etc. of a slice. Use check parentage to see if one slice is a descendent of another.

    slice subtree

    A slice together with all of its descendents forms a slice subtree. The slice is the 'root' of the subtree. You can iterate over all the slices in a subtree (or the whole tree) with next slice in tree.

    subtree

    See slice subtree.

    expression

    An expression is any piece of code that can be evaluated to a value, which can be passed to a command or stored in a variable. Examples include numbers like 3, variables like x, formulas like 20 * x, commands or scripts which return values like NPC direction, compound expressions like hero pixel X(who + 1) / 20 and the string expressions $id="..." and $id+"..." (which return id). Flow control (if, switch, etc) as well as variable are statements, not expressions.
    := expressions like x := 3 can also be used as expressions, but it's often considered poor taste to do so.


    Predefined Constants

    [Back to top-level index]

    This section only lists constants which can be used for multiple commands. There are many other builtin constants, but they're documented along with the commands they're for.

    Control Codes

    A constant specifying a keyboard key or joystick button by its builtin function. (Possibly includes mouse buttons too, if enabled in the Mouse Controls menu.) They can be passed to key is pressed, keyval, wait for key, keypress, new keypress and wait for scancode.
    Previously these could only be used with the wait for key command, but that's changed!
    Possible values:
    any key, up key, down key, left key, right key, use key, menu key, cancel key, flee key, run key.
    (flee key and run key are different names for the same constant; menu key and cancel key used to be the same but are now different: the Start button on a gamepad is a menu key.)

    [Notice] All commands which accept a key constant can also accept a scancode (like key:enter) instead. See scancode.

    Key Constants

    An alias for control codes.

    Numeric Constants

    There are pre-defined constants for the numbers from 0 to 10. You can use these constants to make your scripts look friendly :)
    zero, one, two, three, four, five, six, seven, eight, nine, ten

    Boolean Constants

    There are constants are named true and false, and for on and off. These are useful for checking and setting the values of tags, and in conditional statements. true/on are equal to 1, false/off are equal to 0.

    Directions

    A direction is a value 0-3 used by commands such as walk hero and walk NPC, which goes clockwise from north:
    north = up = 0
    east = right = 1
    south = down = 2
    west = left = 3
    You can convert a direction into relative X and Y values using the dir X and dir Y functions.

    me

    me is a constant that can be used to refer to the first hero in your caterpillar party (hero zero) in any command that takes a caterpillar party rank as an argument. It is equal to zero. You can't write me where a hero party slot or hero ID is needed! See Ways to refer to a hero in a script.

    none

    none is a constant that means the same as zero.

    autonumber

    autonumber is an obsolete constant that is used as the ID number in old-style define script commands. This is not needed anymore. Use script instead.

    current stat

    A constant for use with the get hero stat, set hero stat, set capped hero stat and get level MP commands.
    The current value of a stat is what is normally used. The current value of stats other than HP or MP is usually equal to the maximum value, except due to temporary buffs or debuffs in-battle (which wear off after the end of the battle) or if modified with set hero stat. Both maximum and current values of a stat are normally limited to the stat cap.

    maximum stat

    A constant for use with the get hero stat, set hero stat, set capped hero stat and get level MP commands.
    The maximum value of a stat is used for limiting it (such as for curing items) and for resetting it, such as on levelup or at an inn (if enabled by the game's general bitsets). See current stat for more information. Both maximum and current values of a stat are normally limited to the stat cap.

    base stat

    A constant for use with the get hero stat, set hero stat and set capped hero stat commands.
    The base value of a stat is not displayed anywhere in-game, but tracks the value of a hero's stat without their equipment or stat caps taken into account. In other words the base value of a stat can continue to grow as a hero levels even if the current and max values have hit the cap. Hint: you can press F4 in the Status menu to display the base values of each stat in brackets.

    inside battle

    outside battle

    hero portrait

    A constant used in the get hero picture, set hero picture, get hero palette, set hero palette, reset hero picture and reset hero palette commands:

    Color Constants

    Constants for each of the three primary colors are used in commands like read color or write color:
    color:red, color:green, color:blue

    Mouse Constants

    The following constants are for use with the mouse functions such as mouse button.
    left button, middle button, right button

    get count

    When passed to NPC at pixel, NPC at spot, slice at pixel, find colliding slice or zone at spot they return the number of NPCs, slices or zones at that spot. With spells learned returns the number of spells a hero learnt. With find enemy in formation, returns the number of enemies, or the number of some kind of enemy in the formation.

    Wall Bit Constants

    The following constants are for use with functions like read pass block or write pass block:
    north wall, east wall, south wall, west wall, vehicle A, vehicle B, harm tile, overhead tile

    crop

    A constant used in set map edge mode which makes the edges of the map impassible and prevents the camera from scrolling off them.

    wrap

    A constant used in set map edge mode which lets the player walk over the edge of the map around to the opposite side.

    default tile

    A constant used in set map edge mode which makes the edges of the map impassible and displays a specified tile everywhere off the edge of the map.

    party

    Pass as first argument to give experience to divide the experience between all the live heroes in the battle (active) party.

    timer: default

    Pass to set timer to leave one of the parameters at its default setting. Valid for any parameter except id

    timer: game over

    Pass to set timer in the trigger field to have the game end when the timer runs out.

    timer flag: critical

    Pass to set timer in the flags field to indicate that if the timer runs out during a battle, it should end the battle immediately.

    timer flag: battle

    Pass to set timer in the flags field to indicate that the timer should run during battle. Otherwise, the timer will be paused during battle.

    timer flag: menu

    Pass to set timer in the flags field to indicate that the timer should run while the player is in the menu. Otherwise, it will be paused while the player is in the main menu.

    song: silence

    Used with set formation song and get formation song to indicate an enemy formation without music. Used by set ambient music and get ambient music for a silent map.

    song: same as last map

    Alias:

    song: same as map

    Used with set formation song and get formation song to indicate an enemy formation which uses the same music as the map. Used by set ambient music and get ambient music for a map that continues with the last map's music.


    Stats: There are 967 commands (of which 15 are aliases), 27 constants and 19 definitions of types and other terms in this file.

    This file was generated from an XML file. The contents were painstakingly transcribed by Mike Caron from the original Plotscripting Dictionary, which was created by James Paige.