Macros can easily be defined in the .dmf file, but some times people prefer a more hands on, code-y approach. My library assists with that.
Inspired by Handy Stuff, a list of helpful libs by Forum_Account, I aimed to create my own library to handle macros. While his method is very effective, as are some of the others I've come across, I like to understand what is going on with the code. And what better way to learn and understand than to teach, yes?
This has been updated as of May 9th. Please re-read the documentation below, or the comments in the code.
Adding a Macro
The full list of modifiers is this:
client.addMacro(kKey, runProc, repeat=0, release=0, shift=0, alt=0)
Here are some samples for using it:
client.addMacro("NORTH", "jump")
This will make your mob run "jump" with no arguments when the "NORTH" (your up key) is first pressed.
client.addMacro("A", "fall+4", release=1)
This will make your mob run "fall" with a 4 argument when you release the A key. The 'release' is set to 1, which is why it's on release of the key.
You only have to put the modifier that you're going to use on 1. For example:
client.addMacro("B", "say+I released the b key while holding shift!", release=1, shift=1)
The result is evident. "repeat" is whether or not to do it while holding down the button, release is when you let go of the key, shift is while pressing shift and alt is while pressing alt.
Removing a Macro
client.removeMacro("NORTH", release=1)
This would get rid of the above macro. It clears whatever you have set there.
Misc. Notes
If you set this;
client.arrows = 0
In your code, it will turn off BYOND's standard movement code.
All things called by these macros must be verbs. Macros can't run procs, only verbs. I suggest keeping "control_freak" on (it's on by default in my library), as well as making any macro that's sensitive have this line of code in it:
set hidden = 1
This will hide it from your verb panels.
More information can be found in this post. If you have any questions, put it in the comments section and I'll do my best to assist you.
ID:112969
May 1 2011, 10:00 pm
|
|
I've been trying to link it to a blog post, actually. The URL is here:
http://www.byond.com/members/ SqueakyReaper?command=view_post&post=112760 Finally found the "documentation" field, so I dropped the link in there. |
Updated the macromaker. It now supports releasing the key, holding it down, pressing while shift and pressing while alt. Not sure why I didn't put that in before...
|
Keep it up, and thanks!