Quantcast Concatenation problem - WoWInterface
Thread Tools Display Modes
05-04-15, 05:53 AM   #1
Benalish
A Theradrim Guardian
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 60
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?
  Reply With Quote
05-04-15, 08:04 AM   #2
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 329
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.

Last edited by suicidalkatt : 05-04-15 at 08:10 AM.
  Reply With Quote
05-04-15, 01:18 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,918
Originally Posted by suicidalkatt View Post
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.



Originally Posted by Benalish View Post
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.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-04-15 at 01:24 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Concatenation problem

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