Quantcast WeakAuras: Shared functions withing a dynamic group - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
03-04-18, 06:37 AM   #1
FranekW
A Cyclonian
 
FranekW's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 41
WeakAuras: Shared functions withing a dynamic group

Is it possible to use some kind of "global" functions in WeakAuras environment, or global to a group, or to a dynamic group but still local in terms of WoW env? I could still refer to them when creating codes in Custom Triggers or Custom Text

[TL;DR]

I have created and completed a dynamic group in WeakAuras which contains a set of progress bars, which in turn track random buffs when you apply Rogue's Roll the Bones (based on Muzgu in Wowhead). The problem is Roll the Bones produces a number of buffs out of six in total. In terms of WA, each buff works exactly the same. The only difference is the buff itself. I had to copy and paste a lot of functions and change only one line. Because I created codes for Custom Text and Custom Triggers, for each buff, it was very laborious and prone to error. It would be much more effective and optimised, if I could place the core functions somewhere else within WA environment with a single parameter "buff_name".

For instance, for the buff "Broadsides", I created functions for custom text and custom trigger "Dynamic Info". The code for other buffs, such as "Jolly Roger", "Grand Melee", "Grand Melee", "Shark Infested Waters", "True Bearing", "Restless Blades", and "Buried Treasure" is exactly the same. I only change "buff_name". Below is an example of redundant functions and the third one which would handle everything in one place.
Thanks



Custom text:
Lua Code:
  1. -- Function for Custom Text
  2. function()
  3.     local buff_name = "Broadsides"
  4.     if UnitBuff("PLAYER", buff_name) then
  5.         dur, exptime = select(6, UnitBuff("PLAYER", buff_name))
  6.     end
  7.     return string.format("%.1f", max(0, dur + exptime - GetTime())), max(36, dur), true
  8. end

Custom Trigger "Dynamic Info"
Lua Code:
  1. -- Function for Custom Trigger Dynamic Info
  2. function()
  3.     local buff_name = "Broadsides"
  4.     if UnitBuff("PLAYER", buff_name) then
  5.         dur, exptime = select(6, UnitBuff("PLAYER", buff_name))
  6.     end
  7.     return max(0, dur + exptime - GetTime()), max(36, dur), true
  8. end
Example of an optimised function:

Lua Code:
  1. -- global function
  2. function(buff_name, format)
  3.     if UnitBuff("PLAYER", buff_name) then
  4.         dur, exptime = select(6, UnitBuff("PLAYER", buff_name))
  5.     end
  6.     out = {max(0, dur + exptime - GetTime()), max(dur, 36), true}
  7.     if format then
  8.         out[1] = string.format("%.1f", out[1])
  9.     end
  10.     return out
  11. end

Last edited by FranekW : 03-04-18 at 12:41 PM.
  Reply With Quote
 

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » WeakAuras: Shared functions withing a dynamic group

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