Macro variables
A variable is a value a macro remembers while it runs: the cheapest listing on an auction page, the number in a /balance reply, how many times the bot has died. A Set variable step stores one, {name} writes it into a chat message or a webhook, and an If or a loop compares it. A For each loop fills one too, with the player, block, entity, item or value it is on.
Variables need Tier 3, like every Logic step. Each account running a macro has its own, and they start empty every time the macro runs, unless a step keeps them for the next run.
Set variable
Set variable is in the step picker's Logic group. Every Set variable step has two fields:
- Call it is the variable's name: letters, numbers and underscores only, starting with a letter, up to 32 characters. Capitals turn into lower case as you type. A name that breaks the rule turns the card grey, and the step will not run.
- Set it to is where the value comes from, one of the five sources below.
Setting a name that already holds a value replaces it, so a later step can count up a variable an earlier one started.
Something on the open screen
Reads the items in an open container and in the bot's own inventory, and keeps one of them: the cheapest listing on an auction page, the shop offer that pays the most.
- Look for sets how an item is matched: A specific item by its id, An item by name or An item by lore, with the id or the text in the box beneath.
- Take the sets which match wins: Lowest number or Highest number, read from the tooltip line named under Rank by the line containing, or The first one found, which needs no line.
- Only items where narrows the matches first, with up to three rows: a tooltip line containing some text, is at least or is at most, and a number. "Only items where Self Destruct is at least 6h" keeps the listings with six hours or more left on them.
Text matches part of a line, capitals are ignored and colour codes are stripped, so $ finds $ 24M. Shorthand like 24M and 1.5k, and durations like 7h 21m, are read as the numbers they stand for. An item whose tooltip has no line you ask about is not a match at all. Containers are searched before the bot's own inventory.
The variable remembers where the item was as well as its number. A Use GUI step set to An item I found earlier, with the variable's name under The variable that found it, clicks that exact item. It checks the item is still in its slot first, and skips the step if it is not, so a menu that has changed pages costs a missed click rather than the wrong purchase.
The chat message that started this macro
Keeps a chat line. The number in it, the default, stores the first number in the line, so "player paid you 5 gems" is 5 and "$ 24M" is 24000000; a line with no number in it clears the variable instead. The whole message stores the line as text, with its formatting stripped.
On a Chat message macro, the line is the one that started it, or the most recent one a Wait for step has caught since. On any other event it is the most recent line caught by a Wait for step aimed at a chat message, which is how a macro asks a question and reads the answer:
Timer, every hour
1. Chat /balance
2. Wait for a chat message containing "Balance"
3. Set variable balance = the number in the chat message
A macro with neither has no line to read, so the step clears the variable every time it runs, and its panel says so.
A value I type
Value is stored as typed. Anything that reads as a number is stored as one, so 20M, 1.5k and 6h can all be compared later, and anything else is kept as text. Other variables can go in it as {name}.
Maths on other variables
Two sides and an operator: add, subtract, multiply or divide. Each side is a number you type, or another variable as {name} on its own in the box. It is one operation per step, so (a + b) / c is two steps: add the two into one variable, then divide it in the next.
Every account's shared value
Combines what this macro's accounts have shared, into a total, an average, the lowest, the highest or a count. See Totals across your accounts.
Under the source sit two boxes: Keep between runs, on every source (Keeping a value between runs), and Share with my other accounts, on every source but Every account's shared value (Totals across your accounts).
Writing a variable into a message
Type the name in braces, {best}, and the bot puts the value in when the step runs. Braces work anywhere text goes out or is typed in as a value:
- a Chat step's message,
- a Discord webhook or Notify my devices message,
- Value on a Set variable step, and each line of a For each list.
The number boxes take a variable only on its own, as {name} with nothing around it: both sides of a Maths step, a check's Value, and the number on an Only items where row. The boxes that can only ever hold a variable take its name bare, without braces: The variable that found it on Use GUI, The variable to look at on Look at variable, and a check's Variable.
The builder checks every name you use. A {name} that nothing in the macro sets would only ever find nothing, so the header says "A step reads {name} that nothing in this macro sets", and the macro will not save until you fix the spelling, add the step that sets it, or drag the step off the flow. It checks that something in the macro sets the name, not that it is set first: a step that runs before any Set variable has finds the variable empty, unless it was kept from the last run.
That check reads every lower-case word in braces as a variable, including one you meant as plain text. To send a brace as it is, double the opening one: {{hello} goes out as {hello}.
In a Discord webhook or a Notify my devices message, the event's own placeholders come first: {account}, {event}, {server}, {from}, {to}, {coords}, {dimension}, {health}, {message}, {entity}, {item}, {reason}, {block} and {sound} always mean the event's value there, even when a variable of the same name is set. Give your variables other names, {price} rather than {item}. A Chat step has no placeholders, so there every name in braces is a variable.
Values from a For each
A For each loop sets its variable afresh on every pass, and what the variable holds depends on what the loop goes through:
| Goes through | Called, to begin with | In a message | Also used by |
|---|---|---|---|
| Player online | {player} | The player's name | A check |
| Block nearby | {spot} | The block's coordinates | Look at variable |
| Entity nearby | {target} | The player's name, or the mob's type | Look at variable |
| Item in the open GUI or inventory | {stack} | The item's name | Use GUI's An item I found earlier, a check |
| Value in a list I type | {value} | The line | A check |
Rename it under Call it, by the same rules as a Set variable name, and keep clear of the placeholder names above. Look at variable turns the bot to the block or entity the loop is on; aimed at a variable that holds a name or an item, it has nothing to turn to and is skipped, and so is an entity that has gone.
Checking a variable
Pick A variable under Checks whether in an If, or in a Repeat set to While a check passes or Until a check passes. Put the variable's name under Variable, without braces, then pick under Is:
| Is | Passes when the variable |
|---|---|
| has a value | holds anything at all |
| at most, at least | is a number no more than, or no less than, the value |
| under, over | is a number below, or above, the value |
| exactly, anything but | is the value, or is not |
| text containing | contains the value as text |
The value is typed, and 20M, 6h and 1.5k compare as the numbers they stand for, or it names another variable as {other}. The card reads the check back as a sentence: "If best is at most 20M".
Has a value is how you ask whether a search found anything. A search that matched nothing leaves the variable empty, which is not the same as finding something worth nothing, and this check tells the two apart. There is no "has no value": put the steps for an empty variable on the If's No branch instead, the way every check is turned round.
Totals across your accounts
A variable belongs to one account: each account running a macro has its own. To add the same value up across all of them, such as every account's /balance, use two Set variable steps.
- On the step that reads each account's own value, tick Share with my other accounts. Every account keeps its latest value where the macro's other accounts can see it, and the step still sets its own variable as before.
- On a later Set variable step, pick Every account's shared value under Set it to. Under Take, pick The total, The average, The lowest, The highest or The count (of accounts that have one), and name the shared variable under Of the shared variable. With only one variable shared in the macro, it is filled in for you.
The second step puts the answer in a variable of its own, so {total} works anywhere a variable does: a Discord webhook, Notify my devices, a chat message or an If.
Timer, every hour
1. Chat /balance
2. Wait for a chat message containing "Balance"
3. Set variable balance = the number in the chat message, shared
4. Wait 10 seconds
5. Set variable total = the total of the shared balance
6. One at a time Only the first account runs them
7. Discord webhook All accounts: {total}
8. End one at a time
The Wait in step 4 matters. Accounts on one timer start together but get their replies at their own pace, so the wait gives every account time to share its balance before any of them adds up. The One at a time region then posts the total once rather than once per account.
Who counts:
- Every account this macro runs on, including the one adding up.
- An account that is offline counts with the last value it shared, and so does one whose reply had no number in it this time.
- An account you take off the macro stops counting straight away.
- An account whose shared value is text rather than a number counts towards The count, and not towards the other four.
- With nothing shared yet, the total, average, lowest and highest are left empty rather than 0, so an If can tell "no account has reported" from "they have nothing". The count is 0.
Shared values belong to the macro: another macro sharing a variable of the same name keeps its own. The builder will not save a step that combines a variable nothing in its macro shares, because that total could only ever be empty.
Keeping a value between runs
A variable normally starts empty every time a macro runs. Tick Keep between runs on a Set variable step and it carries over instead: each account starts its next run with the value the last run left it. That is how a macro counts across runs, or remembers the balance it saw an hour ago.
Death
1. If deaths has a value
No branch:
2. Set variable deaths = 0
3. End if
4. Set variable deaths = {deaths} + 1, kept between runs
5. Discord webhook {account} has died {deaths} times
The first run finds {deaths} empty, so the If takes its No branch and step 2 starts the count at 0. Every run after that starts with the count the last one saved, so the If takes its Yes branch, which has nothing on it, and step 4 adds one.
How it works:
- Each account keeps its own value, for this macro only. To add the values up across your accounts, share them as well.
- Keeping belongs to the variable, not to one step: once any step for
{deaths}has the box ticked, every Set variable step for{deaths}saves what it sets, and the box shows ticked on all of them. Untick it on any of them to stop keeping it. - A step that finds nothing, such as a chat message with no number in it, clears the variable for the next run too.
- Numbers and text are kept. An item found on an open screen is kept as its name and number, so the next run cannot click it.
- Values carry over through reconnects, restarts and edits to the macro, and come along if you change what starts the macro.
Once the macro has been saved and has run, the box lists what each account holds now and when it last changed. Reset forgets the value on every account, so each one starts its next run without it. Unticking the box and saving forgets it too. Deleting the macro deletes its kept values.
Running macros
Run, pause and order your macros, stay inside your plan's macro limit, stand a macro down with stop conditions, and read what went wrong in its logs.
Macro library and sharing
Add ready-made macros from MinecraftAFK and other players, publish your own to the community, and send a macro to a friend with a private link.