Thread Tools Display Modes
11-07-14, 12:29 PM   #1
Tuetenpenner
A Defias Bandit
Join Date: Nov 2014
Posts: 2
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

Last edited by Tuetenpenner : 11-07-14 at 12:33 PM.
  Reply With Quote
11-07-14, 12:33 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.

Last edited by semlar : 11-07-14 at 12:36 PM.
  Reply With Quote
11-07-14, 12:36 PM   #3
Tuetenpenner
A Defias Bandit
Join Date: Nov 2014
Posts: 2
Ok but it doesn't work with characters in a group too. I tried the function with a macro and that did work.
  Reply With Quote
11-07-14, 12:40 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Strip the realm out of their name, eg. arg2:match('^[^-]+')
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » If(...) will not be executed.

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