12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16 ■ Binding Keys <strong>and</strong> Clicks to Addon Code 311...The name attribute, in this case TOGGLESHEATH, sets the name <strong>of</strong> this particularaction. You use this name with the SetBinding() functions later in thischapter. The key binding interface looks <strong>for</strong> a global string variable calledBINDING_NAME_name to label the binding in the list. For example, the value<strong>of</strong> BINDING_NAME_TOGGLESHEATH is Sheath/Unsheath Weapon in the Englishversion <strong>of</strong> <strong>WoW</strong> (see Figure 16-1).Once you bind a key to a comm<strong>and</strong>, the code inside the Binding tagis executed whenever you press the key. In this case, because Z is boundto TOGGLESHEATH, pressing Z calls the ToggleSheath function, which cyclesthrough your equipped weapons.NOTE There are certain situations in which key bindings might not appear towork correctly, such as when you try to use a keyboard binding while an EditBoxwidget has the keyboard focus. Similarly <strong>for</strong> mouse buttons, any time the cursor isover a mouse-enabled frame, the frame consumes button clicks <strong>for</strong> use withOnClick, OnMouseDown, <strong>and</strong> so on, whether or not the h<strong>and</strong>lers have beendefined <strong>for</strong> the frame.Key bindings are consulted only if the keys or buttons aren’t consumed by someother aspect <strong>of</strong> the user interface.Here’s another example from the built-in Bindings.xml that illustrates acouple more features:if ( keystate == “down“ ) thenMoveAndSteerStart();elseMoveAndSteerStop();endAs with the previous example, this binding includes a name attribute<strong>and</strong> a Lua chunk. The new header attribute sets up a heading <strong>for</strong> the keybinding interface. In this case <strong>WoW</strong> looks <strong>for</strong> BINDING_HEADER_to determine the text <strong>of</strong> the header. You can see in Figure 16-1 thatBINDING_HEADER_MOVEMENT is defined as Movement Keys in the English client.Of particular note is the runOnUp attribute, which tells the game to execute thebinding code twice: once when the key is pressed down, <strong>and</strong> again whenthe key is released. The code sample shows that <strong>WoW</strong> provides a keystate

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!