Thread Tools Display Modes
12-05-22, 02:26 PM   #1
Suilixua
A Murloc Raider
Join Date: Dec 2022
Posts: 4
Need help to check which width is greater

Basically I have a resource bar in WeakAuras and above is my primary dynamic group and below the resource Bar I got a secondary dynamic group.
I want that the resource Bar adjust the size depending on which of those 2 grps has a bigger width overall.

I tried it with

Code:
WeakAuras.regions[aura_env.id].region:SetFrameLevel(1)

if(not ProgressBarHooked)then
    local upEnv = aura_env;
    local function setWidthHook(self,width)
        upEnv.region:SetRegionWidth(width);
    end
    
    local topGroupRegion = WeakAuras.GetRegion("Demon Hunter » Primary Bar");
    local bottomGroupRegion = WeakAuras.GetRegion("Demon Hunter » Secondary Bar");
    
    topGroupRegionParent = topGroupRegion:GetParent();
    bottomGroupRegionParent = bottomGroupRegion:GetParent();
    
    
    if topGroupRegionParent:GetWidth() > bottomGroupRegionParent:GetWidth() then
        hooksecurefunc(topGroupRegion,"SetWidth",setWidthHook);
    else
        hooksecurefunc(bottomGroupRegion,"SetWidth",setWidthHook);
        ProgressBarHooked = true;
    end
end

Somehow it only uses the width of the secondary bar, eventhough the primary bar has a larger width.

If I change at the bottom the <"bottomGroupRegion, "SetWidth"> etc. with "topGroupRegion" it only adjusts to the primary bar.

So I guess I miss some small detail and would appreciate help.

https://medal.tv/clips/L0yaUaqwofV76...MTQ5MjMyNDM0LA - here u can see the problem in action

Last edited by Suilixua : 12-05-22 at 06:15 PM.
  Reply With Quote
12-05-22, 07:45 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
First of all, I honestly don't see a problem with the video. The bar between the groups matched the longest group the entire time. Do you have a better example video?

Secondly, there's a logic issue with your code. Let's go through some scenarios.
Scenario 1: top larger, stays the largest one each run
Result: code will hook top SetWidth each time it runs, eventually resulting in lag each SetWidth call that gets worse (setWidthHook gets spammed)

Scenario 2: top larger, then bottom larger, then top larger
Result: code hooks SetWidth on top, then hooks bottom SetWidth, then never runs again. Both SetWidths call setWidthHook, giving the top width then the bottom width. Because of hook order, only the bottom width is used because it was last.

Scenario 3: bottom larger
Result: like #2, but it doesn't matter what happens after, the code will only run once and only be hooked to bottom.
Hooks are immutable. You can't get rid of them unless you overwrite the hooked function (or reload/relog). They also stack theoretically infinitely to the point where the game would just freeze when the hooked function is called. You should only ever hook a specific function once, find some way to switch things inside the function object you put on the hook while hooking both elsewhere first.

Also, sorry to potentially confuse you further, but you should try to avoid hooking or otherwise permanently messing with a weakaura's region. Weakauras pools its frames, and in some clone situations there's a chance a hooked region may be reused by another clone or even another weakaura. I don't think this particular hook/region will have any issues, just parroting the drivel the WA devs tell people. I suggest using WeakAuras.ScanEvents to communicate between the resource bar and the other bars.
  Reply With Quote
12-06-22, 02:26 AM   #3
Suilixua
A Murloc Raider
Join Date: Dec 2022
Posts: 4
Guess I posted the wrong link or my medal did sth wrong.
Here is a better one: https://medal.tv/games/world-of-warc...MTQ5MjMyNDM0LA

It works well for the secondary Bar but as soon as I add another thing on the upper Bar it doesnt change and stays at the size of the bottom one.


Okay, thats good to know already.
Didnt know all the things, im def. a beginner with all the lua stuff.

One thing I dont understand is that even if the top Bar is larger than the bottom one, the resource Bar still uses only the bottom size, even after a reload, but if I understood it correctly it should basically use the upper Bar size?


So I guess I have to read into the ScanEvents thing or find somehow another solution with the hooking and function stuff, which I def. have to read a few times more prolly to fully understand it.

But thanks a lot already for the help, really appreciate it.
  Reply With Quote
12-06-22, 07:41 AM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Ah, I seem to have saw your video link early, it only had the second video. I think you added the one on top after I viewed the link.

As for the logic, only the bottom bar will be followed eventually, as I described in the scenarios. I'd help you with something that may work logically but I've been away from my computer for quite some time. Dry-coding something on my phone is about as fun as sweeping a basketball gym clean with a paint brush.
  Reply With Quote
12-06-22, 01:53 PM   #5
Suilixua
A Murloc Raider
Join Date: Dec 2022
Posts: 4
That makes sense, the first video was my always go to solution but with the new talent tree we got, jesus, that would be so much effort with all the conditions for all the classes/specs I might wanna play.

Yea, I just can imagine how this would feel.
I will try to read somehow into it or maybe find sth. which could help me out -- appreciated!
  Reply With Quote
12-07-22, 02:45 PM   #6
Suilixua
A Murloc Raider
Join Date: Dec 2022
Posts: 4
Found something which helped me a lot and it's finally done and working the exact same way as I wanted it to be.

Once again, thank you so much.
  Reply With Quote

WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » Need help to check which width is greater


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