PDA

View Full Version : How to DB.getChild() using a string value?



mixologee
September 26th, 2021, 18:02
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?



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


Am I just missing something simple (my Lua skills are basic at best) or can this not be done?

Thanks in advance.

Trenloe
September 26th, 2021, 18:11
DB.getChild, according to the API documentation, does accept a string for the source node: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644582/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?

mixologee
September 26th, 2021, 18:26
Lots to unpack, here goes:

Script Error: [string "campaign/scripts/rollHandlers.lua"]:126: attempt to index a nil value. Line 126 is:

local sSourceVal = DB.getChild(sSName, sPSource).getValue();

sSName value is s'charsheet.id-00001'
sPSource value is Strength

DB is:



{ 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 } }

As I am filling this out, I realize that the value I'm getting is capitalized and the DB isn't....I'm assuming that is my problem...will test it out...


UPDATE: Yep, I'm dumb. It was the lowercase thing.

Trenloe
September 26th, 2021, 18:28
As I am filling this out, I realize that the value I'm getting is capitalized and the DB isn't....I'm assuming that is my problem...will test it out...
That'll probably be it. :)