WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   If(...) will not be executed. (https://www.wowinterface.com/forums/showthread.php?t=50385)

Tuetenpenner 11-07-14 12:29 PM

If(...) will not be executed.
 
This is my first Addon and I need some Help. The if() which includes the function FollowUnit() will not be executed. Also my OnWhisper() function seems to be executed twice.

Lua Code:
  1. local f = CreateFrame("Frame");
  2. f:RegisterEvent("CHAT_MSG_WHISPER");
  3. f:RegisterEvent("CHAT_MSG_BN_WHISPER");
  4.  
  5. function Follower_OnLoad()
  6.     DEFAULT_CHAT_FRAME:AddMessage("Follower Loaded!", 1.0, 0.0, 0.0, 3.0);
  7. end
  8.  
  9. f:SetScript("OnEvent", function(self, event, ...)
  10.     if(event == "CHAT_MSG_WHISPER" or "CHAT_MSG_BN_WHISPER") then
  11.         local arg1, arg2 = ...
  12.  
  13.             if(event == "CHAT_MSG_BN_WHISPER") then -- Yet no function.
  14.  
  15.             end
  16.  
  17.             OnWhisper(arg1, arg2)
  18.     end
  19. end)
  20.  
  21. function OnWhisper(arg1, arg2) -- The whole function seems to be executed twice.
  22.     if (arg1 == "f_follow") then
  23.         print("Following " .. arg2)
  24.  
  25.             if (CheckInteractDistance(arg2, 4)) then -- This part will not be executed. Instead it goes to the else part.
  26.                 FollowUnit(arg2)
  27.             else
  28.                 SendChatMessage("I'm too far away to follow you!", "WHISPER", nil, arg2)
  29.             end
  30.     end
  31. end

semlar 11-07-14 12:33 PM

A player's name is not a valid unitID unless they're in your group.

In other words.. you can run FollowUnit on an arbitrary player name, but you can't run CheckInteractDistance on someone's name who isn't in your group.

Tuetenpenner 11-07-14 12:36 PM

Ok but it doesn't work with characters in a group too. I tried the function with a macro and that did work.

semlar 11-07-14 12:40 PM

Strip the realm out of their name, eg. arg2:match('^[^-]+')


All times are GMT -6. The time now is 07:52 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI