PDA

View Full Version : Finding skill tags in DB



Archmage
May 11th, 2008, 03:30
I'm trying to get skill totals from the database, but using
<source>
<name>skilllist.id-00018.total</name>
<op>+</op>
</source>

doesn't work, because apparently the skills are not always given the same id. Is there a way to find a skill in the DB based on its label tag?

Foen
May 11th, 2008, 07:14
You could iterate through the skill list using Lua, and compare each one in turn:



function getSkill(label,sublabel)
local node = window.getDatabaseNode();
if not node or not node.getChild("skilllist") then
return nil;
end
for k,skl in pairs(node.getChild("skilllist").getChildren()) do
if skl.getChild("label") and skl.getChild("label").getValue()==label then
if sublabel then
if skl.getChild("sublabel") and skl.getChild("sublabel").getValue()==sublabel then
return skl;
end
else
return skl;
end
end
end
return nil;
end


The above code should work in any top-level control environment, otherwise you would need to change the call to getDatabaseNode accordingly.

The function returns the database node which matches the given label and, if a sublabel is included in the function call, the sublabel. It returns nil if there is no such match. Note that this is case-sensitive.

Hope that helps

Stuart

joshuha
May 12th, 2008, 15:01
This is generally how I find anything in a list. I loop through the list until I hit the value I am looking for.