Thread Tools Display Modes
12/16/23, 10:35 AM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Question 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?
  Reply With Quote
12/16/23, 10:44 AM   #2
ExoY
 
ExoY's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 88
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.
  Reply With Quote
12/16/23, 11:00 AM   #3
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by ExoY View Post
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.

Last edited by sinnereso : 12/16/23 at 11:03 AM.
  Reply With Quote
12/16/23, 11:17 AM   #4
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by ExoY View Post
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.
  Reply With Quote
12/16/23, 11:42 AM   #5
FlatBadger
 
FlatBadger's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2021
Posts: 17
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

Last edited by FlatBadger : 12/16/23 at 12:15 PM.
  Reply With Quote
12/16/23, 02:21 PM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Originally Posted by sinnereso View Post
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.
  Reply With Quote
12/18/23, 02:10 PM   #7
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by sirinsidiator View Post
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?

Last edited by sinnereso : 12/18/23 at 03:41 PM.
  Reply With Quote
12/18/23, 07:07 PM   #8
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Originally Posted by sinnereso View Post
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)
  Reply With Quote
12/18/23, 08:07 PM   #9
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by Baertram View Post
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
  Reply With Quote
12/20/23, 09:56 AM   #10
ExoY
 
ExoY's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 88
Originally Posted by sinnereso View Post
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?
  Reply With Quote
12/20/23, 10:25 AM   #11
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 245
Originally Posted by ExoY View Post
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.

Last edited by sinnereso : 12/20/23 at 10:29 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » question regarding tables and number of entries


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