Jump to content

Photo

Macros Mod; A Useful Guide To Advanced Scripting(8)

14 replies to this topic
  • Please log in to reply

Poll: Support this post: (42 member(s) have cast votes)

Are you interested in this post?

  1. Yes, please complete it (39 votes [92.86%])

    Percentage of vote: 92.86%

  2. Meh, i don't care (3 votes [7.14%])

    Percentage of vote: 7.14%

  3. Nope, nobody gives a !%#% (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

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.

Spoiler

There are a few things that i plan on covering in this post, i'll list them here for future reference:
Spoiler

 
 
__Variables
 
Variables hold information that can be used at later intervals in the program,  And are a fundamental aspect of all programming languages.
-Types:
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.

-Declaration:
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.

Spoiler

-Usage:
 
In order for us to let the compiler know we want the value of a specific variable, we need to enclose it in '%' signs.
Spoiler

__Global Variables
 
 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.

-Declaration:
 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.

-Example usage:
Imagine we want to save a message in one script and log it in another script that runs later:

Spoiler

__Environmental Variables
 
 
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: 

Spoiler

-Some variables are only available in Events, more info on that later.

-Examples:
Here are some examples to better understand the usage of these variables:

Spoiler

__Events
 
 
 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
 
Spoiler

-Usage:
Not much to say, just click on an event and put your script right in there!
 
__Parameters
 
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:
Spoiler

Spoiler

 
__Conditionals
 
 
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.

-Syntax:
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:

Conditional(Condition(s))

..

Actions

..

End Conditional

Here i'll explain each segment:
-Conditionals:
(Inputs/optional Inputs not listed here, check this for that)

  • IFChecks if the condition is met.
  • IIF: Outputs different text in chat depending if the condition is met or not
  • ELSEUsed 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.
  • IFENDSWITHChecks 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.

-Conditions:
 
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). 

-Actions:
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.
 
-Examples:

  •  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 10
    Spoiler
  • Input two numbers, check if they equal to 100 when multiplied
    Spoiler
  • Check your health, warn you depending on how low it is
    Spoiler

__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.

 

-Syntax:
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:

Spoiler

 *Loop conditions are similar to those of Conditionals, read those above.

-Iterators:
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)

-Breaking out:

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.

 

*Side note:

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.

 

-Examples:

  •  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

__Commands

 

 

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!

 

-Syntax:

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:

 

Command(Input/outputs/condition checks)

Look at examples for better understanding.

 

-Commands list:

There is a list of commands on the mod GUI itself.

Spoiler

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.

 

-Examples:

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

__GUI's

 

 

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.

 

-Screens:

 

Basic info on screens are in Mumfrey's own video, but here's a bit more info:

-GUI types:

      .Button: 

   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.

        +Examples:

Spoiler

      .Icon: 

  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.

        +Examples:

Spoiler

 

      .Label: 

   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.

        +Examples:

Spoiler

      .Custom GUI:

   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.

        +Examples:

Spoiler

      .Playback status:

   Displays currently running scripts, similar to how they display when you press the macro activate key.

   No examples or anything, pretty simple stuff.

   .Progress bar:

   Useful for things like health bars, timers, etc.

        +Examples:

Spoiler

 

      .Slider:

   Allows the use of a slider, which can be accessed from screens like InChat and adjusted to edit an integral value.

        +Examples:

Spoiler

 

      .Textarea:

  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.

        +Examples:

Spoiler

 

 

 


Edited by UniversAll, 05 November 2018 - 01:14 PM.

  • Lex1k0n, LordGeokal, PrinceKush and 20 others like this

 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#2
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

Updated!


 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#3
SauronDark

SauronDark

    Diamond Monger

  • Server Donator
  • 670 posts
i am really excited to build scripts my own, i knew basic programming, so this wont be difficult at all!, thank any way

#4
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

Minor update, 

also if u have any suggestions for some example scripts i could write for next parts, write it here.


Edited by UniversAll, 16 November 2017 - 12:55 PM.

 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#5
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

Updated again,

 

if u have any suggestions for some example scripts i could write for next parts, write it here.


 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#6
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

Updated and fixed a few things, feel free to ask questions


 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#7
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

Bump..

added another part

suggestions wont hurt :/


 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#8
Yawz

Yawz

    Enderdragon Slayer

  • Server Donator
  • 3,468 posts

Following this, thank you. :)



#9
desiassassin

desiassassin

    Enderdragon Slayer

  • Server Donator
  • 1,029 posts

wow so long....gj universall

 

let's see if I can make some macros on ma own


FK Signatures!!


#10
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

made slight modifications to the post, update coming in the near future..


 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#11
visitor

visitor

    Pumpkin Farmer

  • Members
  • 113 posts

UnivesAll I Can Tell You Took Coding Fundmentals In Middle/High School


AjAjoxi.gif

Im Planning of Adjusting My sign&i got 517 kills in PB yesterday 10/8/18

 


#12
visitor

visitor

    Pumpkin Farmer

  • Members
  • 113 posts

Il Try that mod


AjAjoxi.gif

Im Planning of Adjusting My sign&i got 517 kills in PB yesterday 10/8/18

 


#13
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

Updated, added more than half of the GUI tutorial and added screenshots for better understanding

Also considering doing voiced videos instead to avoid wasting so much time :P


  • NightWanderer likes this

 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft


#14
skrillex53

skrillex53

    can i haz fraction

  • Server Donator
  • 57 posts

I don't understand nothing cause I'm not programmer /developper but you made nice tutorial, nice work it's cool tutorial


1527274966-untitled-2.gif


#15
UniversAll

UniversAll

    Shop Owner

  • Server Donator
  • 195 posts

Completed GUI section.


  • Lex1k0n likes this

 |||•-|||

 (macros scripts/tutorial,Fil guide,shopMap)

 TE was the first and will be the last Minecraft server i will ever play, Goodbye Minecraft



Also tagged with one or more of these keywords: macros, scripts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users