1. I have a question and getting a bug

    This code I don't really understand the BindingTestCaptureFrame.button = self. I dont see any "button" frame or variable defined in the xml

     function BindingTestButton_OnClick(self, button)
       if button == "LeftButton" then
         BindingTestCaptureFrame.button = self
         BindingTestCaptureFrame:Show()
       elseif button == "RightButton" then
         local key = GetBindingKey(self.command)
         if key then
           SetBinding(key, nil)
         end
         BindingTestButton_OnEnter(self)
       end
     end
    

    This code is generating an error when I mouse over the buttons the print(self.command) was to see what was causing the error. The result is a nil. So I guess passing nil to GetbindingKey() is bad, but why its nil I have no idea.

     function BindingTestButton_OnEnter(self)
       GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
       GameTooltip:AddLine(TOOLTIP_TEXT1)
       GameTooltip:AddLine(TOOLTIP_TEXT2)
       print(self.command)
       local list = {GetBindingKey(self.command)}
       for i, key in ipairs(list) do
         list[i] = GetBindingText(key, "KEY_")
       end
       GameTooltip:AddLine(
         TOOLTIP_BINDING_LIST:format(table.concat(list, LIST_SEPERATOR)),
         NORMAL_FONT_COLOR.r,
         NORMAL_FONT_COLOR.g,
         NORMAL_FONT_COLOR.b,
         1
       )
       GameTooltip:Show()
     end
    

    The error

     Message: Interface\AddOns\BindingTest\BindingTest.lua:52: Usage: GetBindingKey("COMMAND"[, mode])
     Time: 06/28/10 01:36:39
     Count: 3
     Stack: [C]: in function `GetBindingKey'
     Interface\AddOns\BindingTest\BindingTest.lua:52: in function <Interface\AddOns\BindingTest\BindingTest.lua:47>
    
     Locals: (*temporary) = nil
    
  2. I have a question and getting a bug

    This code I don't really understand the BindingTestCaptureFrame.button = self. I dont see any "button" frame or variable defined in the xml

     function BindingTestButton_OnClick(self, button)
       if button == "LeftButton" then
         BindingTestCaptureFrame.button = self
         BindingTestCaptureFrame:Show()
       elseif button == "RightButton" then
         local key = GetBindingKey(self.command)
         if key then
           SetBinding(key, nil)
         end
         BindingTestButton_OnEnter(self)
       end
     end
    

    The section of the book that discusses widget scripts states that each script is automatically called with certain arguments. You can consult the documentation for OnClick to see what these are. If you're using XML you'll need to either explicitly pass these arguments to your handler function, or if you use the function="BlahBlah" syntax, it will do it for you.

    This code is generating an error when I mouse over the buttons the print(self.command) was to see what was causing the error. The result is a nil. So I guess passing nil to GetbindingKey() is bad, but why its nil I have no idea.

     function BindingTestButton_OnEnter(self)
       GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
       GameTooltip:AddLine(TOOLTIP_TEXT1)
       GameTooltip:AddLine(TOOLTIP_TEXT2)
       print(self.command)
       local list = {GetBindingKey(self.command)}
       for i, key in ipairs(list) do
         list[i] = GetBindingText(key, "KEY_")
       end
       GameTooltip:AddLine(
         TOOLTIP_BINDING_LIST:format(table.concat(list, LIST_SEPERATOR)),
         NORMAL_FONT_COLOR.r,
         NORMAL_FONT_COLOR.g,
         NORMAL_FONT_COLOR.b,
         1
       )
       GameTooltip:Show()
     end
    

    The error

     Message: Interface\AddOns\BindingTest\BindingTest.lua:52: Usage: GetBindingKey("COMMAND"[, mode])
     Time: 06/28/10 01:36:39
     Count: 3
     Stack: [C]: in function `GetBindingKey'
     Interface\AddOns\BindingTest\BindingTest.lua:52: in function <Interface\AddOns\BindingTest\BindingTest.lua:47>
     
     Locals: (*temporary) = nil
    

    I'm checking to see why something like this might happen.

  3. Looks like it's an issue with the printed version of the code in the prose of the chapter. It should read self.action in the OnEnter script, not self.command. The printed version of code at the end of the chapter has the correct version.

  4. Thanks