Thread Tools Display Modes
04/12/14, 09:16 PM   #1
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 639
Function to check values in a Set

Can you help me with something?
Code:
if profession == 6 then
    profession = 5
end
Looking at the Esohead.lua, it seems that Wood is assigned to profession number 6. In HarvestMap Wood is 5. The author HarvestMap uses this simple method to assign which set is to be used. I need help with some coding since I don't know lua, because I want to do something different. I want to parse through the set.

Example of one of 9 sets of numbers.
Code:
	-- Added: Supplies
    [8] = {
        1187,
        23265,
        23267,
        45835,
    },
If I have a list of IDs as noted above how do I make it look at all the ID numbers in the Set, and if it finds one, then do something. Here is what I was thinking.

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
How do I change this, I don't know if that is even correct at all. Also, does that need an Else statement before last 'return false'?

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.
  Reply With Quote
04/12/14, 10:07 PM   #2
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
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:
  1. local skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_ALCHEMY)
  2.     local skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  3.     local abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  4.     TradeSkills[CRAFTING_TYPE_ALCHEMY] = { Name = skillName, Icon = abilityIcon }
  5.  
  6.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_BLACKSMITHING)
  7.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  8.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  9.     TradeSkills[CRAFTING_TYPE_BLACKSMITHING] =  { Name = skillName, Icon = abilityIcon }
  10.  
  11.  
  12.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_CLOTHIER)
  13.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  14.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  15.     TradeSkills[CRAFTING_TYPE_CLOTHIER] =   { Name = skillName, Icon = abilityIcon }
  16.  
  17.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_ENCHANTING)
  18.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  19.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  20.     TradeSkills[CRAFTING_TYPE_ENCHANTING] =     { Name = skillName, Icon = abilityIcon }
  21.  
  22.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_PROVISIONING)
  23.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  24.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  25.     TradeSkills[CRAFTING_TYPE_PROVISIONING] =   { Name = skillName, Icon = abilityIcon }
  26.    
  27.     skillType,skillIndex = GetCraftingSkillLineIndices(CRAFTING_TYPE_WOODWORKING)
  28.     skillName,skillRank  = GetSkillLineInfo(skillType, skillIndex)
  29.     abilityName,abilityIcon = GetSkillAbilityInfo(skillType, skillIndex, 1)
  30.     TradeSkills[CRAFTING_TYPE_WOODWORKING] =    { Name = skillName, Icon = abilityIcon }

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:
  1. tableName = {
  2.     name = "Stuart",
  3.     address = "123 Letsby Avenue",
  4.     single = "true" ,
  5.     ["No of Children"] = 3,
  6.     Children = {
  7.          "Stuart",
  8.          "Alison",
  9.          "William"
  10.     }
  11. }

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:
  1. for key,data in pairs(tableName) do
  2.      -- data could be another table so another cycle will need to be done to access that one etc.
  3.      if type(data) == "table" then
  4.         for key2,data2 in pairs(data) do
  5.             -- work with this level of keys or data
  6.         end
  7.      else
  8.         -- work with key or data,
  9.      end
  10. end

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.
  Reply With Quote
04/12/14, 11:47 PM   #3
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 639
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


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
I'm adding this to HarvestMapImport.lua so that it looks at the tables, and the separates out Crates from the Alchemy section.

Last edited by Sharlikran : 04/13/14 at 12:00 PM.
  Reply With Quote
04/13/14, 08:07 AM   #4
thelegendaryof
 
thelegendaryof's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 161
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
Edit:

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.
  Reply With Quote
04/13/14, 12:02 PM   #5
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 639
Warning: Spoiler

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.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Function to check values in a Set

Thread Tools
Display Modes

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