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 output parameters, which are marked by the 'out' modifier.
Output parameters are optional, and you may omit them if you don't need the value they return. 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 |
col(color) |
draw col color 0 0 0 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) Deprecated. Use config instead. |
control config block value 0 0 0 |
block.config(value) |
control config block value 0 0 0 |
block.configure = value Deprecated. Use config instead. |
control config block value 0 0 0 |
block.config = value |
control config block value 0 0 0 |
block.color(packedColor) |
control color block packedColor 0 0 0 |
block.color = packedColor |
control color block packedColor 0 0 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 = angleDiff(a, b) |
op angleDiff 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 |
result = asin(a) |
op asin result a 0 |
result = acos(a) |
op acos result a 0 |
result = atan(a) |
op atan result a 0 |
Look up an item/liquid/unit/block type by ID. Total counts of each type can be accessed with @unitCount, @itemCount, @liquidCount, @blockCount.
Function call | Generated instruction |
---|---|
result = lookup(:type, index) |
lookup type result index |
Pack [0, 1] RGBA components into a single number for drawing or rule-setting.
Function call | Generated instruction |
---|---|
result = packcolor(r, g, b, a) |
packcolor result r g b a |
Wait a certain number of seconds.
Function call | Generated instruction |
---|---|
wait(sec) |
wait sec |
Halt execution of this processor.
Function call | Generated instruction |
---|---|
stopProcessor() |
stop |
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 |
autoPathfind() |
ucontrol autoPathfind 0 0 0 0 0 |
pathfind(x, y) |
ucontrol pathfind x y 0 0 0 |
boost(enable) |
ucontrol boost enable 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 |
payEnter() |
ucontrol payEnter 0 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 |
building = getBlock(x, y, out type, out floor) |
ucontrol getBlock x y type building floor |
result = within(x, y, radius) |
ucontrol within x y radius result 0 |
unbind() |
ucontrol unbind 0 0 0 0 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, out outx, out outy) |
ulocate ore core true oreType outx outy found 0 |
building = ulocate(:building, :group, enemy, out outx, out outy, out found) |
ulocate building group enemy @copper outx outy found building |
building = ulocate(:spawn, out outx, out outy, out found) |
ulocate spawn core true @copper outx outy found building |
building = ulocate(:damaged, out outx, out outy, out found) |
ulocate damaged core true @copper outx outy found building |
These instructions are only available to the World Processor, which can be placed in custom-created levels in Mindustry 7 or higher.
Get tile data at any location.
Function call | Generated instruction |
---|---|
result = getblock(:layer, x, y) |
getblock layer result x y |
Set tile data at any location.
Function call | Generated instruction |
---|---|
setblock(:floor, to, x, y) |
setblock floor to x y 0 0 |
setblock(:ore, to, x, y) |
setblock ore to x y 0 0 |
setblock(:block, to, x, y, team, rotation) |
setblock block to x y team rotation |
Spawn unit at a location.
Function call | Generated instruction |
---|---|
result = spawn(unit, x, y, rotation, team) |
spawn unit x y rotation team result |
Apply or clear a status effect from a unit.
Function call | Generated instruction |
---|---|
applyStatus(:status, unit, duration) |
status false status unit duration |
clearStatus(:status, unit) |
status true status unit 0 |
Spawn a wave.
Function call | Generated instruction |
---|---|
spawnwave(x, y, natural) |
spawnwave x y natural |
Set a game rule.
Function call | Generated instruction |
---|---|
setrule(:currentWaveTime, value) |
setrule currentWaveTime value 0 0 0 0 |
setrule(:waveTimer, value) |
setrule waveTimer value 0 0 0 0 |
setrule(:waves, value) |
setrule waves value 0 0 0 0 |
setrule(:wave, value) |
setrule wave value 0 0 0 0 |
setrule(:waveSpacing, value) |
setrule waveSpacing value 0 0 0 0 |
setrule(:waveSending, value) |
setrule waveSending value 0 0 0 0 |
setrule(:attackMode, value) |
setrule attackMode value 0 0 0 0 |
setrule(:enemyCoreBuildRadius, value) |
setrule enemyCoreBuildRadius value 0 0 0 0 |
setrule(:dropZoneRadius, value) |
setrule dropZoneRadius value 0 0 0 0 |
setrule(:unitCap, value) |
setrule unitCap value 0 0 0 0 |
setrule(:mapArea, x, y, width, height) |
setrule mapArea 0 x y width height |
setrule(:lighting, value) |
setrule lighting value 0 0 0 0 |
setrule(:ambientLight, value) |
setrule ambientLight value 0 0 0 0 |
setrule(:solarMultiplier, value) |
setrule solarMultiplier value 0 0 0 0 |
setrule(:buildSpeed, value, team) |
setrule buildSpeed value team 0 0 0 |
setrule(:unitHealth, value, team) |
setrule unitHealth value team 0 0 0 |
setrule(:unitBuildSpeed, value, team) |
setrule unitBuildSpeed value team 0 0 0 |
setrule(:unitCost, value, team) |
setrule unitCost value team 0 0 0 |
setrule(:unitDamage, value, team) |
setrule unitDamage value team 0 0 0 |
setrule(:blockHealth, value, team) |
setrule blockHealth value team 0 0 0 |
setrule(:blockDamage, value, team) |
setrule blockDamage value team 0 0 0 |
setrule(:rtsMinWeight, value, team) |
setrule rtsMinWeight value team 0 0 0 |
setrule(:rtsMinSquad, value, team) |
setrule rtsMinSquad value team 0 0 0 |
Display a message on the screen from the text buffer. If the success result variable is @wait, will wait until the previous message finishes. Otherwise, outputs whether displaying the message succeeded.
Function call | Generated instruction |
---|---|
message(:notify) |
message notify 0 |
message(:mission) |
message mission 0 |
message(:announce, duration) |
message announce duration |
message(:toast, duration) |
message toast duration |
Manipulate the player camera.
Function call | Generated instruction |
---|---|
cutscene(:pan, x, y, speed) |
cutscene pan x y speed 0 |
cutscene(:zoom, level) |
cutscene zoom level 0 0 0 |
cutscene(:stop) |
cutscene stop 0 0 0 0 |
Create a particle effect.
Function call | Generated instruction |
---|---|
effect(:warn, x, y) |
effect warn x y 0 0 0 |
effect(:cross, x, y) |
effect cross x y 0 0 0 |
effect(:blockFall, x, y, blocktype) |
effect blockFall x y 0 0 blocktype |
effect(:placeBlock, x, y, size) |
effect placeBlock x y size 0 0 |
effect(:placeBlockSpark, x, y, size) |
effect placeBlockSpark x y size 0 0 |
effect(:breakBlock, x, y, size) |
effect breakBlock x y size 0 0 |
effect(:spawn, x, y) |
effect spawn x y 0 0 0 |
effect(:trail, x, y, size, color) |
effect trail x y size color 0 |
effect(:breakProp, x, y, size, color) |
effect breakProp x y size color 0 |
effect(:smokeCloud, x, y, color) |
effect smokeCloud x y 0 color 0 |
effect(:vapor, x, y, color) |
effect vapor x y 0 color 0 |
effect(:hit, x, y, color) |
effect hit x y 0 color 0 |
effect(:hitSquare, x, y, color) |
effect hitSquare x y 0 color 0 |
effect(:shootSmall, x, y, rotation, color) |
effect shootSmall x y rotation color 0 |
effect(:shootBig, x, y, rotation, color) |
effect shootBig x y rotation color 0 |
effect(:smokeSmall, x, y, color) |
effect smokeSmall x y 0 color 0 |
effect(:smokeBig, x, y, color) |
effect smokeBig x y 0 color 0 |
effect(:smokeColor, x, y, rotation, color) |
effect smokeColor x y rotation color 0 |
effect(:smokeSquare, x, y, rotation, color) |
effect smokeSquare x y rotation color 0 |
effect(:smokeSquareBig, x, y, rotation, color) |
effect smokeSquareBig x y rotation color 0 |
effect(:spark, x, y, color) |
effect spark x y 0 color 0 |
effect(:sparkBig, x, y, color) |
effect sparkBig x y 0 color 0 |
effect(:sparkShoot, x, y, rotation, color) |
effect sparkShoot x y rotation color 0 |
effect(:sparkShootBig, x, y, rotation, color) |
effect sparkShootBig x y rotation color 0 |
effect(:drill, x, y, color) |
effect drill x y 0 color 0 |
effect(:drillBig, x, y, color) |
effect drillBig x y 0 color 0 |
effect(:lightBlock, x, y, size, color) |
effect lightBlock x y size color 0 |
effect(:explosion, x, y, size) |
effect explosion x y size 0 0 |
effect(:smokePuff, x, y, color) |
effect smokePuff x y 0 color 0 |
effect(:sparkExplosion, x, y, color) |
effect sparkExplosion x y 0 color 0 |
effect(:crossExplosion, x, y, size, color) |
effect crossExplosion x y size color 0 |
effect(:wave, x, y, size, color) |
effect wave x y size color 0 |
effect(:bubble, x, y) |
effect bubble x y 0 0 0 |
Create an explosion at a location.
Function call | Generated instruction |
---|---|
explosion(team, x, y, radius, damage, air, ground, pierce) |
explosion team x y radius damage air ground pierce |
Set processor execution speed in instructions/tick.
Function call | Generated instruction |
---|---|
setrate(ipt) |
setrate ipt |
Lookup units, cores, players or buildings by index. Indices start at 0 and end at their returned count.
Function call | Generated instruction |
---|---|
result = fetch(:unitCount, team, type) |
fetch unitCount result team 0 type |
result = fetch(:playerCount, team) |
fetch playerCount result team 0 0 |
result = fetch(:coreCount, team) |
fetch coreCount result team 0 0 |
result = fetch(:buildCount, team, type) |
fetch buildCount result team 0 type |
result = fetch(:unit, team, index, type) |
fetch unit result team index type |
result = fetch(:player, team, index) |
fetch player result team index 0 |
result = fetch(:core, team, index) |
fetch core result team index 0 |
result = fetch(:build, team, index, type) |
fetch build result team index type |
Sync a variable across the network. Limited to 20 times a second per variable.
Function call | Generated instruction |
---|---|
sync(out var) |
sync var |
Check if a global flag is set.
Function call | Generated instruction |
---|---|
result = getflag(flag) |
getflag result flag |
Set a global flag that can be read by all processors.
Function call | Generated instruction |
---|---|
setflag(flag, value) |
setflag flag value |
Sets a property of a unit or building.
Function call | Generated instruction |
---|---|
object.setprop(property, value) |
setprop property object value |
« Previous: Function reference for Mindustry Logic 7.0 | Up: Contents | Next: Function reference for Mindustry Logic 8.0 »