Macros
Macros allow users to create shorthand for fast execution of otherwise long commands.
How to create/use a macro
Creating a macro is done with the format /macro = original.script
. Pre-defined parameters can also be applied. For example:
/bal = accts.balance
/hl = kernel.hardline
/dc = kernel.hardline { dc:true }
Once the macro has been created, it can be used by simply typing /<macro name>
. For instance, typing /bal
will run accts.balance.
Macros with custom arguments
By using double braces, you can set up your macros to allow for custom arguments. You can reference specific arguments (seperated by spaces) using each argument's index, like {0}
, {1}
, and {2}
. For example:
/xfer = accts.xfer_gc_to {{ to:"{0}", amount:{1} }}
With the above macro, typing /xfer trust 500
would run accts.xfer_gc_to { to:"trust", amount:500 }
To reference an argument that uses spaces - e.g. a chat message - use {$}
, which references any argument not already specified by a number index. For example:
/chat = chats.send {{ channel:"{0}", message:"{$}" }}
With this macro, typing /chat 0000 This is a chat message!
would call chats.send { channel:"0000", message:"This is a chat message!" }
View current macros
Typing /
by itself will show a list of the current user's macros.
>>/
/bal = accts.balance
/hl = kernel.hardline
/dc = kernel.hardline { dc:true }
Delete a macro
To delete an existing macro, type /macro =
with nothing after the =
.
>>/bal =
Macro deleted.
Macro storage on disk
What's a macro file?
Macros in hackmud are stored in a file per user, which is located in the same place as shell.txt
.
Run #dir and go two folders up. Or navigate to:
Windows -
C:\Users\USERNAME\AppData\Roaming\hackmud
macOS -~/.config/hackmud
Linux - Either~/.config/hackmud
or the game folder.
The naming scheme is username.macros
, and are plain text files.
Workaround: Sharing macros between users
Because macros are scoped to users by default, when you switch to another user, you can't use the first user's macros.
One of the ways you can solve this is with the concept of a symlink: https://en.wikipedia.org/wiki/Symbolic_link
By adding a symlink to a source file for macros, each user would be editing and reading from the same file, allowing macros to be shared between users.
When mucking with files always back them up before accidentally doing destructive actions.
How to set up a symlink on Windows
Windows 10 and later have access to mklink
: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mklink
Here's an example of mapping / copying macros from user_a's macros to user_b's macros.
Running mklink requires a windows command prompt which has been started with administrator permissions.
USAGE:
mklink abs_path_to_new_link_file file_path_to_link_to
COMMAND:
mklink "C:\Users\southr6\AppData\Roaming\hackmud\user_b.macros" "C:\Users\southr6\AppData\Roaming\hackmud\user_a.macros"
How to set up a symlink on macOS & linux
To make a symlink these unix-based platforms, we're going to use the ln
command.
Syntax may differ depending on your OS, check man ln
for usage differences.
Also note, the parameters are in different orders in windows and unix.
We want to run ln
with the -s
options, with the source file being the path to the file containing the macros, and the target file being the path to the username.macros
in the previously mentioned directory.
For example on macOS, my ln usage and command looked like this:
USAGE:
ln [options] source_file new_link_file
COMMAND:
ln -s ~/Developer/hackmud/southr6/workshop/macros.txt ~/.config/hackmud/southr6.macros