WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Concatenation problem (https://www.wowinterface.com/forums/showthread.php?t=52265)

Benalish 05-04-15 05:53 AM

Concatenation problem
 
Hi all. This is a fuction of my code

Lua Code:
  1. function onAdvancedOptionClose()
  2.     local options = { 'duration', 'stack' }
  3.     for i=1, #options do
  4.         local option = options[i]
  5.  
  6.         if not db[option] then
  7.             db[option] = { minimum = {}, maximum = {} }
  8.         end
  9.  
  10.         db[option].minimum = {
  11.             enabled = ["min"..option].cbutton:GetChecked(),
  12.             value = tonumber(["min"..option].ebox:GetText())
  13.         }
  14.  
  15.         db[option].maximum = {
  16.             enable = ["max"..option].cbutton:GetChecked(),
  17.             value = tonumber(["max"..option].ebox:GetText())
  18.         }
  19.  
  20.     end
  21. end

This code returns this error:

unexpected symbol near "["

in correspondence of line

enabled = ["min"..option].cbutton:GetChecked(),

Is a concatenation lua problem? There is a solution?

suicidalkatt 05-04-15 08:04 AM

Your line there:
Lua Code:
  1. enabled = ["min"..option].cbutton:GetChecked(),

You're trying to reference some table "minduration"? Does this table exist? If so you can't reference it in this manner.

It looks like you're trying to find a checkbox and determining if it's checked or not.

Please post your full code to give a better interpretation.

If this table is global, you can find it within the global namespace as follows:
Lua Code:
  1. enabled = _G["min"..option].cbutton:GetChecked(),

That being said, a global with that name is just asking for trouble.

SDPhantom 05-04-15 01:18 PM

Quote:

Originally Posted by suicidalkatt (Post 308587)
That being said, a global with that name is just asking for trouble.

To further expand on this, all addons share the global namespace along with the default UI. Generic names like minduration is likely to cause problems with other addons because they would be accessing the same variable, causing data corruption. This is why it's standard practice to prefix any globals with the name of your addon.



Quote:

Originally Posted by Benalish (Post 308586)
This code returns this error:

unexpected symbol near "["

in correspondence of line

enabled = ["min"..option].cbutton:GetChecked(),

Is a concatenation lua problem? There is a solution?

This error has nothing to do with concatenation. The brackets [] are used as indexing operators on tables and you haven't specified a table to index.


All times are GMT -6. The time now is 02:54 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI