1. #1
    The Lightbringer Lovestar's Avatar
    10+ Year Old Account
    Join Date
    Nov 2010
    Location
    United States
    Posts
    3,075

    Efficiently changing many Frame settings at one time

    Let me start by telling you I have no experience with programming. Tinkering around with LUA in WoW is the closest thing to programming I've ever done in my life. So this is probably a very simplistic problem, be patient with me. :>

    I want to know how to quickly set a lot of Frame:(function) settings at one time, without calling out every single Frame individually, since they all have really similar names. I've tried something like (in pseudocode):
    Code:
    iterate through i = 1,12
    for each one, do:
    someVariable = "MultiBarRightButton" .. i
    someVariable:DoFrameFunctionThing(ponies)

    But LUA really, really did not like this. So I've learned that's not the right way to do it, and I'm probably trying to do something very silly because I'm rather ignorant of how all this really works. What is the proper way to do this?

    -----

    For background, I'm making a simple personal addon which hides the default Blizzard actionbars. I don't need to replace them, I just want to toggle them on and off in order to free up screen-estate.

    I can't use MainMenuBar:Hide() for this, because then any stance change doesn't keybind properly (eg, leaving Stealth causes your keybinds to still try to trigger Stealth bar abilities). So I switched to using MainMenuBar:SetAlpha(0), which works a treat and even seems to be allowed in combat. The problem is, I've discovered with Alpha just set to zero the bars still respond to mouse clicks, which makes for some weird accidental actions and annoying tooltips popping up.

    No problem, I'll just go MainMenuBar:EnableMouse(false). Except that doesn't affect any of the buttons inside it (unlike Hide and SetAlpha). So now my next solution is to set up some sort of function which will iterate through all the similarly-named buttons inside the default Blizz bar, and toggle their mouse interactivity on and off.

    And that's why I'm looking for how to change lots of Frames' settings in one go without calling every single one out individually. I mean I could brute-force it like that, but I'm trying to learn how to do things a little smarter. Any help is appreciated. :>

  2. #2
    Deleted
    Code:
    for i=1,12 do -- there's an optional third parameter to for which specifies step size if you're interested - it defaults to "1" though, so we're in fact doing 'for i=1,12,1 do'
        local f = _G[("MultiBarRightButton%d"):format(i)] -- I believe string.format is more efficient with numeric values than simple concatenation. I could be wrong. Use _G[] to access the global environment with variable key names.
        f:YourFunction(args) -- obviously
    end -- terminate the loop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •