-
September 26th, 2021, 18:02 #1
- Join Date
- Jun 2017
- Posts
- 61
How to DB.getChild() using a string value?
So I'm trying to get the value of a field for the source and target based on the use of a power. The source is the ability that the power uses and the vs is the ability that the target will use to defend (think multiple options based on situation). When I use my below code, I get a nil when accessing the data of what should have a value. Am I wrong in thinking I can use a string variable for the DB.getChild() function?
Code:function resolvePowerTest(rSource, rTarget, rRoll, rPower) local sSName = ActorManager.getCreatureNodeName(rSource); local sTName = ActorManager.getCreatureNodeName(rTarget); local sPSource = rPower.power_source.getValue(); <-- provides the correct source ability string local sPVs = rPower.power_vs.getValue(); <-- provides the correct vs ability string Debug.chat(sPSource .. " vs. " .. sPVs); local sSourceVal = DB.getChild(sSName, sPSource).getValue(); <-- return nil, however a DB.getChildren() will return the correct objects including the one I'm looking for Debug.chat(sSourceVal); local sVsVal = DB.getChild(sTName,sPVs).getValue(); <-- return nil, however a DB.getChildren() will return the correct objects including the one I'm looking for Debug.chat(sVsVal); local tRoll = ActionsManager.roll(rTarget, nil, rRoll, nil) local nTotal = ActionsManager.total(rRoll) + rRoll.nBonuses; local sSuccess = testResult(nTotal - 5); Debug.chat(sSuccess); end
Thanks in advance.
-
September 26th, 2021, 18:11 #2
DB.getChild, according to the API documentation, does accept a string for the source node: https://fantasygroundsunity.atlassia...82/DB#getChild
What's the exact error that you're getting?
What are the values of sSName and sPSource when you get this error?
What is your database structure?Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
September 26th, 2021, 18:26 #3
- Join Date
- Jun 2017
- Posts
- 61
Lots to unpack, here goes:
Script Error: [string "campaign/scripts/rollHandlers.lua"]:126: attempt to index a nil value. Line 126 is:
Code:local sSourceVal = DB.getChild(sSName, sPSource).getValue();
sPSource value is Strength
DB is:
Code:{ s'dmg' = databasenode = { charsheet.id-00001.dmg }, s'strength_bonus' = databasenode = { charsheet.id-00001.strength_bonus }, s'slashdr' = databasenode = { charsheet.id-00001.slashdr }, s'Checkbox2' = databasenode = { charsheet.id-00001.Checkbox2 }, s'intellect_bonus' = databasenode = { charsheet.id-00001.intellect_bonus }, s'coordination_bonus' = databasenode = { charsheet.id-00001.coordination_bonus }, s'inventorylist' = databasenode = { charsheet.id-00001.inventorylist }, s'Checkbox1' = databasenode = { charsheet.id-00001.Checkbox1 }, s'name' = databasenode = { charsheet.id-00001.name }, s'shootdr' = databasenode = { charsheet.id-00001.shootdr }, s'willpower_bonus' = databasenode = { charsheet.id-00001.willpower_bonus }, s'villain_check' = databasenode = { charsheet.id-00001.villain_check }, s'init_cb' = databasenode = { charsheet.id-00001.init_cb }, s'dr' = databasenode = { charsheet.id-00001.dr }, s'dl' = databasenode = { charsheet.id-00001.dl }, s'dp' = databasenode = { charsheet.id-00001.dp }, s'powerlist' = databasenode = { charsheet.id-00001.powerlist }, s'villain_chk' = databasenode = { charsheet.id-00001.villain_chk }, s'willpower' = databasenode = { charsheet.id-00001.willpower }, s'hp' = databasenode = { charsheet.id-00001.hp }, s'coins' = databasenode = { charsheet.id-00001.coins }, s'hv_choice' = databasenode = { charsheet.id-00001.hv_choice }, s'prowess' = databasenode = { charsheet.id-00001.prowess }, s'sfBackground' = databasenode = { charsheet.id-00001.sfBackground }, s'heavydr' = databasenode = { charsheet.id-00001.heavydr }, s'strength' = databasenode = { charsheet.id-00001.strength }, s'languagelist' = databasenode = { charsheet.id-00001.languagelist }, s'prowess_bonus' = databasenode = { charsheet.id-00001.prowess_bonus }, s'encumbrance' = databasenode = { charsheet.id-00001.encumbrance }, s'bashdr' = databasenode = { charsheet.id-00001.bashdr }, s'blastdr' = databasenode = { charsheet.id-00001.blastdr }, s'awareness' = databasenode = { charsheet.id-00001.awareness }, s'staminamodifier' = databasenode = { charsheet.id-00001.staminamodifier }, s'stamina' = databasenode = { charsheet.id-00001.stamina }, s'specialitylist' = databasenode = { charsheet.id-00001.specialitylist }, s'hpmodifier' = databasenode = { charsheet.id-00001.hpmodifier }, s'abilitylist' = databasenode = { charsheet.id-00001.abilitylist }, s'coordination' = databasenode = { charsheet.id-00001.coordination }, s'awareness_bonus' = databasenode = { charsheet.id-00001.awareness_bonus }, s'token' = databasenode = { charsheet.id-00001.token }, s'hero_chk' = databasenode = { charsheet.id-00001.hero_chk }, s'qualitylist' = databasenode = { charsheet.id-00001.qualitylist }, s'temp' = databasenode = { charsheet.id-00001.temp }, s'NumberField1' = databasenode = { charsheet.id-00001.NumberField1 }, s'intellect' = databasenode = { charsheet.id-00001.intellect } }
UPDATE: Yep, I'm dumb. It was the lowercase thing.Last edited by mixologee; September 26th, 2021 at 18:29. Reason: Updating
-
September 26th, 2021, 18:28 #4Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks