Skip to content

Latest commit

 

History

History
511 lines (380 loc) · 52.2 KB

FUNCTIONS_V8A.markdown

File metadata and controls

511 lines (380 loc) · 52.2 KB

Function reference for Mindustry V8A

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.

Micro Processor, Logic Processor and Hyper Processor

Instruction draw

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
drawPrint(x, y, align) draw print x y align 0 0 0
translate(x, y) draw translate x y 0 0 0 0
scale(x, y) draw scale x y 0 0 0 0
rotate(degrees) draw rotate 0 0 degrees 0 0 0
reset() draw reset 0 0 0 0 0 0

Instruction print

Add text to the print buffer. Does not display anything until printflush is used.

Function call                                                                                 Generated instruction                                                  
print(what) print what

Instruction format

Replace next placeholder in text buffer with a value. Does not do anything if placeholder pattern is invalid. Placeholder pattern: "{number 0-9}" Example: print "test {0}"; format "example"

Function call                                                                                 Generated instruction                                                  
format(value) format value

Instruction drawflush

Flush queued Draw operations to a display.

Function call                                                                                 Generated instruction                                                  
display1.drawflush() drawflush display1
drawflush(display1) drawflush display1

Instruction printflush

Flush queued Print operations to a message block.

Function call                                                                                 Generated instruction                                                  
message1.printflush() printflush message1
printflush(message1) printflush message1

Instruction getlink

Get a processor link by index. Starts at 0.

Function call                                                                                 Generated instruction                                                  
block = getlink(linkNum) getlink block linkNum

Instruction control

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(r, g, b) control color block r g b 0

Instruction radar

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

Instruction sensor

Get data from a building or unit.

Function call                                                                                 Generated instruction                                                  
result = object.sensor(property) sensor result object property

Instruction op

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

Instruction lookup

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

Instruction packcolor

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

Instruction wait

Wait a certain number of seconds.

Function call                                                                                 Generated instruction                                                  
wait(sec) wait sec

Instruction stop

Halt execution of this processor.

Function call                                                                                 Generated instruction                                                  
stopProcessor() stop

Instruction end

Jump to the top of the instruction stack.

Function call                                                                                 Generated instruction                                                  
end() end

Instruction ubind

Bind to the next unit of a type, and store it in @unit.

Function call                                                                                 Generated instruction                                                  
unit = ubind(type) ubind type

Instruction ucontrol

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, type?, 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

Instruction uradar

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

Instruction ulocate

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
building = ulocate(building, group, enemy, outx?, outy?, found?) ulocate building group enemy @copper outx outy found building
building = ulocate(spawn, outx?, outy?, found?) ulocate spawn core true @copper outx outy found building
building = ulocate(damaged, outx?, outy?, found?) ulocate damaged core true @copper outx outy found building

World processor

These instructions are only available to the World Processor, which can be placed in custom-created levels in Mindustry 7.

Instruction getblock

Get tile data at any location.

Function call                                                                                 Generated instruction                                                  
result = getblock(layer, x, y) getblock layer result x y

Instruction setblock

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

Instruction spawn

Spawn unit at a location.

Function call                                                                                 Generated instruction                                                  
result = spawn(unit, x, y, rotation, team) spawn unit x y rotation team result

Instruction status

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

Instruction weathersense

Check if a type of weather is active.

Function call                                                                                 Generated instruction                                                  
result = weathersense(weather) weathersense result weather

Instruction weatherset

Set the current state of a type of weather.

Function call                                                                                 Generated instruction                                                  
weatherset(weather, active) weatherset weather active

Instruction spawnwave

Spawn a wave.

Function call                                                                                 Generated instruction                                                  
spawnwave(x, y, natural) spawnwave x y natural

Instruction setrule

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

Instruction message

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, success?) message notify 0 success
message(mission, success?) message mission 0 success
message(announce, duration, success?) message announce duration success
message(toast, duration, success?) message toast duration success

Instruction cutscene

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

Instruction effect

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

Instruction explosion

Create an explosion at a location.

Function call                                                                                 Generated instruction                                                  
explosion(team, x, y, radius, damage, air, ground, pierce, effect) explosion team x y radius damage air ground pierce effect

Instruction setrate

Set processor execution speed in instructions/tick.

Function call                                                                                 Generated instruction                                                  
setrate(ipt) setrate ipt

Instruction fetch

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) fetch unitCount result team 0 0
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) fetch unit result team index 0
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

Instruction sync

Sync a variable across the network. Limited to 20 times a second per variable.

Function call                                                                                 Generated instruction                                                  
sync(var?) sync var

Instruction getflag

Check if a global flag is set.

Function call                                                                                 Generated instruction                                                  
result = getflag(flag) getflag result flag

Instruction setflag

Set a global flag that can be read by all processors.

Function call                                                                                 Generated instruction                                                  
setflag(flag, value) setflag flag value

Instruction setprop

Sets a property of a unit or building.

Function call                                                                                 Generated instruction                                                  
object.setprop(property, value) setprop property object value

Instruction playsound

Plays a sound. Volume and pan can be a global value, or calculated based on position.

Function call                                                                                 Generated instruction                                                  
playsound(true, sound, volume, pitch, x, y, limit) playsound true sound volume pitch 0 x y limit
playsound(false, sound, volume, pitch, pan, limit) playsound false sound volume pitch pan 0 0 limit

Instruction setmarker

Set a property for a marker. The ID used must be the same as in the Make Marker instruction. null values are ignored.

Function call                                                                                 Generated instruction                                                  
setmarker(remove, id) setmarker remove id 0 0 0
setmarker(world, id, boolean) setmarker world id boolean 0 0
setmarker(minimap, id, boolean) setmarker minimap id boolean 0 0
setmarker(autoscale, id, boolean) setmarker autoscale id boolean 0 0
setmarker(pos, id, x, y) setmarker pos id x y 0
setmarker(endPos, id, x, y) setmarker endPos id x y 0
setmarker(drawLayer, id, layer) setmarker drawLayer id layer 0 0
setmarker(color, id, color) setmarker color id color 0 0
setmarker(radius, id, radius) setmarker radius id radius 0 0
setmarker(stroke, id, stroke) setmarker stroke id stroke 0 0
setmarker(rotation, id, rotation) setmarker rotation id rotation 0 0
setmarker(shape, id, sides, fill, outline) setmarker shape id sides fill outline
setmarker(arc, id, from, to) setmarker arc id from to 0
setmarker(flushText, id, fetch) setmarker flushText id fetch 0 0
setmarker(fontSize, id, size) setmarker fontSize id size 0 0
setmarker(textHeight, id, height) setmarker textHeight id height 0 0
setmarker(labelFlags, id, background, outline) setmarker labelFlags id background outline 0
setmarker(texture, id, printFlush, name) setmarker texture id printFlush name 0
setmarker(textureSize, id, width, height) setmarker textureSize id width height 0
setmarker(posi, id, index, x, y) setmarker posi id index x y
setmarker(uvi, id, index, x, y) setmarker uvi id index x y
setmarker(colori, id, index, color) setmarker colori id index color 0

Instruction makemarker

Create a new logic marker in the world. An ID to identify this marker must be provided. Markers currently limited to 20,000 per world.

Function call                                                                                 Generated instruction                                                  
makemarker(marker, id, x, y, replace) makemarker marker id x y replace

Instruction localeprint

Add map locale property value to the text buffer. To set map locale bundles in map editor, check Map Info > Locale Bundles. If client is a mobile device, tries to print a property ending in ".mobile" first.

Function call                                                                                 Generated instruction                                                  
localeprint(property) localeprint property

« Previous: Function reference for Mindustry Logic 7A   |   Next: Mindustry 8 »