PDA

View Full Version : DB path of a known name



Xarxus
February 5th, 2023, 20:01
It will be today's tiredness, but I'm wrapping up on what is probably nonsense.
I need to go back to the DB path of a skill whose name I know, but I can't.

Help.

Xarxus
February 5th, 2023, 20:33
This is my solution. There is a better way?
function getGlobalElementPath(sElementName, sSource)
if sElementName == "" or sSource == "" then
return nil;
end

for _, nodeElement in pairs(DB.getChildrenGlobal(sSource)) do
if nodeElement.getChild("name").getValue() == sElementName then
return nodeElement;
end
end
end

Trenloe
February 5th, 2023, 20:40
That's what you have to do - iterate through the node hierarchy.

I'd recommend you change nodeElement.getChild("name").getValue() to DB.getValue(nodeElement, "name", "") this is more efficient (less API calls) and it also returns a default of "" if the node doesn't exist - which will help to avoid errors if it doesn't exist.

Xarxus
February 5th, 2023, 20:41
Great! Ty