Discontinued.. contact me in discord
The Macros mod is one of the most useful mods for Minecraft that helps you automate many aspects of the game.
Developed by Mumfrey (check the original post).
I'll be focusing on the "Coding" part only in this post, if you want basic info for installing the mod, use other sources.
There are a few things that i plan on covering in this post, i'll list them here for future reference:
Variables hold information that can be used at later intervals in the program, And are a fundamental aspect of all programming languages.
Similar to languages like C++ and Java, the variables in this language have different types. This help to make our program more efficient and readable.
Variables in this language have certain prefixes that we use to declare their type. The types currently supported in this language are:
- Booleans(Flags): Contains only (Yes/No)/(True/False). Has no prefix.
- Integers: Contains integral number values, can not contain numbers with decimals. Prefix is '#'.
- Strings: Contains anything from one character to a sentence (spaces included). Prefix is '&'.
- Arrays: Contains an array of a specific type. For example if we imagine a tower with one Integer on each floor, that whole building is an Array of Integers. Generally used in scripts that require a lot of data to be stored conveniently. The prefix is a pair of brackets "[ ]" that contain the number of members.
You can declare variables with the SET command. In newer versions they can be declared even without this command but i recommend using the command for more readability. Note that declared variables can NOT contain uppercase letters.
In order for us to let the compiler know we want the value of a specific variable, we need to enclose it in '%' signs.
These are variables that are available on the global scope; meaning they are recognized in every scope of our codes.
Whenever we set a variable, it only works on It's local scope, This is good because variables with same names won't get mixed up in different places. When making GUI's or linking scripts to each other, we need to have variables that work on the global scope. This works similar to the Environmental Variables described in the next part.
To declare a global variable, all we need to do is add a '@' sign before before the variable prefix and we're done! Please note that it's best to UNSET these variables at the end of our work to prevent any future problems with the variable's data as well as freeing memory.
Imagine we want to save a message in one script and log it in another script that runs later:
These are Global variables containing game and player properties, they come in many different types but they all have the same properties:
- They can not be edited.
- They do not have prefixes, but they do need to be used with the '%' sign to get the value as well as brackets if they are arrays.
- All of them are declared using Upper-Case letters. So they don't get confused with player-set variables.
-Environmental variables list:
**A complete list when you run this script:
-Some variables are only available in Events, more info on that later.
Here are some examples to better understand the usage of these variables:
Events are special condition checks that can run a script whenever the condition is met. There are currently 20 events available for use(without any custom modules).
Some events have their own special Environmental Variables too!
-Event variables list:
Events have a page with some useful info containing Environmental Variables when you click on them(picture below), but if you're lazy This is a pretty complete list. Note that these two sources supplement each other and are not complete alone.
These are not mentioned in either of those places for some reason(please tell me if there are more):
OnChat ==> CHATPLAYER,CHATMESSAGE
Not much to say, just click on an event and put your script right in there!
I'm not really gonna get into this part, the creator of the mod already released these two videos on this and i feel like its more than enough. But just in case those are outdated, here are 2 more sources that should have them all:
Conditionals are functions that check for a condition and execute some code if they are met
There are 2 kinds of conditionals in this language: Pattern Matching conditionals and IF conditionals(This language does not have Switch/Case conditionals).
- IF conditionals: These are present in almost all languages, the syntax is different but the purpose is the same. All they do is check a condition and execute something when the condition is met.
- Pattern matching conditionals: just a derivation of the normal IF conditionals, checks the pattern defined and executes the code if the pattern matches with your input.
The conditional is declared in a line, and anything after that is performed when the condition is met. Conditionals always end with an ENDIF command so that the compiler knows when they end. This is the structure they have:
Here i'll explain each segment:
(Inputs/optional Inputs not listed here, check this for that)
- IF: Checks if the condition is met.
- IIF: Outputs different text in chat depending if the condition is met or not
- ELSE: Used after IF's, runs other actions if out main conditions didn't meet.
- ELSEIF: Used after an IF, similar to using separate IF's but exits all IF's if one of their conditions are met. This makes the code faster and more organized.
- IFCONTAINS: Checks if the specified strings contains a specific text and runs actions if the condition is met.
- IFBEGINSWITH: Checks if the specified string begins with a specific text and runs actions if the condition is met.
- IFENDSWITH: Checks if the specified string ends with a specific text and runs actions if the condition is met.
- IFMATCHES: Checks if the specified string matches our specific text exactly and runs actions if the condition is met.
Can be anything from a boolean to a mathematical equation. However there are a few important things we need to pay attention to:
- There's a huge difference between '==' and '=' operators. '=' is an assignment operator, we use this to declare variables. for example(#var = 10) is used to assign 10 to #var. '==' however is an equality operator, we use them wherever we check conditions. for example(%#var% == 10) checks if the value of #var is 10.
- Using these operators incorrectly in this language does work in most cases, but in my experience it's better to use them correctly to prevent issues.
- When we use booleans as conditions, instead of doing (%bool%==TRUE) and (%bool%==FALSE) we can use (bool) and (!bool) to make it easier.
- If we want to add more than one condition, we can use the '||' and '&&' operators. '||' is the same as the OR operator. '&&' is the AND operator. Note that when we use these operators, each condition needs to be enclosed in parentheses(examples below).
Can be any command or even more conditionals(more on commands later)
-Ending the Conditional:
It's obligatory for us to use the ENDIF command after all our conditionals to let the compiler know when to stop.
- Check if someone is saying banana in chat!Spoiler
- Check if you're holding the RMB and LMB together.Spoiler
- Input a number, check if its more or equal to 10Spoiler
- Input two numbers, check if they equal to 100 when multipliedSpoiler
- Check your health, warn you depending on how low it isSpoiler
__Loops and Iterators
Loops are a set of actions that will be repeatedly executed until a certain condition is met.
Iterators can be defined simply as "lists" of various data that can be accessed through loops and iterated over.
The general shape of loops are almost the same in every language.
They consist of a loop command, that iterates over a loop condition until the end condition is met, there are a few loop commands that are slightly different in functionality:
*Loop conditions are similar to those of Conditionals, read those above.
Most of them are written here, and the rest is written below(copied from the mod's website):
Note that each Iterator has its own set of variables that can be used in the loop where it's used.
- RUNNING iterator to iterate over running macros, provides MACROID, MACRONAME, MACROTIME
- CONTROLS iterator to iterate over existing controls, provides CONTROLID, CONTROLNAME and CONTROLTYPE variables(more info on the mod's website)
You can break out of any loop with the "BREAK" command, this is very useful when you want to break out of a loop when a condition is met.
This only breaks out of the loop it was written in.
Unfortunately, this language doesn't support CONTINUE or GOTO commands.
A really useful command for loops is the "UNSAFE" command, it lets you modify the execution rate at which the loop(or any part of the script) is run at. End UNSAFE blocks with the ENDUNSAFE command.
- The typical layout for scripts that loop infinitely until the binding key is pressed again: Spoiler
- Check enchantments on all items in inventory and pick the first item from the left that has mending.Spoiler
- Log your FPS into chat until the 0 key is pressed, cleans chat to prevent spam issues(can be used for GUI's in different manners)Spoiler
Command are like built-in functions for out scripts, which we can use to execute all sorts of actions.
The best way of learning how commands work is to experiment with them yourself, so don't stand around and wait for others to tell you how to work with them and try them out yourself!
Commands usually require an input, however, they can provide outputs and have options or flags that we can enable or disable when needed.
The general shape of commands is as followed:
Look at examples for better understanding.
There is a list of commands on the mod GUI itself.
I'm not sure if it's a complete list, but i recommend checking the mod's change logs to see the newer commands, as well as more complete info on commands that might seem complicated to you.
I was too lazy to think of more.. will add later though
- Go through your hotbar inventory, shoot snowballs if there are any.Spoiler
- Looks at the block you are facing if there is any, and walks to it. This script is only to demonstrate some uses of commands(its not stable). Automatically stops the script if it takes too long.Spoiler
Another really useful part of macros, GUI's allow us to really modify out game screen with useful buttons and information.
Here we will take a look at screens as well as different types of GUI's and how to use them, as well as simple examples for better understanding, more complicated GUI's will be added here instead.
Basic info on screens are in Mumfrey's own video, but here's a bit more info:
As the name suggests, puts a button on the screen which runs a command or script when you click it.
Note that buttons won't be accessible in screen such as InGame(test it to see what i mean), so pick a screen such as InChat for these.
You can add a custom icon as well as minecraft texture icons.
To add a custom label just add the image file to path\to\.minecraft\liteconfig\common\macros\icons.
To add minecraft texture icons write the minecraft name ID into the icon field, full list of icons here. For example grass would be minecraft:grass, spruce log would be minecraft:planks:1.
Also supports the use of a durability bar, look at the example.
Adds a label with text you can edit either with a script or bind to a global environmental variable.
Useful for adding labels with info such as current server, biome, coords etc.
Simply imports an existing GUI screen onto another.
Very useful to make our GUI's more compact and malleable, for example when importing multiple GUI's into a single one.
Displays currently running scripts, similar to how they display when you press the macro activate key.
No examples or anything, pretty simple stuff.
Useful for things like health bars, timers, etc.
Allows the use of a slider, which can be accessed from screens like InChat and adjusted to edit an integral value.
As stated my Mumfrey himself:
"TEXTAREAs behave like the minecraft chat, in that you can send text to them but you can't set their text. To write text to a TEXTAREA just use LOGTO with the name of the TEXTAREA and your message."
So basically it's like a second chat screen intended for log purposes i suppose, can have a timer as well.
Edited by UniversAll, 05 November 2018 - 01:14 PM.