|
04/12/14, 09:16 PM | #1 |
Function to check values in a Set
Can you help me with something?
Code:
if profession == 6 then profession = 5 end Example of one of 9 sets of numbers. Code:
-- Added: Supplies [8] = { 1187, 23265, 23267, 45835, }, Arguments: ProfessionId = a valid number 1 to 9 in set Harvest.professions in file HarvestMapData.lua Intention: function CheckInProfessionSet returns True if the ItemId exists in that specific set. Code:
function CheckInProfessionSet(ProfessionId) ProfessionId = tonumber(ProfessionId) for tsId, tsData in pairs(EH.rawMaterials[ProfessionId]) do for key, value in pairs(tsData) do if value == key then return true end end end return false end I got this from the Esohead files. I'd like to use something similar. How can I make it return true or false if the ItemId is in the set? Last edited by Sharlikran : 04/12/14 at 10:46 PM. |
|
04/12/14, 10:07 PM | #2 |
The profession id's can be grabbed from the skill line functions and the crafting type constants.
Item ID's you can get by extracting it from the Item Link, but other than that there is only an instance ID which can be the same for different items and also different for the same items. I haven't been able to pin down a pattern yet, possible the source of the loot, or the type of loot. Hard to say. Anyways, here goes: local skillType,skillIndex = GetCraftingSkillLineIndices(tradeSkill) local skillName,skillRank = GetSkillLineInfo(skillType,skillIndex) TradeskillType CRAFTING_TYPE_ALCHEMY CRAFTING_TYPE_BLACKSMITHING CRAFTING_TYPE_CLOTHIER CRAFTING_TYPE_ENCHANTING CRAFTING_TYPE_INVALID CRAFTING_TYPE_PROVISIONING CRAFTING_TYPE_WOODWORKING Either substitute the variable tradeSkill with the constant reference for the crafting skill you want to use or cycle through from 1 to 6 to store them all, or do what I did below, just to make sure. I can't remember if I tried a loop and it didn't work. Here is a function I have been using to get a test addon working for one of my problem TODO areas : Lua Code:
That aside, lets see what other questions you asked ... You can use a for loop to cycle through a table or set as you mentioned. Example Table. tableName = { 23, 56, "alpha", true } In this example the key would be a number and the data would be the values in this table or list or set Lua Code:
In this example, notice that each value now has a key and value set up and oh look, one of the keys has had to be boxed up as it is a multi word string, and one of the values contains another table. Lua Code:
As to other functionality in the addons you would have to look at the addon as a whole as the data it is looking at could be stored in a certain way to make it work. The CheckIn... Function though is doing its work correctly. If it comes across a valid match it will return out of the function with the value true telling the calling statement to know that a match has been found. If it doesn't find it by the time it has reached the end of the table it is assumed that no match is found and will return false. The only reason this may be wrong is if there was a case specific issue in play. But in ESO case identifies what type of data it is if you want to use it that way. For example. In my gatherer addon I store both node findings ( "Iron Ore", "Bugloss", "Jute" ) and the items that can be looted from it such as ( "iron ore", "bugloss", "raw jute" ). Item names seem to be all in lower case and Object names are in mixed case. It may be worth looking at the Lua manual for looking up the commands for this sort of stuff. A search on google should find several links. Last edited by Xrystal : 04/12/14 at 10:23 PM. |
|
04/12/14, 11:47 PM | #3 |
Thanks for that, that was helpfull. I looked on google and found this site but, nothing is really parsing a set like I am doing. I'm still digging through it though, I may have just overlooked it. It's different from Delphi (TES5Edit) and Python (Wrye Bash) which I am used to using.
You took me in another direction because I did want to parse names as well. I'm not so much going for the accuracy of the sets just yet. I have work with the sets and clean them up. I am initially interested in getting the function to work. I will use else once I get the framework of the function finished. Here are the tables, or Sets that I have so far:
Warning: Spoiler
Code:
Harvest.professions = { -- : Mining [1] = { 808, 4482, 4995, 5820, 23103, 23104, 23105, 23133, 23134, 23135, }, -- : Clothing [2] = { 793, 800, 812, 4448, 4464, 4478, 6020, 23095, 23097, 23129, 23130, 23131, 23142, 23143, 33217, 33218, 33219, 33220, }, -- : Enchanting [3] = { 45806, 45807, 45808, 45809, 45810, 45811, 45812, 45813, 45814, 45815, 45816, 45817, 45818, 45819, 45820, 45821, 45822, 45823, 45824, 45825, 45826, 45827, 45828, 45829, 45830, 45831, 45832, 45833, 45834, 45835, 45836, 45837, 45838, 45839, 45840, 45841, 45842, 45843, 45844, 45845, 45846, 45847, 45848, 45849, 45850, 45851, 45852, 45853, 45854, 45855, 45856, 45857, 54248, 54253, 54289, 54294, 54297, 54299, 54306, 54330, 54331, 54342, 54373, 54374, 54375, 54481, 54482, }, -- : Alchemy [4] = { 883, 1187, 4570, 23265, 23266, 23267, 23268, 30148, 30149, 30151, 30152, 30153, 30154, 30155, 30156, 30157, 30158, 30159, 30160, 30161, 30162, 30163, 30164, 30165, 30166, }, -- : Wood [5] = { 521, 802, 818, 4439, 23117, 23118, 23119, 23137, 23138, }, -- Esohead uses the same ItemID for multiple items. Therefore maintaining -- a list based on the item number would become useless bloat in a file. -- All items looted in ESO are containers. Such that Jute is a container -- it just gives you Jute. a Crate is a container that gives you food items. -- Therefore the name of the item collected will dictate it's category -- rather than the Item's ID number. -- -- These additional elements in the array are here for consistency in how -- the arrays are already handled. It is also appended in this way for -- compatibility with the data already collected by users. Chests are already -- handled separately. -- -- 6 = Chest, 7 = Bottle, 8 = Container, 9 = Fish, 10 = Books [6] = { }, [7] = { }, [8] = { }, [9] = { }, -- Books is the exception such that there may be a way to record lore books -- that are always in the same location and usable only once like Skyshards. -- -- Displaying Books is not implemented at this time so that it's not on the -- menu and therefore confusing players as to why they don't see any books -- on the maps. } -- 7 = Bottle Harvest.bottle = { "Bottle", "Bottles", "Cup", "Cups", "Drink", "Goblet", "Jar", "Jug", "Mug", "Water Skin", "Wine Rack", } -- 8 = Container Harvest.container = { "Backpack", "Barrel", "Barrel (Burnt)", "Barrels", "Barrels (Burnt)", "Basket", "Cabinet", "Crate", "Crate (Burnt)", "Crates", "Crates (Burnt)", "Cupboard", "Desk", "Dresser", "Drink", "Nightstand", "Pot", "Sack", "Tomb Urn", "Trunk", "Urn", "Vase", "Wardrobe", "Yew", } -- 10 = Books Harvest.books = { "Book", "Book Stack", "Books", "Bookshelf", } -- Added for future implementation -- ?? = Enchanting Harvest.enchanting = { "Aspect Rune", "Essence Rune", "Potency Rune", } What you suggested, the sample code I am looking they don't say "for 1, 4" they seem to have a way to just say {{Look at all the items in the set}} and assign that to data. When data is true then do this. Maybe I am interpreting it wrong. I'm just not sure of the syntax. The elements in the set are dynamic, it could be an empty set, it might have 1 item or 4, or 20. Code:
-- I am going specify the specific set of Id numbers I want to work with, in this case (8) or Supplies. for _, data in pairs(Harvest.professions[8]) do for _, data2 in pairs(Harvest.supplies) do -- The item number from the first table exists "and" The name exists in the second table if data and data2 then profession = 8 end end Last edited by Sharlikran : 04/13/14 at 12:00 PM. |
|
04/13/14, 08:07 AM | #4 |
I think what you want is setmetatable. Especially the __newindex metamethod to map values as keys on creation instead of that traversing via a manual loop.
However keep in mind __newindex will only trigger if that metatable has been added and the way you're defining it right now gives it now way to trigger __newindex ever so you will need to use a virtual function like this to get it to work and keep adding it as a collection: Code:
function mapped_table(t) local ret = setmetatable({}, { __newindex = function(self,k,v) rawset(self,k,v) -- map index as key, return value (default) rawset(self,v,k) -- map value as key, return index end }) for k, v in pairs(t) do ret[#ret+1] = v end return ret end local myWhatEverMaterialTable = {} myWhatEverMaterialTable[8] = mapped_table({ 1245, 1259872, 25115, 2958257, 21587, 2187 }) Code:
d(myWhatEverMaterialTable[8][25115]) -- outputs index: 3 d(myWhatEverMaterialTable[8][3]) --outputs value: 25115 d(myWhatEverMaterialTable[8][666]) -- outputs nil because neither the index noir the value exists in the table Also never use table.insert because it 's ignoring metatables as well. Set them manually and you're good to go (like with my function above). Last edited by thelegendaryof : 04/13/14 at 08:51 AM. |
|
04/13/14, 12:02 PM | #5 |
Warning: Spoiler
Code:
function Harvest.IsValidBottle(name) for k, v in pairs(Harvest.bottle) do if v == name then return true end end return false end function Harvest.IsValidContainer(name) for k, v in pairs(Harvest.container) do if v == name then return true end end return false end function Harvest.IsValidBook(name) for k, v in pairs(Harvest.books) do if v == name then return true end end return false end function Harvest.IsValidEnchant(name) for k, v in pairs(Harvest.enchanting) do if v == name then return true end end return false end I figured it out. I was approaching it all wrong. There was already an argument to pass to the function, so all I had to do was take advantage of the name in the set. Thanks for all the advice guys. EDIT: Updated the above post to show the sets I used. |
|
ESOUI » Developer Discussions » Lua/XML Help » Function to check values in a Set |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|