Skip to content

Fix: dead/nodead conditions crash when target is nil #92

Description

@daemonp

The dead and nodead conditions in Conditionals.lua throw an error when conditionals.target is nil.

Error message:
ERROR: Interface\AddOns\Roid-Macros\Conditionals.lua:833: Usage: UnitIsDeadOrGhost("unit")

Cause

When using dead or nodead conditions without an explicit @target specifier, and no target is selected in-game (or autoSelfCast CVar is disabled), conditionals.target remains nil. The UnitIsDeadOrGhost() API call then fails because it receives nil instead of a valid unit ID.

Fix

Add a nil check to both functions that returns false if there's no target to check.

diff --git i/Conditionals.lua w/Conditionals.lua
index 85e0300..ae8bb1d 100644
--- i/Conditionals.lua
+++ w/Conditionals.lua
@@ -826,10 +826,12 @@ Roids.Keywords = {
     end,
 
     dead = function(conditionals)
+        if not conditionals.target then return false end
         return UnitIsDeadOrGhost(conditionals.target);
     end,
 
     nodead = function(conditionals)
+        if not conditionals.target then return false end
         return not UnitIsDeadOrGhost(conditionals.target);
     end,

Other similar functions like ValidatePower, ValidateRawPower, and ValidateHp already have this nil check pattern:
if not unit then return false end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions