Reference › Function reference › Conditions

Conditions.weapon.swingSpeed

dependency

Call as

Conditions.weapon.swingSpeed(value, cache)

Record the dependency Conditions.weapon.swingSpeed, then call it by that name. A namespaced call does not pass self: use a colon call or pass the object yourself.

What it does

Reads the player's main-hand, or off-hand when value.offhand is set, attack speed from the cached UnitAttackSpeed for the swing timer conditions. An off-hand check with no off-hand speed returns false.

Arguments

NameTypeWhat it does
valuetableCondition settings; a truthy offhand field selects the off hand.
cachetable | nilEvaluation-pass cache passed to getCached, or nil to read directly.

Returns

1number | boolean | nilSwing speed in seconds, false when there is no off-hand weapon, or nil when unavailable.
2string | nilReason for nil: missing-api, api-error, restricted-value or invalid-weapon-observation.

Editions

Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.

  • Not available on that edition (the reason is in the tooltip)
  • Only while Blizzard's deprecation fallbacks are on
Game APIClassic EraTBC AnniversaryClassic progressionForeverRetail
UnitAttackSpeedClassic EraTBC AnniversaryClassic progressionForeverRetail
UnitRangedDamageClassic EraTBC AnniversaryClassic progressionForeverRetail

How the addon calls it

Dependencies

Source

Conditions/weapon.lua, line 96. Read only in game; Duplicate makes an editable copy.

Conditions.weapon.swingSpeed(value, cache)
    -- Ranged: the Auto Shot or wand interval (UnitRangedDamage), false with no
    -- ranged attack; the melee hands read UnitAttackSpeed.
    if value.ranged then
        local speed,reason=Functions.cache.getCached(cache,addon.Platform.GetRangedSwingSpeed,addon.Platform)
        if speed==nil then return nil,reason end
        return speed
    end
    if type(UnitAttackSpeed)~="function" then return nil,"missing-api" end
    -- pcall forwards the mainhand and offhand speeds from the observation.
    ---@diagnostic disable-next-line: unbalanced-assignments
    local ok,main,off=pcall(addon.getCached,cache,UnitAttackSpeed,"player")
    if not ok then return nil,"api-error" end
    local speed=main
    if value.offhand then
        speed=off
        -- No off-hand weapon: the API returns no off-hand speed. That is a
        -- reading (nothing to swing), so off-hand checks are false.
        if speed==nil then return false end
    end
    return numericObservation(speed)

Back to Function reference