Thread Tools Display Modes
10-26-12, 12:15 AM   #1
Trololol
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2012
Posts: 13
Parsing string as a table/frame value

Hiya,
I'm pretty new to the LUA coding language, and am wanting to restructure my addon so that it doesn't use as much repetition and a lot less lines.
I am using XML framing for my addon instead of LUA frames.

The XML frames have the structure similar to this:

Lua Code:
  1. <frame name="1Keyf" hidden="true" inherits="whatever">
  2. <Scripts>
  3. <OnMouseDown>
  4. presskey(_,"1",1Keyf)
  5. </OnMouseDown>
  6. </Scripts>
  7. </frame>
  8.  
  9. <frame name="1Key"  inherits="whatever">
  10. <Scripts>
  11. <OnMouseDown>
  12. presskey(_,"1",1Keyf)
  13. </OnMouseDown>
  14. </Scripts>

Basically, there's a hidden frame on top of another frame. What it does is when I click the frame, it calls the function presskey with arguments of the key it's referring to, and the frame that's hidden.
presskey then sends an argument to push with the values key and frameval given from the click event.

What I'm wanting to do is be able to press a key to show the frame with the UIFrameFlash function.


Lua Code:
  1. VMainWindow:EnableKeyboard(true)
  2. VMainWindow:SetScript("OnKeyDown", presskey)
  3.  
  4. function presskey(self, key, frameval)
  5. --Since pressing a key does not refer to any frame, I need to make an if statement to see if it's nil
  6. if frameval == nil then
  7.    frameval = key.."Keyf" --problem line here
  8. end
  9.           push(key,frameval)
  10.           play(key)
  11. end

If I were to add a debug print(frameval) line after the if statement to see if frameval is nil, then:
If I press a key, I'd get the string "1Keyf"
If I press the frame with my mouse, I'd get "table: (table id)"

Lua Code:
  1. function push(key,frameval)
  2. --UIFrameFlash requires a frame value and not a string.
  3.         if UIFrameIsFlashing(frameval) then
  4.             UIFrameFlashStop(frameval)
  5.         end
  6.                 if ((key == 1  or key == 2) and not IsShiftKeyDown()) then
  7.                               UIFrameFlash(frameval, fIT, fOT, fD, false, fIHT, fOHT)
  8.                 end
  9. end
Since using the UIFrameFlash function requires a frame and not a string, how would I go around implementing this?
  Reply With Quote
10-26-12, 03:40 AM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
I think what you are looking for is _G[frameval]. _G contains all of the global variables, which can be accessed using keys.

Also, consider making your functions local by adding the 'local' keyword.
  Reply With Quote
10-26-12, 05:00 AM   #3
Trololol
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2012
Posts: 13
Just what I was looking for. Thanks!
  Reply With Quote
10-26-12, 05:34 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you need your functions to be global (which you do if you want to create your frames in XML) you should definitely not give them generic names like "push". Give them a name that clearly identifies them as part of your addon and is unlikely to collide with anything else, like "MyAddon_Push".
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-26-12, 06:08 PM   #5
Trololol
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jan 2012
Posts: 13
Originally Posted by Phanx View Post
If you need your functions to be global (which you do if you want to create your frames in XML) you should definitely not give them generic names like "push". Give them a name that clearly identifies them as part of your addon and is unlikely to collide with anything else, like "MyAddon_Push".
Yeah, that's what I've done. Thanks for the tip.
  Reply With Quote
10-26-12, 06:49 PM   #6
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Just a note that UIFrameFlash is one of those public functions that although it should be safe for use by addons is subject to cause taint issues.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Parsing string as a table/frame value


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