This document contains function reference for all built-in Mindcode functions. Functions are grouped by the instruction they encapsulate, so that functions with similar logic are listed together. The Mindcode source listed in the Function call column is compiled to the instruction in the Generated instruction column.
In some cases, a single instruction can be generated in more than one way (e.g. the radar
instruction,
which can be written as a turret.radar
function, or as a radar
function which takes turret
as a parameter).
Both ways are identical. Additionally, some functions have optional parameters, which are marked by
a question mark (e.g. building?
). Only output parameters are optional, and you may omit them if you don't
need the value they return. When omitted, the optional parameter is replaced by an unused temporary variable.
Mindcode allows you to omit all optional argument, but in this case the entire instruction will be considered
useless and may be removed by the optimizer.
Add an operation to the drawing buffer. Does not display anything until drawflush is used.
Function call | Generated instruction |
---|---|
clear(r, g, b) |
draw clear r g b 0 0 0 |
color(r, g, b, a) |
draw color r g b a 0 0 |
stroke(width) |
draw stroke width 0 0 0 0 0 |
line(x, y, x2, y2) |
draw line x y x2 y2 0 0 |
rect(x, y, width, height) |
draw rect x y width height 0 0 |
lineRect(x, y, width, height) |
draw lineRect x y width height 0 0 |
poly(x, y, sides, radius, rotation) |
draw poly x y sides radius rotation 0 |
linePoly(x, y, sides, radius, rotation) |
draw linePoly x y sides radius rotation 0 |
triangle(x, y, x2, y2, x3, y3) |
draw triangle x y x2 y2 x3 y3 |
image(x, y, image, size, rotation) |
draw image x y image size rotation 0 |
Add text to the print buffer. Does not display anything until printflush is used.
Function call | Generated instruction |
---|---|
print(what) |
print what |
Flush queued Draw operations to a display.
Function call | Generated instruction |
---|---|
display1.drawflush() |
drawflush display1 |
drawflush(display1) |
drawflush display1 |
Flush queued Print operations to a message block.
Function call | Generated instruction |
---|---|
message1.printflush() |
printflush message1 |
printflush(message1) |
printflush message1 |
Get a processor link by index. Starts at 0.
Function call | Generated instruction |
---|---|
block = getlink(linkNum) |
getlink block linkNum |
Control a building.
Function call | Generated instruction |
---|---|
block.enabled(value) |
control enabled block value 0 0 0 |
block.enabled = value |
control enabled block value 0 0 0 |
block.shoot(x, y, shoot) |
control shoot block x y shoot 0 |
block.shootp(unit, shoot) |
control shootp block unit shoot 0 0 |
block.configure(value) |
control configure block value 0 0 0 |
block.configure = value |
control configure block value 0 0 0 |
block.color(r, g, b) |
control color block r g b 0 |
Locate units around a building with range.
Function call | Generated instruction |
---|---|
result = turret.radar(attr1, attr2, attr3, sort, order) |
radar attr1 attr2 attr3 sort turret order result |
result = radar(attr1, attr2, attr3, sort, turret, order) |
radar attr1 attr2 attr3 sort turret order result |
Get data from a building or unit.
Function call | Generated instruction |
---|---|
result = object.sensor(property) |
sensor result object property |
Perform an operation on 1-2 variables.
Function call | Generated instruction |
---|---|
result = max(a, b) |
op max result a b |
result = min(a, b) |
op min result a b |
result = angle(a, b) |
op angle result a b |
result = len(a, b) |
op len result a b |
result = noise(a, b) |
op noise result a b |
result = abs(a) |
op abs result a 0 |
result = log(a) |
op log result a 0 |
result = log10(a) |
op log10 result a 0 |
result = floor(a) |
op floor result a 0 |
result = ceil(a) |
op ceil result a 0 |
result = sqrt(a) |
op sqrt result a 0 |
result = rand(a) |
op rand result a 0 |
result = sin(a) |
op sin result a 0 |
result = cos(a) |
op cos result a 0 |
result = tan(a) |
op tan result a 0 |
Jump to the top of the instruction stack.
Function call | Generated instruction |
---|---|
end() |
end |
Bind to the next unit of a type, and store it in @unit.
Function call | Generated instruction |
---|---|
unit = ubind(type) |
ubind type |
Control the currently bound unit.
Function call | Generated instruction |
---|---|
idle() |
ucontrol idle 0 0 0 0 0 |
stop() |
ucontrol stop 0 0 0 0 0 |
move(x, y) |
ucontrol move x y 0 0 0 |
approach(x, y, radius) |
ucontrol approach x y radius 0 0 |
boost(enable) |
ucontrol boost enable 0 0 0 0 |
pathfind() |
ucontrol pathfind 0 0 0 0 0 |
target(x, y, shoot) |
ucontrol target x y shoot 0 0 |
targetp(unit, shoot) |
ucontrol targetp unit shoot 0 0 0 |
itemDrop(to, amount) |
ucontrol itemDrop to amount 0 0 0 |
itemTake(from, item, amount) |
ucontrol itemTake from item amount 0 0 |
payDrop() |
ucontrol payDrop 0 0 0 0 0 |
payTake(takeUnits) |
ucontrol payTake takeUnits 0 0 0 0 |
mine(x, y) |
ucontrol mine x y 0 0 0 |
flag(value) |
ucontrol flag value 0 0 0 0 |
build(x, y, block, rotation, config) |
ucontrol build x y block rotation config |
getBlock(x, y, type?, building?) |
ucontrol getBlock x y type building 0 |
result = within(x, y, radius) |
ucontrol within x y radius result 0 |
Locate units around the currently bound unit.
Function call | Generated instruction |
---|---|
result = uradar(attr1, attr2, attr3, sort, order) |
uradar attr1 attr2 attr3 sort 0 order result |
Locate a specific type of position/building anywhere on the map. Requires a bound unit.
Function call | Generated instruction |
---|---|
found = ulocate(ore, oreType, outx?, outy?) |
ulocate ore core true oreType outx outy found 0 |
found = ulocate(building, group, enemy, outx?, outy?, building?) |
ulocate building group enemy @copper outx outy found building |
found = ulocate(spawn, outx?, outy?, building?) |
ulocate spawn core true @copper outx outy found building |
found = ulocate(damaged, outx?, outy?, building?) |
ulocate damaged core true @copper outx outy found building |
« Previous: Code optimization | Next: Function reference for Mindustry Logic 7 »