PDA

View Full Version : Issue with DB.getValue in combination with DB.deleteChild



Mephisto
March 17th, 2022, 17:52
Hi there,
I encounter an issue with DB access. I need to migrate same DB entries to new DB entries.

I first catch the data I want to migrate from the DB and write it to it's new location. This works fine if I comment out the "DB.deleteChild" entries at the end of my code. If the "DB.deleteChild" entries are active, the "DB.getValue" part fails to acquire any data. I assume for some reason the deletion happens before I can grab the data from the DB even so the grabbing happens code wise before the deletion.

Happy to provide the ruleset code and the DB I want to migrate in a PM.



function migrateNPC6(nodeNPC)
-- Get nodes for migration
for _, nodeAction in pairs (DB.getChildren(nodeNPC, "actions")) do
-- Get values from DB.
nHandling = DB.getValue(nodeAction, "atk_handling", 0)
nBonus = DB.getValue(nodeAction, "atk_modifier", 0)
nType = DB.getValue(nodeAction, "atk_type", 0)
sQualities = DB.getValue(nodeAction, "desc", "")
sName = DB.getValue(nodeAction, "name", "")

-- Migrate values from old to new DB entries
DB.setValue(nodeAction, "wpn_handling", "number", nHandling)
DB.setValue(nodeAction, "atk_bonus", "number", nBonus)
DB.setValue(nodeAction, "wpn_name", "string", sName)
DB.setValue(nodeAction, "wpn_qualities", "string", sQualities)
DB.setValue(nodeAction, "wpn_type", "number", nType)

Debug.console("sName", sName)
Debug.console("sQualities", sQualities)
Debug.console("wpn_name", DB.getValue(nodeAction, "wpn_name", ""))
Debug.console("wpn_qualities", DB.getValue(nodeAction, "wpn_qualities", ""))

-- Delete old migrated DB entries
DB.deleteChild(nodeAction, "atk_handling")
DB.deleteChild(nodeAction, "atk_modifier")
DB.deleteChild(nodeAction, "atk_type")
DB.deleteChild(nodeAction, "desc")
DB.deleteChild(nodeAction, "name")
end
end

Moon Wizard
March 17th, 2022, 18:30
I've never had problems with that approach; and use it in migration all the time.

My first guess is that the script is being run on the same NPC more than once. You should be able to put some Debug.console(nodeAction) call in your function; and limit to simpler data.

JPG

Mephisto
March 17th, 2022, 18:34
What do you mean exactly with "limit to simpler data"? :) Need to check on how many times an NPC is being called but I think it is only once if I'm not very much mistaken. Need to check just to eliminate that possibility.

Moon Wizard
March 17th, 2022, 18:47
I mean that I would try running it with a single NPC with a single action, if I was running into issues. Then, you can make sure that code block is only running once, and work from there.

Regards,
JPG

Mephisto
March 20th, 2022, 17:57
You were spot on with your assumption about the code running twice. My debug code caused the problem.:pirate: Thanks to your advise I found the error in no time.