This is one basic approach. Where you create your radio buttons, you could use something like (added some print statements to see what is happening):
Lua Code:
content2.RadioButtons = {}
local function ClearRadio(self)
if not self:GetChecked() then return end -- only action if a radio is checked when it's clicked
for i=1, #content2.RadioButtons do
local button = content2.RadioButtons[i]
if button ~= self and button:GetChecked() then
print(button:GetName(), "Unchecked")
button:SetChecked(false) -- Set other radio buttons unchecked
button:GetScript("OnClick")(button) -- Call the "OnClick" script if the buttons need to "do stuff" when unchecked
end
end
end
local button = CreateFrame("CheckButton", "Otvet1", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
button:SetHeight(20)
button:SetWidth(20)
button:ClearAllPoints()
button:SetPoint("CENTER", content2, "TOP", -220, -50) --Расположение Чекбаттона
_G[button:GetName() .. "Text"]:SetText("Ответ 1")
tinsert(content2.RadioButtons, button)
button:SetScript("OnClick", function(self)
ClearRadio(self)
if self:GetChecked() then
print(self:GetName(), "Checked")
-- do whatever this button does when checked
else
-- do whatever this button does when unchecked
end
end)
button:SetChecked(true) -- check button 1 (default)
button:GetScript("OnClick")(button) -- click button 1 (default)
button = CreateFrame("CheckButton", "Otvet2", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
button:SetHeight(20)
button:SetWidth(20)
button:ClearAllPoints()
button:SetPoint("CENTER", content2, "TOP", -220, -70) --Расположение Чекбаттона
_G[button:GetName() .. "Text"]:SetText("Ответ 2")
tinsert(content2.RadioButtons, button)
button:SetScript("OnClick", function(self)
ClearRadio(self)
if self:GetChecked() then
print(self:GetName(), "Checked")
-- do whatever this button does when checked
else
-- do whatever this button does when unchecked
end
end)
button = CreateFrame("CheckButton", "Otvet3", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
button:SetHeight(20)
button:SetWidth(20)
button:ClearAllPoints()
button:SetPoint("CENTER", content2, "TOP", -220, -90) --Расположение Чекбаттона
_G[button:GetName() .. "Text"]:SetText("Ответ 3")
tinsert(content2.RadioButtons, button)
button:SetScript("OnClick", function(self)
ClearRadio(self)
if self:GetChecked() then
print(self:GetName(), "Checked")
-- do whatever this button does when checked
else
-- do whatever this button does when unchecked
end
end)
button = CreateFrame("CheckButton", "Otvet4", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
button:SetHeight(20)
button:SetWidth(20)
button:ClearAllPoints()
button:SetPoint("CENTER", content2, "TOP", -220, -110) --Расположение Чекбаттона
_G[button:GetName() .. "Text"]:SetText("Ответ 4")
tinsert(content2.RadioButtons, button)
button:SetScript("OnClick", function(self)
ClearRadio(self)
if self:GetChecked() then
print(self:GetName(), "Checked")
-- do whatever this button does when checked
else
-- do whatever this button does when unchecked
end
end)