when you press one radio button from the rest the mark disappeared
5 Attachment(s)
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.
|
Do you mind if I ask what this line is for?
Lua Code:
I understand it defines a local table but I don’t have a clue about local underscore. Thanks. |
Quote:
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 :) |
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:
Lua Code:
When assigning variables, you can assign multiple on a single line Lua Code:
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:
It becomes very useful when you have a function which returns a lot of values, but you only need a few. Lua Code:
|
LanceDH
Thank you for the clarification |
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(...) 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:
|
@Fizzlemizz and @LanceDH thanks for the answers. It's much clearer now but it leads to another question. In the expression:
Lua Code:
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. |
addon.toc
Code:
... Code:
local _, Core = ... Code:
local _, Core = ... 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 |
In your other thread, these would be equivalent:
Lua Code:
This is way off topic but to elaborate further: Lua Code:
... 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. |
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:
|
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:
|
Quote:
I could not do it |
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:
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:
and I would not know that without your help, which I am really grateful for :) |
All times are GMT -6. The time now is 11:20 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI