bitwizard simplified bit manipulation & other tools for mindustry logic // mixed mlog and custom ops
Important information:
- The comment character "#" must be escaped with a "\" prefix to be used outside the commenting context
Important information:
main instruction / instruction set | sub instruction | parameters | purpose & details | example |
---|---|---|---|---|
timer | new | name, duration in ms | create and start a timer | timer new BakePretzelTimer 1200000 |
loop | name | determine the line of code a timer should jump to if it's not expired (the line below) | timer loop BakePretzelTimer op add becomeImpatient becomeImpatient 1 |
|
extend | name, duration in ms | extend a timer | timer extend BakePretzelTimer 60000 | |
close | close the most recently created timer | timer new Wait2secs 2000 timer loop Wait2secs timer close |
||
consistent (alias: con) | disables line count optimization for instructions below this tag | consistent spl of value SomeRandomSplit 0 #becomes 2 lines instead of 1 for given index 0 due to line count consistency |
||
inconsistent (alias: incon) | enables line count optimization for instructions below this tag, is the default setting | incon spl of value SomeRandomSplit 0 #output is back to default 1 line |
||
tickbarrier (tickbar, tick) | halts execution until the current tick elapses | tickbar op add ticks ticks 1 # works best with fast processors |
||
expect | building links | prevents the processor from finishing initialization if the provided links aren't valid | expect switch1 display1 message1 | |
memorylabel (memlabel) | memory block reference, labels... | allows giving memory slots names without impacting performance | memlabel vitaminContents 0:A 1:B12 2:C read vitaminA vitaminContents A read vitaminC vitaminContents C |
|
spl* | new | target variable name, reference name, bitranges... | create a bit splitter for a variable that may access at most 52 bits | spl new bytes Bytes 8 8 8 8 8 8 #splits 'bytes' into 6 actual bytes |
label functionality: you can give names to your bitranges by joining the name and the value with a colon | spl new bits Bits 1:bit1 1:bit2 1:bit3 1:bit4 | |||
target variable name, reference, step, a syntactical "*", amount of bitranges | if you want to save on the line count you'll like to take a more calculative approach to splitters like here | spl new bits Bits 1 * 16 | ||
label functionality jr: give your bitranges names, this time by index | spl new bytes Bytes 8 * 4 0:byte1 2:byte3 3:byte4 | |||
label | splitter reference, labels... | you can also set the labels in a separate line if you like, good for managing a LOT of wordy labels on multiple lines | spl new moreAndMoreBits MoreAndMoreBits 1 2 3 4 5 6 7 8 9 10 spl label MoreAndMoreBits 0:OneBit 1:TwoBits 2:ThreeBits 3:FourBits 4:FiveBits spl label MoreAndMoreBits 5:SixBits 6:SevenBits 7:EightBits 8:NineBits 9:TenBits |
|
obtainf* (of) | output variable, splitter reference, constant bitrange index | get the range of bits of a splitter's target variable at a constant index | spl obtainf a Bytes 1 #gets the 2nd range of bits in 'Bytes' | |
obtaind (od) | output variable, splitter reference, bitrange index | get the range of bits of a splitter's target variable at an index that may be determined in runtime this generates a lot more code than obtainf so don't use it when you don't need to define the bitrange index in runtime |
spl obtaind a Bytes x #gets the x-th range of bits in 'Bytes' | |
clearf (cf) | splitter reference, constant bitrange index | clear the range of bits of a splitter's target variable at a constant index | spl clearf Bytes 3 #clears the 4th range of bits in 'Bytes' | |
cleard (cd) | splitter reference, bitrange index | clear the range of bits of a splitter's target variable at an index that may be determined in runtime this generates a lot more code than clearf so don't use it when you don't need to define the bitrange index in runtime |
spl cleard Bytes x #clears the x-th range of bits in 'Bytes' | |
writef* (wf) | input, splitter reference, constant bitrange index | write to the range of bits of a splitter's target variable at a constant index | spl writef 0b10100101 Bytes 3 #writes a number to the 4th range of bits in 'Bytes' | |
writef-* (wf-) | input, splitter reference, constant bitrange index | write to the range of bits of a splitter's target variable at a constant index "reduced write", does not spend processing power clearing the destination before writing to it |
spl wf- 0b10100101 Bytes 3 #writes a number to the 4th range of bits in 'Bytes' | |
writed* (wd) | input, splitter reference, bitrange index | write to the range of bits of a splitter's target variable at an index that may be determined in runtime this generates a lot more code than writef so don't use it when you don't need to define the bitrange index in runtime |
spl writed 0xFF Bytes x #writes a number to the x-th range of bits in 'Bytes' | |
writed-* (wd-) | input, splitter reference, bitrange index | write to the range of bits of a splitter's target variable at an index that may be determined in runtime this generates a lot more code than writef so don't use it when you don't need to define the bitrange index in runtime "reduced write", does not spend processing power clearing the destination before writing to it |
spl wd- 0xFF Bytes x #writes a number to the x-th range of bits in 'Bytes' | |
using bitrange labels | you can make use of bitrange labels with fast splitter methods in place of bitrange indices: | spl new bytes Bytes 8 * 2 0:Byte1 spl obtainf byte Bytes Byte1 spl clearf byte Bytes Byte1 spl writef 0xFF Bytes Byte1 |
||
fun | new | name | declare a new function | fun new ConstructingAdditionalPylons |
close | close the most recently declared function | fun close | ||
have / call | function name, (condition, comparand 1, comparand 2) | have fun™ / call a function, optionally when a given condition is met | fun have ConstructingAdditionalPylons >= resources enough | |
uflag | (empty) | flag value | set @unit's flag to the provided flag value | uflag 64 #so much shorter |
get | unit type, flag value search, (escape conditions...) | will try to bind @unit to an UNCONTROLLED unit of the provided unit type, with the specified flag; @unit escape conditions may be used to break out of the loop | uflag get @oct 0 === null jump noOctsPresent equal @unit null # makes use of escape conditions to tell whether a unit of a unit type is present |
|
get any | unit type, flag value search, (escape conditions...) | will try to bind @unit to ANY unit of the provided unit type, with the specified flag; once again, @unit escape conditions may be used to break out of the loop | uflag get any @quad 0 uflag 69 |
|
await | unit reference, (condition), flag value, (intermediary function calls...) | causes the processor to loop until @unit's flag meets the specified condition ("equal" by default) | set signal 6942069420 uflag signal uflag await @unit not signal # this is how to do the network |
|
test | unit reference, condition, output variable | test's @unit's flag for the specified condition | uflag test @unit == 0 lol | |
verify | unit reference, jump target OR function name | will (call / jump to) the specified target if @unit is A. dead B. controlled by another processor |
myLabel: uflag get any @flare 0 wait 5s uflag verify @unit myLabel |
|
log2 | output, input | get the base 2 logarithm of a number; automatically defines LN2 if necessary | log2 x 16 | |
define | LN2 | define a variable 'LN2' as the natural logarithm of 2 at the start of your code | define LN2 print LN2 printf message1 #gimme ln2 |
|
LN16 | define a variable 'LN16' as the natural logarithm of 16 at the start of your code | define LN16 | ||
PI | define a variable 'PI' as a 16-digit approximate of pi at the start of your code | define PI | ||
parray | variable (used as index) | create a pointer array | parray a | |
/ | close one case of a pointer array that isn't the last case | parr fruit set x "apple" / set x "orange" // |
||
// | close the last case of a pointer array (defines the size of it) | parr car set x "King Kai's car" / set x "some burning Tesla vehicle in China" // |
||
for | variable, (optional = assignment), conditional operator, condition right side, (!recommended! increment value) | create a for loop to be used in conjunction with 'next' | for x = y != 10 z next |
|
next | close the most recently created for loop | for x not 10 1 next |
*: in part or wholly affected by line inconsistency and the 'consistent' tag