ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   question regarding tables and number of entries (https://www.esoui.com/forums/showthread.php?t=10756)

sinnereso 12/16/23 10:35 AM

question regarding tables and number of entries
 
Im looking for a way to determine the number of entries on the fly for a chat multiiple event filter im working on for the "FOR" statement. Ive been getting errors stating its expecting a number with this setup.

Code:

MyAddon.killFilterList = {}

function MyAddon.PvpKillFeedFilter(victomDisplayName)--<< PVP CHAT FEED MULTIPLE EVENT FILTER
        for i = 1, MyAddon.killFilterList do
                if (nil == MyAddon.killFilterList[victomDisplayName]) then
                        table.insert(MyAddon.killFilterList, victomDisplayName)
                        return false
                end
        end
        return true
end

I'd like to to just scan the list and add entries theyre not present.

then later clear the list which I think I can do with "MyAddon.killFilterList = {}" but untested untill the 1st part is working.

Suggestions?

ExoY 12/16/23 10:44 AM

can you explain with a small simple example what you want to do.

maybe it is just me, but i have no idea what you are trying to achieve with the text you posted.

sinnereso 12/16/23 11:00 AM

Quote:

Originally Posted by ExoY (Post 49046)
can you explain with a small simple example what you want to do.

maybe it is just me, but i have no idea what you are trying to achieve with the text you posted.

im trying to filter the new pvp kill feel chat events that appear to fire multiple times.. so im adding playernames to a list to prevent displaying the same kill multiple times.. So if the player is in the list do nothing.. if not then add to the list and display chat output.. the chat output code i didnt post here but my primary issue is the error im getting from the "for i = 1, MyAddon.killFilterList do" line stating its expecting a number of current entries i guess.

sinnereso 12/16/23 11:17 AM

Quote:

Originally Posted by ExoY (Post 49046)
can you explain with a small simple example what you want to do.

maybe it is just me, but i have no idea what you are trying to achieve with the text you posted.

one of the dev's posted a way to fix this after the kill feed was released but I didnt understand it at the time and cant find it now so ive been trying to create my own.

FlatBadger 12/16/23 11:42 AM

You need to iterate the table, but it depends on the structure of your table. You need to use either
Lua Code:
  1. pairs
or
Lua Code:
  1. ipairs

e.g.

Lua Code:
  1. local myTable = {[key1]="value1",[key2]=value2}
  2.  
  3. for key, value in pairs(myTable) do
  4.  d("key: " .. key .. " value: " .. value)
  5.  
  6. end
  7.  
  8. local myOtherTable ={value1, value2, value3}
  9.  
  10. for index, value in ipairs(myOtherTable) do
  11.   d("item number " .. index .. " = " .. value)
  12. end

instead of ipairs you could also use:

Lua Code:
  1. for index = 1, #myOtherTable do
  2.   d("value = " .. myOtherTable[index])
  3. end

sirinsidiator 12/16/23 02:21 PM

Quote:

Originally Posted by sinnereso (Post 49045)
Im looking for a way to determine the number of entries on the fly for a chat multiiple event filter im working on for the "FOR" statement. Ive been getting errors stating its expecting a number with this setup.

Code:

MyAddon.killFilterList = {}

function MyAddon.PvpKillFeedFilter(victomDisplayName)--<< PVP CHAT FEED MULTIPLE EVENT FILTER
        for i = 1, MyAddon.killFilterList do
                if (nil == MyAddon.killFilterList[victomDisplayName]) then
                        table.insert(MyAddon.killFilterList, victomDisplayName)
                        return false
                end
        end
        return true
end

I'd like to to just scan the list and add entries theyre not present.

then later clear the list which I think I can do with "MyAddon.killFilterList = {}" but untested untill the 1st part is working.

Suggestions?

You are passing the table "MyAddon.killFilterList" to "for .. do" instead of the length of the table "#MyAddon.killFilterList".

Other than you are mixing two different approaches on how to use tables and end up not filtering anything at all.
You iterate over the table and insert new entries into it with numeric indexes, but at the same time try to access entries in the table by using the displayName as a key (instead of the numeric index).

Code:

MyAddon.killFilterList = {}

function MyAddon.PvpKillFeedFilter(victomDisplayName)--<< PVP CHAT FEED MULTIPLE EVENT FILTER
        if not MyAddon.killFilterList[victomDisplayName] then
                MyAddon.killFilterList[victomDisplayName] = true
                return false
        end
        return true
end

Aside of that you will have to unset the entry in the killFilterList at some point, otherwise you won't ever show the name again after it got filtered the first time.

sinnereso 12/18/23 02:10 PM

Quote:

Originally Posted by sirinsidiator (Post 49050)
You are passing the table "MyAddon.killFilterList" to "for .. do" instead of the length of the table "#MyAddon.killFilterList".

Other than you are mixing two different approaches on how to use tables and end up not filtering anything at all.
You iterate over the table and insert new entries into it with numeric indexes, but at the same time try to access entries in the table by using the displayName as a key (instead of the numeric index).

Code:

MyAddon.killFilterList = {}

function MyAddon.PvpKillFeedFilter(victomDisplayName)--<< PVP CHAT FEED MULTIPLE EVENT FILTER
        if not MyAddon.killFilterList[victomDisplayName] then
                MyAddon.killFilterList[victomDisplayName] = true
                return false
        end
        return true
end

Aside of that you will have to unset the entry in the killFilterList at some point, otherwise you won't ever show the name again after it got filtered the first time.

yes im aware of the resetting the list which is next and I think a non issue but populating the list has been my issue. Im using similar code to populate a list of char names on account though and works fine.

what im trying to do is add victoms to the list and NOT display them(and return false) if in the list because the ingame killfeed fires twice per kill.

will "#MyAddon.killFilterList" work in the for .. do statement for length of list or number of entries? I've never seen this example before.

The devs posted a fix for the pvp kill feed double spam but I cant find it anywhere.. Anyone have a link?

Baertram 12/18/23 07:07 PM

Quote:

Originally Posted by sinnereso (Post 49056)
will "#MyAddon.killFilterList" work in the for .. do statement for length of list or number of entries? I've never seen this example before.

Depends on if your table #MyAddon.killFilterList uses a non-gap index key (1, 2, 3, 4, 5, ...) or not.
# means "count of" and only works (afaik) with non-gap index tables, same as "for key, value in ipairs(tableName) do " would iterate.

If your key is a string like a characteror accountName, it will not work.
You will have to read above then where the guys explainend you alreay how to iterate that -> "in pairs" (not in ipairs)

sinnereso 12/18/23 08:07 PM

Quote:

Originally Posted by Baertram (Post 49059)
Depends on if your table #MyAddon.killFilterList uses a non-gap index key (1, 2, 3, 4, 5, ...) or not.
# means "count of" and only works (afaik) with non-gap index tables, same as "for key, value in ipairs(tableName) do " would iterate.

If your key is a string like a characteror accountName, it will not work.
You will have to read above then where the guys explainend you alreay how to iterate that -> "in pairs" (not in ipairs)

Thank you for all the help.. I found the dev post regarding my issue and have come up with another workaround thats more effective and more efficient.. ty

ExoY 12/20/23 09:56 AM

Quote:

Originally Posted by sinnereso (Post 49060)
Thank you for all the help.. I found the dev post regarding my issue and have come up with another workaround thats more effective and more efficient.. ty

Can you post the link to the dev post and your improved solutions, so others can benefit from it as well?

sinnereso 12/20/23 10:25 AM

Quote:

Originally Posted by ExoY (Post 49075)
Can you post the link to the dev post and your improved solutions, so others can benefit from it as well?

Sure but this question here was more generalized to assist me with a pvp kill feed doouble spam filter which is why I didnt go more into detail on my resolution.. Here's the link and solution.

https://www.esoui.com/forums/showthr...8153#post48153

the event sends these variables twice when firing:

Code:

(eventCode, killLocation, killerDisplayName, killerCharacterName, killerAlliance, killerRank, victomDisplayName, victomCharacterName, victomAlliance, victomRank, isKillLocation)
apparently my double spam issue is caused by one being "isKillLocation" location based 10cell radius and one not which is using the standard 2cell radius. I just filter by " if isKillLocation then" or "if not isKillLocation then" and imediately solved the issue.


All times are GMT -6. The time now is 01:10 PM.

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