Thread Tools Display Modes
03/17/23, 12:02 PM   #1
nilo
Join Date: Feb 2022
Posts: 15
Questions about events, RegisterForEvent, RegisterForUpdate, ..

Atm I have a texture on screen when my role = LFG_ROLE_INVALID and this texture changes when I enter group according to my selected role. You can see in the ss how I'm doing it atm, however I want to do it more efficiently. I want to find a way to only UpdateMyRole when event EVENT_GROUP_MEMBER_ROLES_CHANGED is detected, I've tried a couple different ways using RegisterForEvent and RegisterForUpdate but no sucess and I can't find good info on how to use this and events in general.
Also I would like to know how impactful it is to game performance to use this "zo_callLater(function() LGRI.UpdateMyRole(myNewRole) end, 100)" as you can see inside my function LGRI.UpdateMyRole(roleId), and if it's good practice or not
Attached Thumbnails
Click image for larger version

Name:	3.PNG
Views:	255
Size:	45.7 KB
ID:	1548  
  Reply With Quote
03/17/23, 12:54 PM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
RegisterForEvent is used with the EVENT_* constants and that events fire automatically by the game at some defined trigger.
You register a callback fnction hat is executed as the event triggers by the game.

RegisterForUpdate is a kind of a repeated check every n milliseconds where a callback function that you define is called each time.
So this is done to repetivle do checks every n milliseconds, like an OnUpdate task during moving controls on the screen, or check every n milliseconds if you are grouped etc. (-> makes not sense as if you get grouped or leave group there are events that fire and you can react on them instead of constantly check every n milliseconds something that cannot change without those events having fired).

zo_callLater is using RegisterForUpdate and calls your callback function the delay later that you have defined.
In some circumstances it's okay to use it as some data will not be updated "instantly", but as events fire the data of the events should be fine and a zo_callLater should not be needed there (unless you check anything that is not related to the particular event).

Perfomance wise it's always bet to use events, and register event filters (if possible) as they will be called at C code, before the lua event even triggers. If the filter say "event is not needed for you" it's the best as no lua code of your callback function will be called at all! (e.g. in combat/buff events filter for unit tag "player" to only see ylur combat related stuff, and strip other group player's or enemy cobmat/buff stuff).

Last edited by Baertram : 03/17/23 at 12:58 PM.
  Reply With Quote
03/17/23, 01:01 PM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
Events: https://wiki.esoui.com/Events
Event filters: https://wiki.esoui.com/AddFilterForEvent

Registering your event callback function:

Lua Code:
  1. local function callbackFuncForThisEvent(eventI, param1, param2)
  2.  --do your stuff here
  3. end
  4. EVENT_MANAGER:RegisterForEvent("UniqueNameHere_forExmaple_MyAddon_EVENT_ADD_ON_LOADED", EVENT_ADD_ON_LOADED, callbackFuncForThisEvent)

Unregistering your event callback function if not needed anymore
Lua Code:
  1. EVENT_MANAGER:UnregisterForEvent("SameUniqueNameHereWhchWasUsedToReisterIt_inThisExample_MyAddon_EVENT_ADD_ON_LOADED", EVENT_ADD_ON_LOADED)
  Reply With Quote
03/17/23, 05:09 PM   #4
nilo
Join Date: Feb 2022
Posts: 15
Originally Posted by Baertram View Post
RegisterForEvent is used with the EVENT_* constants and that events fire automatically by the game at some defined trigger.
You register a callback fnction hat is executed as the event triggers by the game.

RegisterForUpdate is a kind of a repeated check every n milliseconds where a callback function that you define is called each time.
So this is done to repetivle do checks every n milliseconds, like an OnUpdate task during moving controls on the screen, or check every n milliseconds if you are grouped etc. (-> makes not sense as if you get grouped or leave group there are events that fire and you can react on them instead of constantly check every n milliseconds something that cannot change without those events having fired).

zo_callLater is using RegisterForUpdate and calls your callback function the delay later that you have defined.
In some circumstances it's okay to use it as some data will not be updated "instantly", but as events fire the data of the events should be fine and a zo_callLater should not be needed there (unless you check anything that is not related to the particular event).

Perfomance wise it's always bet to use events, and register event filters (if possible) as they will be called at C code, before the lua event even triggers. If the filter say "event is not needed for you" it's the best as no lua code of your callback function will be called at all! (e.g. in combat/buff events filter for unit tag "player" to only see ylur combat related stuff, and strip other group player's or enemy cobmat/buff stuff).
Thanks for your cool explanation, very helpful

I have some more questions tho, in the attached ss I submited there are 3 independent scenarios:

A is just what I had before,

C is the changes I made I would like to know if this is what you meant I should do in your previous answer,

and B is just a curious attempt however whenever I /reloadui or log in using it I can't get past the loading screen and game freezes, I'm curious of what might be the reason for this happening

(And just to clarify I'm not running this 3 versions simultaneously, I just put them there for visual representation )
Attached Thumbnails
Click image for larger version

Name:	4.PNG
Views:	197
Size:	94.1 KB
ID:	1550  
  Reply With Quote
03/17/23, 05:15 PM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
Could you please show your total code, and no screenshots? It's ahrd to see what is wrong if we do not have ALL addon files that you are calling (especially thx txt "manifes" file can create issues too!)

You can attach zip files to the posts too afaik and if this does not work try to just paste the code between the lua highlight tags, or post a link to github/gist/whatever code sharing platform you prefer.


Basically you need to do EVENT_MANAGER:RegisterForEvent("myAddonName", EVENT_GROUP_MEMBER_ROLE_CHANGED, yourCallbackFunctionForThatEvent) within your EVENT_ADD_ON_LOADED callback function, without any zo_callLater!
This will register yourCallbackFunctionForThatEvent for that event, whenever it fires (should fire each time a group member changes his role).

And if you want to update your role texture once at EVENT_ADD_ON_LOADED you need to do that manually, by either calling your function yourCallbackFunctionForThatEvent once (if that was designed to work without the event data which the event callback would pass in as parameters!) or by other means.

And EVENT_MANAGER:UnregisterForEvent is not needed unless you want to explicitly unregister events because they are not needed any longer (eg. if you disable a setting about that group role update -> unregister the events for that too so they do not fire any longer the callback functions. And if you enable the setting -> Register the events again).



btw: You got a typo in your event name!
EVENT_GROUP_MEMBER_ROLE_CHANGED

without S after ROLE

Last edited by Baertram : 03/17/23 at 05:22 PM.
  Reply With Quote
03/17/23, 06:48 PM   #6
nilo
Join Date: Feb 2022
Posts: 15
Originally Posted by Baertram View Post
Basically you need to do EVENT_MANAGER:RegisterForEvent("myAddonName", EVENT_GROUP_MEMBER_ROLE_CHANGED, yourCallbackFunctionForThatEvent) within your EVENT_ADD_ON_LOADED callback function, without any zo_callLater!
This will register yourCallbackFunctionForThatEvent for that event, whenever it fires (should fire each time a group member changes his role).
I tried doing this, rn it's like this, I'm in group with tank role lets say, I reloadui, the texture on screen is the tank one as it should but if I change role it updates the texture to the one as if my role is roleId = LFG_ROLE_INVALID

Originally Posted by Baertram View Post
btw: You got a typo in your event name!
EVENT_GROUP_MEMBER_ROLE_CHANGED

without S after ROLE
and thank you so much for this

Last edited by nilo : 03/20/23 at 10:47 AM.
  Reply With Quote
03/17/23, 07:09 PM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
Code:
evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole(newRole))
This des not work as it will only execute the function LGRI.UpdateMyRole(newRole) at the time the interpreter is running the code once, and at that time the parameter "newRole"of the event function is nil -> will lead to a missing role then and thus uses the unknown I guess.

You need to put such functions in an anonymous function so that this anony function is called at the time the event fires, and not at the time the code is interpreted.

Code:
evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, function() LGRI.UpdateMyRole(newRole) end)
And if you call that in your callback function of EVENT_GROUP_MEMBER_ROLE_CHANGED
-> evm:UnregisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED)
It will make the event EVENT_GROUP_MEMBER_ROLE_CHANGED only be called once and then it won't fire for your addon anymore.
Is this intended to only be fired once? I'd say it should fire on EACH role change, no matter how often you do it?

Also move the filter to your event_Add_on_loaded function where you register the event!
-> evm:AddFilterForEvent(EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG_PREFIX, "player")

Lua Code:
  1. function LGRI.UpdateMyRole(eventId, roleId) --watch the 1st param always is eventIf for event callbacks!!!
  2.     local my = LGRI.my
  3.  
  4.     -- Role
  5.     if roleId == 1 then
  6.         my.roleIcon = "esoui/art/lfg/lfg_icon_dps.dds"
  7.         LGRIRoleIcon:SetTexture(my.roleIcon)
  8.  
  9.     elseif roleId == 2 then
  10.         my.roleIcon = "esoui/art/lfg/lfg_icon_tank.dds"
  11.         LGRIRoleIcon:SetTexture(my.roleIcon)
  12.     elseif roleId == 4 then
  13.         my.roleIcon = "esoui/art/lfg/lfg_icon_healer.dds"
  14.         LGRIRoleIcon:SetTexture(my.roleIcon)
  15.     else
  16.         my.roleIcon = "esoui/art/armory/builditem_icon.dds"
  17.         LGRIRoleIcon:SetTexture(my.roleIcon)
  18.     end
  19.  
  20.     local myNewRole = GetGroupMemberSelectedRole("player")
  21.     LGRI.my.roleId = myNewRole;
  22.  
  23.     --zo_callLater(function() LGRI.callbackForRoleChange(myNewRole) end, 100)
  24.       --Do not unregister here!
  25.     --evm:UnregisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED)
  26. end
  27.  
  28. function LGRI.OnAddOnLoaded(event, addonName)
  29.     if addonName ~= LGRI.name then return end
  30.     evm:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  31.  
  32.     LargeGroupRoleIcons.Initialize()
  33.  
  34.     evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  35.     evm:AddFilterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  36. end
  37.  
  38. SLASH_COMMANDS["/lgri"] = LGRI.HideANDShowIcons
  39.  
  40. evm:RegisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED, LGRI.OnAddOnLoaded)
  41.  
  42. --[[ -- not needed!
  43. function LGRI.callbackForRoleChange(newRole)
  44.     evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole(newRole))
  45. end
  46. ]]

Also watch out for the event callback functions, the 1st param always is the eventId!!! That's why you pass in a number like 32456 as the roleId which makes it fail!

Last edited by Baertram : 03/17/23 at 07:15 PM.
  Reply With Quote
03/17/23, 07:19 PM   #8
nilo
Join Date: Feb 2022
Posts: 15
Originally Posted by Baertram View Post
Code:
evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole(newRole))
This des not work as it will only execute the function LGRI.UpdateMyRole(newRole) at the time the interpreter is running the code once, and at that time the parameter "newRole"of the event function is nil -> will lead to a missing role then and thus uses the unknown I guess.
I see

Originally Posted by Baertram View Post
You need to put such functions in an anonymous function so that this anony function is called at the time the event fires, and not at the time the code is interpreted.
Ok I'll try to do that

Originally Posted by Baertram View Post
Code:
evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, function() LGRI.UpdateMyRole(newRole) end)
And if you call that in your callback function of EVENT_GROUP_MEMBER_ROLE_CHANGED
-> evm:UnregisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED)
It will make the event EVENT_GROUP_MEMBER_ROLE_CHANGED only be called once and then it won't fire for your addon anymore.
Is this intended to only be fired once? I'd say it should fire on EACH role change, no matter how often you do it?
I see, it's not intended to only fire once, it's on each role change yes

Originally Posted by Baertram View Post
Lua Code:
  1. function LGRI.UpdateMyRole(eventId, roleId) --watch the 1st param always is eventIf for event callbacks!!!
  2.     local my = LGRI.my
  3.  
  4.     -- Role
  5.     if roleId == 1 then
  6.         my.roleIcon = "esoui/art/lfg/lfg_icon_dps.dds"
  7.         LGRIRoleIcon:SetTexture(my.roleIcon)
  8.  
  9.     elseif roleId == 2 then
  10.         my.roleIcon = "esoui/art/lfg/lfg_icon_tank.dds"
  11.         LGRIRoleIcon:SetTexture(my.roleIcon)
  12.     elseif roleId == 4 then
  13.         my.roleIcon = "esoui/art/lfg/lfg_icon_healer.dds"
  14.         LGRIRoleIcon:SetTexture(my.roleIcon)
  15.     else
  16.         my.roleIcon = "esoui/art/armory/builditem_icon.dds"
  17.         LGRIRoleIcon:SetTexture(my.roleIcon)
  18.     end
  19.  
  20.     local myNewRole = GetGroupMemberSelectedRole("player")
  21.     LGRI.my.roleId = myNewRole;
  22.  
  23.     --zo_callLater(function() LGRI.callbackForRoleChange(myNewRole) end, 100)
  24.       --Do not unregister here!
  25.     --evm:UnregisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED)
  26. end
  27.  
  28. function LGRI.OnAddOnLoaded(event, addonName)
  29.     if addonName ~= LGRI.name then return end
  30.     evm:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  31.  
  32.     LargeGroupRoleIcons.Initialize()
  33.  
  34.     evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  35.     evm:AddFilterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  36. end
  37.  
  38. SLASH_COMMANDS["/lgri"] = LGRI.HideANDShowIcons
  39.  
  40. evm:RegisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED, LGRI.OnAddOnLoaded)
  41.  
  42. --[[ -- not needed!
  43. function LGRI.callbackForRoleChange(newRole)
  44.     evm:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole(newRole))
  45. end
  46. ]]

Also watch out for the event callback functions, the 1st param always is the eventId!!! That's why you pass in a number like 32456 as the roleId which makes it fail!
Interesting, I didn't know about the eventId part

Last edited by nilo : 03/17/23 at 07:44 PM.
  Reply With Quote
03/18/23, 06:10 PM   #9
nilo
Join Date: Feb 2022
Posts: 15
Ok so now I have a new problem, I'm successfully calling my UpdateMyRole function whenever EVENT_GROUP_MEMBER_ROLE_CHANGED triggers, however I need smth to call this function whenever I stop being in a group and my roleId changes to LFG_ROLE_INVALID.
In order to fix this I tried doing this
Code:
EM:RegisterForEvent(LGRI.name, EVENT_GROUP_MEMBER_LEFT, LGRI.UpdateMyRole)
EM:AddFilterForEvent(EVENT_GROUP_MEMBER_LEFT, ????????? , string memberDisplayName)
I checked this page, however I don't know which filter type to fill that blank with
https://wiki.esoui.com/AddFilterForEvent

https://wiki.esoui.com/EVENT_GROUP_MEMBER_LEFT
also I just found this here
"isLocalPlayer - simple boolean
True if it is the player, false for other group members."
I guess I could use this too but again, i can't find which filter type to use

Last edited by nilo : 03/20/23 at 10:48 AM.
  Reply With Quote
03/19/23, 07:01 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
You do not always need to filter events, and beside that you cannot even filter each event! The filters are helpers to prevent event callbacks firing each time for unneccessary circumstances, like if you only want to check yourself but the event fires for all units around you.

Some events do not even support filters as the Wiki describes, e.g. if there is no unitTag in the event's callback function parameters you cannot use any unitTag related event filters for it.
Same counts for displayname and I think there does not even exist and event filter stuff for displaynames -> check the event filter site at the wiki.

If the callback function of the event already provides a parameter like isLocalPlayer and it's true if YOU left the group, then just add the EVENT_MANAGER:RegisterForEvent... of the group_left and check in your callback function at the start if it's you who left, or others.
e.g. if only you are the relevant unit to check things with you can skip all others simply by:

Lua Code:
  1. if not isLocalPlayer then return end


Lua Code:
  1. function LGRI.OnAddOnLoaded(event, addonName)
  2.     if addonName ~= LGRI.name then return end
  3.     EM:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  4.  
  5.     LargeGroupRoleIcons.Initialize()
  6.  
  7.     EM:RegisterForEvent(LGRI.name .. "_EVENT_GROUP_MEMBER_ROLE_CHANGED", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  8.     EM:AddFilterForEvent(LGRI.name .. "_EVENT_GROUP_MEMBER_ROLE_CHANGED", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player") --carefull! You are missing the first parameter, the unique event name of your addon! That way the filters won't be applied! Event filters always need to use the unique SAME name as your RegsiterForEvent used where you want to apply the filter!!!
  9.  
  10.          --number eventCode, string memberCharacterName, GroupLeaveReason reason, boolean isLocalPlayer, boolean isLeader, string memberDisplayName, boolean actionRequiredVote
  11.     EM:RegisterForEvent(LGRI.name .. "_EVENT_GROUP_MEMBER_LEFT", EVENT_GROUP_MEMBER_LEFT,
  12. function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  13.    if not isLocalPlayer then return end[
  14.    LGRI.UpdateMyRole()
  15. end)
  16. end

Last edited by Baertram : 03/19/23 at 07:06 AM.
  Reply With Quote
03/19/23, 01:09 PM   #11
nilo
Join Date: Feb 2022
Posts: 15
Originally Posted by Baertram View Post
You do not always need to filter events, and beside that you cannot even filter each event! The filters are helpers to prevent event callbacks firing each time for unneccessary circumstances, like if you only want to check yourself but the event fires for all units around you.

Some events do not even support filters as the Wiki describes, e.g. if there is no unitTag in the event's callback function parameters you cannot use any unitTag related event filters for it.
Same counts for displayname and I think there does not even exist and event filter stuff for displaynames -> check the event filter site at the wiki.

If the callback function of the event already provides a parameter like isLocalPlayer and it's true if YOU left the group, then just add the EVENT_MANAGER:RegisterForEvent... of the group_left and check in your callback function at the start if it's you who left, or others.
I understand, thanks

This is not working for me tho
Lua Code:
  1. function LGRI.OnAddOnLoaded(event, addonName)
  2.     if addonName ~= LGRI.name then return end
  3.     EM:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  4.  
  5.     LargeGroupRoleIcons.Initialize()
  6.  
  7.     EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  8.     EM:AddFilterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  9.  
  10.     EM:RegisterForEvent(LGRI.name .. "ILeftGroup", EVENT_GROUP_MEMBER_LEFT,
  11. function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  12.    if not isLocalPlayer then return end
  13.    LGRI.UpdateMyRole()
  14. end)
  15. end
But this is working the difference is in the AddFilterForEvent line
Lua Code:
  1. function LGRI.OnAddOnLoaded(event, addonName)
  2.     if addonName ~= LGRI.name then return end
  3.     EM:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  4.  
  5.     LargeGroupRoleIcons.Initialize()
  6.  
  7.     EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  8.     EM:AddFilterForEvent(EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  9.  
  10.     EM:RegisterForEvent(LGRI.name .. "ILeftGroup", EVENT_GROUP_MEMBER_LEFT,
  11. function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  12.    if not isLocalPlayer then return end
  13.    LGRI.UpdateMyRole()
  14. end)
  15. end


And also one extra question, I want to register another event(EVENT_GROUP_MEMBER_JOINED) to trigger my UpdateMyRole() function, what's the correct way?
Lua Code:
  1. EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, EVENT_GROUP_MEMBER_JOINED, LGRI.UpdateMyRole)
  2.  
  3. or separately?
  4.  
  5. EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  6. EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_JOINED, LGRI.UpdateMyRole)

Last edited by nilo : 03/19/23 at 01:11 PM.
  Reply With Quote
03/19/23, 01:12 PM   #12
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
Event register and unregister always is 1 event only, not multiple within one call.

And the event filters should work like I had added my code above, with the first para = the same unique name you have used to register your event with.
You can register multiple filters with the same unique name, as long as the filtertype is different (e.g. REGISTER_FILTER_POWER_TYPE and REGISTER_FILTER_UNIT_TAG works, but 2x REGISTER_FILTER_UNIT_TAG won't work with the same unique name).

Example:
Code:
EVENT_MANAGER:RegisterForEvent("ZO_HealthWarning", EVENT_POWER_UPDATE, OnPowerUpdate)
EVENT_MANAGER:AddFilterForEvent("ZO_HealthWarning", EVENT_POWER_UPDATE, REGISTER_FILTER_POWER_TYPE, COMBAT_MECHANIC_FLAGS_HEALTH)
EVENT_MANAGER:AddFilterForEvent("ZO_HealthWarning", EVENT_POWER_UPDATE, REGISTER_FILTER_UNIT_TAG, "player")
If your code works though it is ignoring the filter then and this is why "it works" ? You can check if your function EVENT_GROUP_MEMBER_ROLE_CHANGED is fired for any other group member than yourself, by adding a d("debug message here") in your callback function
e.g. d(">unitTag: " ..tostring(unitTag))

Perhas the group related event filters only accept unitTags that start with group. e.g. the unitTag start at group1 and count up to groupn. Maybe "player" is never send to the event EVENT_GROUP_MEMBER_ROLE_CHANGED then?
You can remove the filter and test what the unitTag is like as you yourself change the role (via the d debug message).
Maybe it will be group2 or similar then and that's why it won't work with "player". In this case leave the event filter away and check manuallyif the group unitTag passed to the callback function parameter is the one of yourself.

You should be able to detect that via GetUnitDisplayName(unitTag) and comparing the displayName with GetDisplayName() result (cache that once at the start of your addon as it would not change in between during gameplay).

Last edited by Baertram : 03/19/23 at 01:18 PM.
  Reply With Quote
03/19/23, 01:17 PM   #13
nilo
Join Date: Feb 2022
Posts: 15
Originally Posted by Baertram View Post
Event register and unregister always is 1 event only, not multiple within one call.
Ok

Originally Posted by Baertram View Post
And the event filters should work like I had added my code above, with the first para = the same unique name you have used to register your event with.
Which is like I have on my first code sample in the previous post, right?

Originally Posted by Baertram View Post
If your code works though it is ignoring the filter then and this is why "it works" ? You can check if your function EVENT_GROUP_MEMBER_ROLE_CHANGED is fired for any other group member than yourself, by adding a d("debug message here") in your callback function
I'll check it later when I have more time
  Reply With Quote
03/19/23, 01:19 PM   #14
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
I've edited my answer above.
  Reply With Quote
03/19/23, 03:00 PM   #15
nilo
Join Date: Feb 2022
Posts: 15
Originally Posted by Baertram View Post
If your code works though it is ignoring the filter then and this is why "it works" ? You can check if your function EVENT_GROUP_MEMBER_ROLE_CHANGED is fired for any other group member than yourself, by adding a d("debug message here") in your callback function
e.g. d(">unitTag: " ..tostring(unitTag))
Yes, it fires whenever me or a group member changes role and the output is ">unitTag: nil"

this returns my index
Lua Code:
  1. local index = GetGroupIndexByUnitTag("player")
  2. d(">index: " ..tostring(index))

So I'm thinking of doing this
Lua Code:
  1. function LGRI.OnAddOnLoaded(event, addonName)
  2.     if addonName ~= LGRI.name then return end
  3.     EM:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  4.  
  5.     LargeGroupRoleIcons.Initialize()
  6.  
  7.     EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  8.     --EM:AddFilterForEvent(EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  9.     EM:AddFilterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG,
  10.     function (unitTag)
  11.         local index = GetGroupIndexByUnitTag("player")
  12.         local unitTag = GetGroupUnitTagByIndex(index)
  13.         if not unitTag == "group"..index then return end
  14.         LGRI.UpdateMyRole()
  15.     end)
  16.  
  17.     EM:RegisterForEvent(LGRI.name .. "ILeftGroup", EVENT_GROUP_MEMBER_LEFT,
  18.     function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  19.         if not isLocalPlayer then return end
  20.         LGRI.UpdateMyRole()
  21.     end)
  22. end

Last edited by nilo : 03/19/23 at 03:28 PM.
  Reply With Quote
03/19/23, 03:34 PM   #16
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
If the unitTag is always nil, there either is a bug in that event or your parameter order of that event is wrong so that you do not actually check the unitTag but some other param which returns nil. Did you add the 1st parameter eventId in your callback?

>this returns my index
And what is your index then? if it's 4294967296 it's wrong Should be something like 1, 2, 3 etc.


You cannot use a function in the event filters!
Code:
EM:AddFilterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG,
    function (unitTag)
That won't work afaik. Only fixed values are allowed.
That event filter would only work with something like this:
Code:
EM:AddFilterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "group1")


And this would neither work or at least is not needed.
GetGroupUnitTagByIndex should always return "group" .. <number> so it cannot be anything else than group..index as you have passed in the index.

Lua Code:
  1. local unitTag = GetGroupUnitTagByIndex(index)
  2.         if not unitTag == "group"..index then return end


Your functin function LGRI.UpdateMyRole(eventId) needs the unitTag as 2nd parameter and then you can use that function properly.


Lua Code:
  1. function LGRI.UpdateMyRole(eventId, unitTag)
  2.     if unitTag ~= nil then
  3.     local index = GetGroupIndexByUnitTag("player")
  4.     local myUnitTag = GetGroupUnitTagByIndex(index)
  5.     if unitTag ~= myUnitTag then return end
  6.     end
  7.  
  8.     local my = LGRI.my
  9.     local roleId = GetGroupMemberSelectedRole("player")
  10.  
  11.     -- Role
  12.     if roleId == 1 then
  13.         my.roleIcon = "esoui/art/lfg/lfg_icon_dps.dds"
  14.         LGRI.UI.MyRoleIcon:SetTexture(my.roleIcon)
  15.  
  16.     elseif roleId == 2 then
  17.         my.roleIcon = "esoui/art/lfg/lfg_icon_tank.dds"
  18.         LGRI.UI.MyRoleIcon:SetTexture(my.roleIcon)
  19.     elseif roleId == 4 then
  20.         my.roleIcon = "esoui/art/lfg/lfg_icon_healer.dds"
  21.         LGRI.UI.MyRoleIcon:SetTexture(my.roleIcon)
  22.     else
  23.         my.roleIcon = "esoui/art/armory/builditem_icon.dds"
  24.         LGRI.UI.MyRoleIcon:SetTexture(my.roleIcon)
  25.     end
  26. end
  27.  
  28. function LGRI.OnAddOnLoaded(event, addonName)
  29.     if addonName ~= LGRI.name then return end
  30.     EM:UnregisterForEvent(LGRI.name, EVENT_ADD_ON_LOADED)
  31.  
  32.     LargeGroupRoleIcons.Initialize()
  33.  
  34.     EM:RegisterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, LGRI.UpdateMyRole)
  35.     --EM:AddFilterForEvent(EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG, "player")
  36.     --EM:AddFilterForEvent(LGRI.name .. "MyRoleChanged", EVENT_GROUP_MEMBER_ROLE_CHANGED, REGISTER_FILTER_UNIT_TAG,
  37.  
  38.     EM:RegisterForEvent(LGRI.name .. "ILeftGroup", EVENT_GROUP_MEMBER_LEFT,
  39.     function(eventId, memberCharacterName, groupLeaveReason , isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
  40.         if not isLocalPlayer then return end
  41.         LGRI.UpdateMyRole()
  42.     end)
  43. end

Last edited by Baertram : 03/19/23 at 03:53 PM.
  Reply With Quote
03/19/23, 03:40 PM   #17
nilo
Join Date: Feb 2022
Posts: 15
yes, I have eventId as 1st parameter

and my index was 2
  Reply With Quote
03/19/23, 03:44 PM   #18
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
Updated my answer above, the code at the bottom should be the one you are searching for (no event filter, just unitTag check for your own tag).

Edit: Updated it again and changed the unitTag == nil within LGRI.UpdateMyRole to a ~= nil check, so hat your call from EM:RegisterForEvent(LGRI.name .. "ILeftGroup", EVENT_GROUP_MEMBER_LEFT, still works.

Last edited by Baertram : 03/19/23 at 03:54 PM.
  Reply With Quote
03/19/23, 04:27 PM   #19
nilo
Join Date: Feb 2022
Posts: 15
Yep makes sense, thanks
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Questions about events, RegisterForEvent, RegisterForUpdate, ..


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