Quantcast when you press one radio button from the rest the mark disappeared - WoWInterface
Thread Tools Display Modes
01-06-19, 01:46 AM   #1
Rusmikey
A Murloc Raider
Join Date: May 2018
Posts: 5
when you press one radio button from the rest the mark disappeared

Good afternoon, I'm trying to do an addon test, but I can't make it so that when I select one answer option, the label drops from the others. Help me please.
Attached Files
File Type: lua config.lua (10.2 KB, 12 views)
File Type: lua init.lua (2.6 KB, 17 views)
File Type: tga help.tga (355.2 KB, 12 views)
File Type: tga perviy.tga (78.7 KB, 10 views)
File Type: tga perviyy.tga (98.4 KB, 10 views)
  Reply With Quote
01-06-19, 04:27 AM   #2
FranekW
A Deviate Faerie Dragon
 
FranekW's Avatar
Join Date: Mar 2018
Posts: 17
Do you mind if I ask what this line is for?

Lua Code:
  1. local _, core = ...;

I understand it defines a local table but I don’t have a clue about local underscore. Thanks.

Last edited by FranekW : 01-06-19 at 04:30 AM.
  Reply With Quote
01-06-19, 04:43 AM   #3
Rusmikey
A Murloc Raider
Join Date: May 2018
Posts: 5
Originally Posted by FranekW View Post
Do you mind if I ask what this line is for?

Lua Code:
  1. local _, core = ...;

I understand it defines a local table but I donít have a clue about local underscore. Thanks.

I do not know English well, but I hope you will understand me. I recently started practicing Lua and therefore make mistakes and do not understand everything
  Reply With Quote
01-06-19, 06:47 AM   #4
LanceDH
An Aku'mai Servant
 
LanceDH's Avatar
Join Date: Aug 2012
Posts: 32
This is off topic to the main question, but in the spirit of explaining code:

... is a collection of multiple variables.
Say you have a
Lua Code:
  1. function test(...)
And you call it using
Lua Code:
  1. test(1, true, "three")
... will contain the values 1, true, and "three" in that order.

When assigning variables, you can assign multiple on a single line
Lua Code:
  1. local a, b, c = ...
Will then assign 1 to a, true to b, and "three" to c
The underscore variables is typically used as a throwaway variable for values you don't care about.
So if you only care for the third variables you can type
Lua Code:
  1. local _, _, value = ...
If I'm not mistaken, the _ will all end up as one variable, so it's both easier to read and more optimized.
It becomes very useful when you have a function which returns a lot of values, but you only need a few.
Lua Code:
  1. local n, _, _, header, _, _, _, id, _, _, _, _, _, _, _, hidden = GetQuestLogTitle(i);
  Reply With Quote
01-06-19, 07:43 AM   #5
Rusmikey
A Murloc Raider
Join Date: May 2018
Posts: 5
LanceDH
Thank you for the clarification
  Reply With Quote
01-06-19, 11:58 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 977
Rusmikey: Think of each .lua file as a function in its own right and each file is passed several (currently two paramters). The first is the name of the addon the file is in and, the second is a table that is exclusive to and available to all .lua files under the addon. The table can be used for sharing data/functions etc. between .lua files in the addon.

When you see something like local _,Core = ... (usually) near the beginning of a .lua file, that is the "file" retrieving these "parameters" (as mentioned, the _ is usualy used as a throwaway parameter)
Code:
function Code.lua(...)
     local _, Core = ...
--or 
    local addonName, Core = ...
--or
   local Addon, NS = ...
end

The UIRadioButtonTemplate doesn't do anything on it own other than just display a checkbutton that looks like a radio button. You have to add the OnClick code to de-select the other buttons when each one is clicked.

Lua Code:
  1. <CheckButton name="UIRadioButtonTemplate" virtual="true">
  2.         <Size>
  3.             <AbsDimension x="16" y="16"/>
  4.         </Size>
  5.         <Layers>
  6.             <Layer level="BACKGROUND">
  7.                 <FontString name="$parentText" inherits="GameFontNormalSmall" parentKey="text">
  8.                     <Anchors>
  9.                         <Anchor point="LEFT" relativePoint="RIGHT">
  10.                             <Offset>
  11.                                 <AbsDimension x="5" y="0"/>
  12.                             </Offset>
  13.                         </Anchor>
  14.                     </Anchors>
  15.                 </FontString>
  16.             </Layer>
  17.         </Layers>
  18.         <NormalTexture file="Interface\Buttons\UI-RadioButton">
  19.             <TexCoords left="0" right="0.25" top="0" bottom="1"/>
  20.         </NormalTexture>
  21.         <HighlightTexture file="Interface\Buttons\UI-RadioButton" alphaMode="ADD">
  22.             <TexCoords left="0.5" right="0.75" top="0" bottom="1"/>
  23.         </HighlightTexture>
  24.         <CheckedTexture file="Interface\Buttons\UI-RadioButton">
  25.             <TexCoords left="0.25" right="0.5" top="0" bottom="1"/>
  26.         </CheckedTexture>
  27. </CheckButton>
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-06-19 at 12:04 PM.
  Reply With Quote
01-06-19, 12:59 PM   #7
FranekW
A Deviate Faerie Dragon
 
FranekW's Avatar
Join Date: Mar 2018
Posts: 17
@Fizzlemizz and @LanceDH thanks for the answers. It's much clearer now but it leads to another question. In the expression:

Lua Code:
  1. local _, core = ...

what exactly does the table "core" contains? I don't understand how a lua file can pass anything outside. Do we create that table at the end of a file? If I use a function analogy, we can return anything if we use "return" but with file, it's confusing. Thanks.

Last edited by FranekW : 01-06-19 at 01:02 PM.
  Reply With Quote
01-06-19, 01:19 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 977
addon.toc
Code:
...
File1.lua
File2.lua
File1.lua
Code:
local _, Core = ...
Core.Hello = "Hello from file 1"
File2.lua
Code:
local _, Core = ...
print(Core.Hello)
prints "Hello from file 1"


The table (Core in this case) is created by the game and passed to each .lua file, it is not global. It can only be seen by other .lua files in the same addon (not xml files). The table starts off empty but your addon can use it as you see fit.

You don't "return" anything from the file, "function" was used to describe those arguments you may see in wow .lua files where ... seemingly appears "out-of-the-blue" rather than as actual function parameters
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
01-06-19, 08:18 PM   #9
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 973
In your other thread, these would be equivalent:
Lua Code:
  1. local _, HiddenFrames = ...
  2. print(type(HiddenFrames))
  3. -- >>> "table"
  4.  
  5. local HiddenFrames = LibStub("AceAddon-3.0"):NewAddon("HiddenFrames")
  6. print(type(HiddenFrames))
  7. -- >>> "table"
Both HiddenFrames are tables, initially empty, which you populate with whatever you see fit: functions, variables, more tables. You don't want to duplicate yourself, so pick one of the two above, and don't use both.

This is way off topic but to elaborate further:
Lua Code:
  1. local folderName, HiddenFrames = ...
  2. print(folderName)
  3. -- >>> "HiddenFrames"
  4.  
  5. print(type(folderName))
  6. -- >>> "string"

... is a variable argument, or vararg for short. It contains a variable quantity of variables, in this case, a quantity of two: a string and a table.

Last edited by myrroddin : 01-06-19 at 08:21 PM. Reason: explaining vararg
  Reply With Quote
01-07-19, 12:33 AM   #10
Rusmikey
A Murloc Raider
Join Date: May 2018
Posts: 5
Thank you all for the help. That's how you solved the problem.
The code will be huge, but there is nowhere to go
Lua Code:
  1. function buttonuncheked_Click()
  2.         Otvet1:SetChecked();
  3.         Otvet2:SetChecked();
  4.         Otvet3:SetChecked();
  5.         Otvet4:SetChecked();
  6.        
  7.     end
  8.    
  9.     function button1_Click()
  10.         buttonuncheked_Click();
  11.         Otvet1:SetChecked(true);
  12.     end
  13.    
  14.     function button2_Click()
  15.         buttonuncheked_Click();
  16.         Otvet2:SetChecked(true);
  17.     end
  18.    
  19.     function button3_Click()
  20.         buttonuncheked_Click();
  21.         Otvet3:SetChecked(true);
  22.     end
  23.    
  24.     function button4_Click()
  25.         buttonuncheked_Click();
  26.         Otvet4:SetChecked(true);
  27.     end
  Reply With Quote
01-07-19, 03:14 AM   #11
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 977
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:
  1. content2.RadioButtons = {}
  2. local function ClearRadio(self)
  3.     if not self:GetChecked() then return end -- only action if a radio is checked when it's clicked
  4.     for i=1, #content2.RadioButtons do
  5.         local button = content2.RadioButtons[i]
  6.         if button ~= self and button:GetChecked() then
  7.             print(button:GetName(), "Unchecked")
  8.             button:SetChecked(false) -- Set other radio buttons unchecked
  9.             button:GetScript("OnClick")(button) -- Call the "OnClick" script if the buttons need to "do stuff" when unchecked
  10.         end
  11.     end
  12. end
  13. local button = CreateFrame("CheckButton", "Otvet1", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  14. button:SetHeight(20)
  15. button:SetWidth(20)
  16. button:ClearAllPoints()
  17. button:SetPoint("CENTER", content2, "TOP", -220, -50) --Расположение Чекбаттона
  18. _G[button:GetName() .. "Text"]:SetText("Ответ 1")
  19. tinsert(content2.RadioButtons, button)
  20. button:SetScript("OnClick", function(self)
  21.     ClearRadio(self)
  22.     if self:GetChecked() then
  23.         print(self:GetName(), "Checked")
  24.         -- do whatever this button does when checked
  25.     else
  26.         --  do whatever this button does when unchecked
  27.     end
  28. end)
  29. button:SetChecked(true) -- check button 1 (default)
  30. button:GetScript("OnClick")(button) -- click button 1 (default)
  31.  
  32. button = CreateFrame("CheckButton", "Otvet2", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  33. button:SetHeight(20)
  34. button:SetWidth(20)
  35. button:ClearAllPoints()
  36. button:SetPoint("CENTER", content2, "TOP", -220, -70) --Расположение Чекбаттона
  37. _G[button:GetName() .. "Text"]:SetText("Ответ 2")
  38. tinsert(content2.RadioButtons, button)
  39. button:SetScript("OnClick", function(self)
  40.     ClearRadio(self)
  41.     if self:GetChecked() then
  42.         print(self:GetName(), "Checked")
  43.         -- do whatever this button does when checked
  44.     else
  45.         -- do whatever this button does when unchecked
  46.     end
  47. end)
  48.  
  49. button = CreateFrame("CheckButton", "Otvet3", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  50. button:SetHeight(20)
  51. button:SetWidth(20)
  52. button:ClearAllPoints()
  53. button:SetPoint("CENTER", content2, "TOP", -220, -90) --Расположение Чекбаттона
  54. _G[button:GetName() .. "Text"]:SetText("Ответ 3")
  55. tinsert(content2.RadioButtons, button)
  56. button:SetScript("OnClick", function(self)
  57.     ClearRadio(self)
  58.     if self:GetChecked() then
  59.         print(self:GetName(), "Checked")
  60.         -- do whatever this button does when checked
  61.     else
  62.         -- do whatever this button does when unchecked
  63.     end
  64. end)
  65.  
  66. button = CreateFrame("CheckButton", "Otvet4", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  67. button:SetHeight(20)
  68. button:SetWidth(20)
  69. button:ClearAllPoints()
  70. button:SetPoint("CENTER", content2, "TOP", -220, -110) --Расположение Чекбаттона
  71. _G[button:GetName() .. "Text"]:SetText("Ответ 4")
  72. tinsert(content2.RadioButtons, button)
  73. button:SetScript("OnClick", function(self)
  74.     ClearRadio(self)
  75.     if self:GetChecked() then
  76.         print(self:GetName(), "Checked")
  77.         -- do whatever this button does when checked
  78.     else
  79.         -- do whatever this button does when unchecked
  80.     end
  81. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-07-19 at 03:19 AM.
  Reply With Quote
01-07-19, 05:10 AM   #12
Rusmikey
A Murloc Raider
Join Date: May 2018
Posts: 5
Originally Posted by Fizzlemizz View Post
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:
  1. content2.RadioButtons = {}
  2. local function ClearRadio(self)
  3.     if not self:GetChecked() then return end -- only action if a radio is checked when it's clicked
  4.     for i=1, #content2.RadioButtons do
  5.         local button = content2.RadioButtons[i]
  6.         if button ~= self and button:GetChecked() then
  7.             print(button:GetName(), "Unchecked")
  8.             button:SetChecked(false) -- Set other radio buttons unchecked
  9.             button:GetScript("OnClick")(button) -- Call the "OnClick" script if the buttons need to "do stuff" when unchecked
  10.         end
  11.     end
  12. end
  13. local button = CreateFrame("CheckButton", "Otvet1", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  14. button:SetHeight(20)
  15. button:SetWidth(20)
  16. button:ClearAllPoints()
  17. button:SetPoint("CENTER", content2, "TOP", -220, -50) --Расположение Чекбаттона
  18. _G[button:GetName() .. "Text"]:SetText("Ответ 1")
  19. tinsert(content2.RadioButtons, button)
  20. button:SetScript("OnClick", function(self)
  21.     ClearRadio(self)
  22.     if self:GetChecked() then
  23.         print(self:GetName(), "Checked")
  24.         -- do whatever this button does when checked
  25.     else
  26.         --  do whatever this button does when unchecked
  27.     end
  28. end)
  29. button:SetChecked(true) -- check button 1 (default)
  30. button:GetScript("OnClick")(button) -- click button 1 (default)
  31.  
  32. button = CreateFrame("CheckButton", "Otvet2", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  33. button:SetHeight(20)
  34. button:SetWidth(20)
  35. button:ClearAllPoints()
  36. button:SetPoint("CENTER", content2, "TOP", -220, -70) --Расположение Чекбаттона
  37. _G[button:GetName() .. "Text"]:SetText("Ответ 2")
  38. tinsert(content2.RadioButtons, button)
  39. button:SetScript("OnClick", function(self)
  40.     ClearRadio(self)
  41.     if self:GetChecked() then
  42.         print(self:GetName(), "Checked")
  43.         -- do whatever this button does when checked
  44.     else
  45.         -- do whatever this button does when unchecked
  46.     end
  47. end)
  48.  
  49. button = CreateFrame("CheckButton", "Otvet3", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  50. button:SetHeight(20)
  51. button:SetWidth(20)
  52. button:ClearAllPoints()
  53. button:SetPoint("CENTER", content2, "TOP", -220, -90) --Расположение Чекбаттона
  54. _G[button:GetName() .. "Text"]:SetText("Ответ 3")
  55. tinsert(content2.RadioButtons, button)
  56. button:SetScript("OnClick", function(self)
  57.     ClearRadio(self)
  58.     if self:GetChecked() then
  59.         print(self:GetName(), "Checked")
  60.         -- do whatever this button does when checked
  61.     else
  62.         -- do whatever this button does when unchecked
  63.     end
  64. end)
  65.  
  66. button = CreateFrame("CheckButton", "Otvet4", content2, "UIRadioButtonTemplate") --frame указывает на то чтобы кнопка прилипла к общему окну и была с ним взаимосвязана
  67. button:SetHeight(20)
  68. button:SetWidth(20)
  69. button:ClearAllPoints()
  70. button:SetPoint("CENTER", content2, "TOP", -220, -110) --Расположение Чекбаттона
  71. _G[button:GetName() .. "Text"]:SetText("Ответ 4")
  72. tinsert(content2.RadioButtons, button)
  73. button:SetScript("OnClick", function(self)
  74.     ClearRadio(self)
  75.     if self:GetChecked() then
  76.         print(self:GetName(), "Checked")
  77.         -- do whatever this button does when checked
  78.     else
  79.         -- do whatever this button does when unchecked
  80.     end
  81. end)
Thanks for your time. Checked code works very cool
I could not do it
  Reply With Quote
01-07-19, 05:46 AM   #13
FranekW
A Deviate Faerie Dragon
 
FranekW's Avatar
Join Date: Mar 2018
Posts: 17
First, I understand now I should have started a new topic. I feel like I stole it from OP! I did not realise asking about one character in a short line would elaborate to a couple of major answers. It would be much better to move posts answered my questions to a new thread.

Second, thanks for clarification. Now I understand why lua files in each addon starts with one of those lines. Still, people create addons using different ways and without clarifications here it would be much more difficult to me to understand it. For instance, Core.lua in Altoholic begins like this:

Lua Code:
  1. local addonName = ...
  2.  
  3. _G[addonName] = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0", "AceSerializer-3.0", "AceTimer-3.0", "LibMVC-1.0")

I guess the idea is to use _G to share addon table between files. My understanding is that "sharing" would also be accomplished if Author wrote this as a first line:

Lua Code:
  1. local Altoholic = LibStub("AceAddon-3.0"):NewAddon(addonName, "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0", "AceSerializer-3.0", "AceTimer-3.0", "LibMVC-1.0")

and I would not know that without your help, which I am really grateful for
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » when you press one radio button from the rest the mark disappeared

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off