ID:35824
 
Keywords: interface, tutorial
A BYONDscape Classic!


This concludes my first article contribution to BYONDscape.  If you have any questions/comments, drop me line at [email protected].

Keyboard Macros

As a DM programmer, one of the most common questions I receive is, "How do you make this key do that?"  To new DM programmers, I suppose this subject is very mystifying and complicated, only to be touched by BYOND gurus.  The funny thing is, it is actually extremely easy to implement.

The real issue at hand is not the difficulty of implementing the system, but whether or not it is right for your game.  The major turn-off of using keyboard macros is that it hinders the ability to type out verbs.  Simply put, the two do not work well with each other.  In order to access the verb say, you must first press backspace.  This is quite a nuisance.  Because of this, players tend to turn macro-mode off, and they forget to put it back on.  You will often hear things like, "That's not fair, I had macro-mode off," or, "You only beat me because I forgot to put macro-mode on!"  If you are going to use keyboard macros in your game, it is a good idea to make it unnecessary to turn macro-mode off.

On to the part about setting up macros... this shouldn't take too long.   Create a new script (.dms) file and key in the following code:

macro
    g

        return "get"

    i

        return "inventory"

Examine the code.  Note how it is very similar in structure to DM.  The same indentation rules apply.  Here is what it is doing.  When the player presses the "g" key, it is processed as though he had typed, "get."  The same thing happens for inventory.  Then, all that needs to be done is to create a "get" and "inventory" verb.  This must be done in a code (.dm) file.  Create a new code file, and then key the following code:

mob
    verb
        get()
            set name = "get"
            for(var/obj/O in usr.loc)
                O.Move(usr)

                usr << "You get [O]."
        inventory()
            set name = "inventory"
            usr << "You carry:"
            if(contents.len)
                for(var/a in src)
                    usr << "\t[a]"
            else
                usr << "\tNothing!"

This code should be pretty easy to understand.  If it isn't, just look at it for a little bit and you'll get it.  Basically, the get() verb picks up all items on the ground and puts them in the players contents.  Then, inventory displays the contents.  We have macros that link to these verbs, so lets try it out. 

Create an icon for a default mob, obj, and turf.  Assign the atoms their icons (mob/icon = 'Mob.dmi', etc.).  Then a create a new map (.dmp) file and place some objects around.  If you have trouble following these directions, you may want to check out Zilal's tutorial, ZBT.  Now we can test out our miniature game.  Press CTRL-K to compile the game, and then press CTRL-R to run it.

If all goes well, you should see the three verbs we created in the verb panel and the map you created in the main screen.  Try pressing our macros, "g" and "i." They're not working!  No, you didn't do anything wrong.  It is because we have macro-mode off.  In the lower-left hand of your window, there should be a button labeled, "ALT."  Make sure it is indented by clicking it.  If the button is indented, it indicates that macro-mode is on.  Another way to tell that you are in macro-mode is that the text box at the bottom of the screen will contain, "(macro)."  Now press "i."  You should get a message saying you aren't carrying anything.  Good job!  You got the macros working.  However, wouldn't it be nice if we could make it so that macro-mode was already turned on when the player logged in?

Well, I have some good news.  Making macro-mode auto-enabled is as simple as adding one line of code:

client/command_text = ".alt "

Seems too easy, doesn't it?  That's really all there is to it!  You may want to recompile and test the macros out again.  Notice that when you log in, your input box contains the text, "(macro)."  Macro-mode has been enabled for you already!  Isn't that just great?

What happens if you want to macro a key like "F1," "Spacebar," or even "Enter"?  These are actually just as simple to macro as any other key, but there are only certain keys that are able to be macroed.  For a full list of non-printable keys that may be macroed, go here.

Umm. How relevant is this now BYOND v4.0 has changed a lot of the macro stuff?
Hm, mind clipping some of the left of http://members.byond.com/DreamMakers/files/articles/ Ebonshadow.2002-1024/images/line12.gif or something; it's kind of causing a box overflow in there. :(
DarkView wrote:
Umm. How relevant is this now BYOND v4.0 has changed a lot of the macro stuff?

Beats me! I hope it still works, because if not, some of my games are broken.
You can edit 4.0 macros in the new interface files, just under "Macros" click on whatever macro set you have set on your window, and add/remove/edit them.

Not that hard to convert.
Hiead wrote:
it's kind of causing a box overflow in there. :(

Uh oh! I see what you mean. I didn't have that problem at home. I'll just comment out the image for now, until I can access the file directly.