-
Posted by galvin on Mon, 28 Jun 2010 05:39:08
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
-
Posted by jnwhiteh on Mon, 28 Jun 2010 07:58:33
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.
-
Posted by jnwhiteh on Mon, 28 Jun 2010 08:16:17
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 theOnEnter
script, notself.command
. The printed version of code at the end of the chapter has the correct version. -
Posted by galvin on Mon, 28 Jun 2010 16:35:27
Thanks