PDA

View Full Version : need help: XML button unchecking


ChaosInc
01-07-2007, 06:57 PM
My XML experience is non-existent and I'm trying to figure out how to make a button "uncheck" when you "check" another one. Checked over at wowwiki.com, but all I can find is how to "check" them and nothing on "unchecking".

Any help would be appreciated. As I said, I know squat about XML.

Telic
01-07-2007, 08:00 PM
Here's a simple checkbox example called CB1;
In the <Scripts> section, you can have an <OnClick> section like normal buttons do - the code in here will be executed when someone clicks on the check box. The function "SetChecked()" can be used to set the status of the other Checkbox - I have used the name CB2 for the other checkbox.
CB2:SetChecked(0) will uncheck it.
CB2:SetChecked(1) will check it.


<CheckButton name="CB1" inherits="UICheckButtonTemplate">
<Size>
<AbsDimension x="18" y="18"/>
</Size>
<Anchors>
<Anchor point="CENTER">
</Anchor>
</Anchors>
<Scripts>
<OnClick>
CB2:SetChecked(0);
</OnClick>
</Scripts>
</CheckButton>

ChaosInc
01-07-2007, 08:35 PM
Thx, exactly what I need. One more thing though, is there a more efficient way to do this:
------------------------------------------------------
.xml
<OnClick>MyMod_SetButton(2);</OnClick>

.lua
function MyMod_SetButtons(i)
for num= 1,5 do
getglobal("MyMod_Button".. num):SetChecked(0);
end
getglobal("MyMod_Button".. i):SetChecked(1);
end;
------------------------------------------------------

or is that the best I can get to do the changes? There are 5 buttons total, only one can be selected at a time.

Edit: deleted a line of code copied having nothing to do with this

Telic
02-07-2007, 07:58 PM
I'd say for mutually exclusive checkboxes where 1 MUST be checked (i.e. successive clicks on the same box should NOT un-check it), then your code is fine :)

[Except that your XML is calling "MyMod_SetButton" and the LUA function is called "MyMod_SetButtons"]