-
Posted by zenasprime on Thu, 24 Sep 2009 20:14:37
Where can I find a detailed description of how to setup a Check Button. So far, the few references I have found have either do not describe how to actually implement one or, if they do, I couldn't get them to work in game.
Thanks,
-z
-
Posted by jnwhiteh on Thu, 24 Sep 2009 20:38:55
You implement them precisely the same way you implement a button, you just substitute "CheckButton" instead of "Button". What specifically are you trying to accomplish?
Here's some example code:
local frame = CreateFrame("CheckButton", "UICheckButtonTemplateTest", UIParent, "UICheckButtonTemplate") frame:ClearAllPoints() frame:SetPoint("CENTER", 0, 0) _G[frame:GetName() .. "Text"]:SetText("Example checkbutton") MakeMovable(frame)
-
Posted by zenasprime on Thu, 24 Sep 2009 21:02:06
Hi and thanks for the quick response.
Well, I'm trying to implement three check buttons that the user can use to indicate what class roles they would like to advertise for (ie tank, heals, dps). I've implemented the check buttons in the XML file and they appear in my addon, though unlabeled.
<CheckButton name="$parent_CheckButton1" inherits="UICheckButtonTemplate" text="Hello"> <Size> <AbsDimension x="20" y="20"/> </Size> <Anchors> <Anchor point="TOPLEFT"> <Offset> <AbsDimension x="50" y="-80"/> </Offset> </Anchor> </Anchors> <Scripts> <OnLoad> getglobal(this:GetName().."Text"):SetText("CheckButton1") </OnLoad> </Scripts> </CheckButton> <CheckButton name="$parent_CheckButton2" inherits="UICheckButtonTemplate" text="Hello"> <Size> <AbsDimension x="20" y="20"/> </Size> <Anchors> <Anchor point="TOPLEFT"> <Offset> <AbsDimension x="105" y="-80"/> </Offset> </Anchor> </Anchors> <Scripts> <OnLoad> getglobal(this:GetName().."Text"):SetText("CheckButton2") </OnLoad> </Scripts> </CheckButton> <CheckButton name="$parent_CheckButton3" inherits="UICheckButtonTemplate" text="Hello"> <Size> <AbsDimension x="20" y="20"/> </Size> <Anchors> <Anchor point="TOPLEFT"> <Offset> <AbsDimension x="157" y="-80"/> </Offset> </Anchor> </Anchors> <Scripts> <OnLoad> getglobal(this:GetName().."Text"):SetText("CheckButton3") </OnLoad> </Scripts> </CheckButton>
Unforutnately, I'm having a problem testing the checkbox in my lua functions. If I try something like...
checkbuttontest = WoWPUGBuilder_CheckButton1:GetChecked() print(checkbuttontest)
... the functions stops working that the checkbuttontest = ... line I know I'm missing something here but I haven't been able to find it yet.
Thanks for your help, -z
PS how do i display code in this forum? Whenever I try to use the code dudad it only makes formatting worse.
-
Posted by zenasprime on Thu, 01 Oct 2009 23:02:20
Here is a link to the .zip file for all my files.
-
Posted by jnwhiteh on Wed, 07 Oct 2009 18:34:15
Functions don't just "stop working". I really need you to provide a bit more information about what is happening and going wrong. I'm not really sure what's going on..
-
Posted by zenasprime on Thu, 08 Oct 2009 02:28:55
Okay, I seem to have made a little bit of progress. I guess my question is this...
How do I determine if a checkbox is checked? Currently I am using an if/then statement like this...
if CheckButton1 then table.insert(roles, "Tank") end
I don't think that this actually does anything.
I've also tried this..
checkbuttontest = WoWPUGBuilder_CheckButton1:GetChecked() print(checkbuttontest) print('checkbuttontest successful')
but if I add that to my function, I get no output what so ever after the assignment statement (ie the function has "stopped working").
If the two methods above are in error, how do I test if a checkbox is checked and consequently perform actions according to the outcome.
Thanks for your help and sorry for the confusion. -z
-
Posted by curti on Mon, 12 Oct 2009 05:55:51
Not sure if this is the best way to do it, but I think you can do the following
<CheckButton> <Scripts> <OnClick> someFunction(); </OnClick> </Scripts> </CheckButton> somefunction() if (CheckButton:GetChecked() == 1) then print("Checked"); else print("Not Checked"); end end
Edit: Changed OnClick Text.
-
Posted by jnwhiteh on Mon, 12 Oct 2009 09:41:49
Okay, I seem to have made a little bit of progress. I guess my question is this...
How do I determine if a checkbox is checked? Currently I am using an if/then statement like this...
if CheckButton1 then
table.insert(roles, "Tank")
end
I don't think that this actually does anything.
Indeed, this is just checking to see if the global variable named CheckButton1 is set to something other than nil or false. Since that's the name of your button, it's always true.
I've also tried this..
checkbuttontest = WoWPUGBuilder_CheckButton1:GetChecked()
print(checkbuttontest) print('checkbuttontest successful')
but if I add that to my function, I get no output what so ever after the assignment statement (ie the function has "stopped working").
If the two methods above are in error, how do I test if a checkbox is checked and consequently perform actions according to the outcome.
You check if a checkbox is checked using the GetChecked() method. For example:
if CheckButton1:GetChecked() then print("Checkbutton is checked") else print("Checkbutton is not checked") end
-
Posted by zenasprime on Tue, 13 Oct 2009 22:07:34
Thanks for your clarification. I knew that there was an error with the "CheckButton1" if/then statement but my AddOn seemed to work better with it then with "WoWPUGBuilder_CheckButton1:GetChecked()" so I wasn't too sure. I've gone and changed the function to look like this...
function AdvertiseMessageConstruction() print('**Executing AdvertiseMessageConstruction()**') local instances = {} local roles = {} -- The following if/then statements will construct the desired instance array print("**Executing DropDown Menu Routine**") if OldKingdom then table.insert(instances, "Old Kingdom") end if AzjolNerub then table.insert(instances, "Azjol-Nerub") end if CullingofStratholme then table.insert(instances, "Culling of Stratholme") end if DrakTharonKeep then table.insert(instances, "Drak'Tharon Keep") end if Gundrak then table.insert(instances, "Gundrak") end if TheNexus then table.insert(instances, "Nexus") end if TheOculus then table.insert(instances, "Oculus") end if TrialoftheChampion then table.insert(instances, "Trial of the Champion") end if HallsofLightning then table.insert(instances, "Halls of Lightning") end if HallsofStone then table.insert(instances, "Halls of Stone") end if UtgardKeep then table.insert(instances, "Utgarde Keep") end if UtgardePinnacle then table.insert(instances, "Utgarde Pinnacle") end if VioletHold then table.insert(instances, "Violet Hold") end -- The following if/then statements will construct the desired role array print("**Executing CheckButton Routine**") if CheckButton1:GetChecked() then print("CheckButton1 is checked") table.insert(roles, "Tank") else print("CheckButton1 is not checked") end if CheckButton2:GetChecked() then print("CheckButton2 is checked") table.insert(roles, "Heals") else print("CheckButton2 is not checked") end if CheckButton3:GetChecked() then print("CheckButton3 is Checked") table.insert(roles, "DPS") else print("CheckButton3 is not checked") end -- The following code will build the instance list and role list from the corresponding tables print('**Building Instance List**') instancelist = table.tostring(instances) print('instancelist: ' .. instancelist) print('**Building Role List**') rolelist = table.tostring(roles) print('rolelist:' .. rolelist) -- The following code will format the role list and instance list into a message string which is then returned by the function. print("**Formatting Message to be Advertised**") local msg = string.format("Lookin for %s for %s", rolelist, instancelist) print("Message: " .. msg) return msg end
Unfortunately I'm still not getting any execution past the if/then statements for the checkbox. I'm going back to check the xml which currently looks like this...
<CheckButton name="$parent_CheckButton1" inherits="UICheckButtonTemplate" text="Hello"> <Size> <AbsDimension x="20" y="20"/> </Size> <Anchors> <Anchor point="TOPLEFT"> <Offset> <AbsDimension x="50" y="-80"/> </Offset> </Anchor> </Anchors> <Scripts> <OnLoad> getglobal(this:GetName().."Text"):SetText("CheckButton1") </OnLoad> </Scripts> </CheckButton> <CheckButton name="$parent_CheckButton2" inherits="UICheckButtonTemplate" text="Hello"> <Size> <AbsDimension x="20" y="20"/> </Size> <Anchors> <Anchor point="TOPLEFT"> <Offset> <AbsDimension x="105" y="-80"/> </Offset> </Anchor> </Anchors> <Scripts> <OnLoad> getglobal(this:GetName().."Text"):SetText("CheckButton2") </OnLoad> </Scripts> </CheckButton> <CheckButton name="$parent_CheckButton3" inherits="UICheckButtonTemplate" text="Hello"> <Size> <AbsDimension x="20" y="20"/> </Size> <Anchors> <Anchor point="TOPLEFT"> <Offset> <AbsDimension x="157" y="-80"/> </Offset> </Anchor> </Anchors> <Scripts> <OnLoad> getglobal(this:GetName().."Text"):SetText("CheckButton3") </OnLoad> </Scripts> </CheckButton>
This is an almost verbatim copy from a reference I found on the internet. When I run XMLNanny I get the following error...
"ERROR: No character data is allowed by content model line 64, column 10"
and I get this error for every line after line 64, which is where
"<CheckButton name="$parent_CheckButton1" inherits="UICheckButtonTemplate" text="Hello">"
starts. What does it mean when this error pops up? -
Posted by zenasprime on Tue, 13 Oct 2009 22:14:29
I took s shot in the dark and decided to change the CheckButton name from "$parent_CheckButton1" to just "CheckButton1". The AddOn now works as I am intending it to, however I am still getting that error in XMLNanny. Any clue what that error could be referring to?
Thanks for your help with the lua function.
-z
-
Posted by jnwhiteh on Wed, 14 Oct 2009 07:06:15
Not without knowing what is on line 64. Also, are these checkbuttons within another frame? That's the only way $parent works.
-
Posted by zenasprime on Wed, 14 Oct 2009 10:05:57
Not without knowing what is on line 64.
<Size>
Also, are these checkbuttons within another frame? That's the only way $parent works.
Yes, they are within the frame "WoWPUGBuilderFrame".
And now I can see why...
checkbuttontest = WoWPUGBuilder_CheckButton1:GetChecked()
print(checkbuttontest) print('checkbuttontest successful')
...wasn't working properly.
-
Posted by jnwhiteh on Wed, 14 Oct 2009 16:37:07
Well, you absolutely should have (in 3.2) gotten the popup error box when the code ran. If it was running at load time, that would be different.. but either way you would get an error saying 'attempt to index a nil value'
-
Posted by zenasprime on Sat, 24 Oct 2009 06:04:31
Thanks for your help. :)
http://wow.curseforge.com/addons/wowpugbuilder/