View Single Post
04/24/23, 08:22 AM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Also keep in mind that JumpToFriend could be used by ANY addon without the context menus or UI elements you know!
It also trigges if you just do /script JumpToFriend(@TestAccount) in your chat!

So if you want to do something delayed etc. based on entries at the vanilla UI context menus, hook into the context menus and not the final API function that some other addons might use too.

I'm still not sure WHAT EXACTLY you try to achieve here and why, and when? You mentioned a "visual" thing? Is something shown visually too early or too late? And what?


Lua Code:
  1. ZO_PreHook("JumpToFriend", function(displayName)
  2.         MyAddon.TravelToPlayerContext(displayName)
  3.         zo_callLater(function() return false end, effectDelay)
  4.     end)

This will call JumpToFriend and execute the code normal,
call your function MyAddon.TravelToPlayerContext(displayName) (whatever it does. If this calls JumpToFriend you got an endless loop now! :-) ).
including the jump start to your friend at the end of that function call to JumpToFriend.

After that it will return a false which never is passed to the prehook of JumpToFriend as you have called it with zo_callLater in that "closure" of zo_callLater(function() ... end. So the return false will be passed to the PreHook of JumpToFriend but not from that back to the calling code where it would be needed.
But as a return false or nil is not needed at all in a ZO_PreHook it will just do the same as a normal JumpToFriend would do: Jmp to the displayname! Without delay! Normal!

What you thought off was this maybe:

Lua Code:
  1. local preventEndlessLoop = false
  2. ZO_PreHook("JumpToFriend", function(displayName)
  3.     if preventEndlessLoop then return true end --check for endless loop protection as this is called from JumpToFriend ZO_PreHook, and abort here with true -> Abort JumpToFriend
  4.     MyAddon.TravelToPlayerContext(displayName) --call your visual stuff here
  5.     zo_callLater(function()
  6.         preventEndlessLoop = true   --prevent an endless loop as we call JumpToFriend from JumpToFriend ...
  7.         jumpToFriend(displayName)
  8.         preventEndlessLoop = false  -end prevent an endless loop as we call JumpToFriend from JumpToFriend ...
  9.     end, effectDelay) --delay the call to JumpToFriend a bit
  10.     return true --prevent original JumpToFriend
  11.  end)

Still, you got the problemw ith return true here, maybe breaking other addons, maybe not.
I'd rather check if you could skip and PreHook here and achieve whatever you want by other means.

Last edited by Baertram : 04/24/23 at 08:32 AM.
  Reply With Quote