Skip to content
MattZeeX edited this page Jan 12, 2024 · 6 revisions

WeakAuras text fields support a certain level of dynamic replacement. These patterns are similar to the patterns you might have seen if you have any experience with string manipulation in Lua; they are always a % to signal that this text should be replaced, followed by a string of one or more characters, to signal what value should replace the pattern.


The following replacement patterns are supported natively:
  • %n - Name info. Prototype triggers will supply this information automatically. For example, a buff trigger looking for the "Beacon of Light" buff on the player will replace %n with Beacon of Light. If Dynamic Info points to a custom trigger, then %n will be replaced by the Name Info function's return value. If there is no such script, then the name of the aura itself will be used as a fallback.
  • %i - Icon info. This will be replaced with a texture escape string representing the icon (see here for more details on escape sequences). There is a checkbox in the display tab, labeled "Auto" or "Automatic Icon" (depending on the display type of the aura) which determines the behavior of this replacement pattern. If the box is unchecked, then whatever icon you specify in the box that appears below it will be what replaces %i. Otherwise, the displayed icon is determined by the dynamic info, similar to how %n works. If the Dynamic Info has no Icon info, then Interface\Icons\INV_Misc_QuestionMark (the red question mark on a black background) will be used as a fallback.
  • %p - Progress info. This will have one of two behaviors, depending on the progress type of the aura. If it is timed progress (all buff triggers are timed, for example), then %p will be replaced by the remaining duration of the buff. If it is static progress (a health trigger is static, for example), then %p will be replaced by the value attribute of the aura's state. %p will be formatted according to the selection of the Remaining time Precision dropdown menu in the Dispaly Tab. Both Progress and Total (see below) are supplied by the Duration Info of the aura.
  • %t - Total Info. In a timed progress aura, this will be the maximum duration of the aura. In a static progress aura, this will be the maximum value that %p can take.
  • %s - Stacks Info. This can take multiple meanings, depending on precisely what the trigger is set to. Traditionally, it is the number of stacks that a given buff will have, though you can also change that to the number of charges a spell has, or the size of the number in the tooltip of an aura, and a few other things which the the trigger will notify you of if it's available. In a custom trigger, this is supplied by the Stacks Info function, and falls back to the empty string if no value is available.
  • %c - Custom function. A new script editbox will appear, which will allow you to write a custom function, and replace the pattern with an arbitrary string. This function can return multiple values, and you choose which one you wish to replace by appending %c with a number (so, for example, %c3 will be replaced by the third value that the function returns). The script should look something like this (as always, remember that you can ignore the values passed in if you don't need them - a simple function() header will do if you won't be needing those values):
function(expirationTime, rawDuration, progress, formattedDuration, name, icon, stacks)
  -- some code
  -- The first two values passed in are the raw values set by the duration info from the trigger(s), and have not been formatted.
  -- The last 5, on the other hand values are precisely the strings that replace %p, %t, %n, %i, and %s, respectively. 
  -- Note that they have already been formatted, so trying to manipulate progress (say, by adding 5 to it) may not have the result you expect.
  return "some", "strings", "in", "a", "list", "like", "this"
end

Note:

If you directly follow a text replacement with more text instead of a space you can break WA's ability to catch the placeholder. In cases like this you can let WA know which is the text replacement bit by using curly brackets. For example:

  • %{p}seconds
  • %{s}count
  • %{2.p}seconds (see below for more about this one)

Info from specific triggers

You can display any of the text replacements available on triggers, even if the trigger in question isn't currently supplying Dynamic Info to your Aura using the trigger number, then a dot, then the replacement string. For example:

  • %2.p
  • %4.health
  • %3.unitName

These values can also be accessed via the custom text function using the aura_env.states table, accessing trigger 2's stacks value like so:

function()
    if aura_env.states and aura_env.states[2] then
    --Just the normal nil checking required, 
    -- as you would always need to when digging into a table's children
        return aura_env.states[2].stacks
    end
end

Custom text functions set to update on "Trigger Update" will fire when any trigger's values change.


Additional Replacement Patterns

Some triggers will supply additional information which is available to be used as a text replacement. You will be able to see what is supplied by hovering over a text field (a tooltip will explain what's available, like so. These are not ever formatted, so they may not be particularly pretty. For example, the %percenthealth replacement will have full precision, which is usually around 8 decimal places. You can format these values yourself, if you use a %c pattern instead, with a function like this:

function()
    if aura_env.state and aura_env.state.percenthealth then
        -- when WeakAuras sees %thing in a text field, it will attempt to replace that with whatever is in aura_env.state.thing
        -- so we can simply grab that value and format it in this function
        -- however, aura_env.state, or aura_env.state.thing may not exist when this function runs, so it's is best to check for nils
        return Round(aura_env.state.percenthealth) --anything returned will be cast into a string, so returning a number is fine.
    end
end