PDA

View Full Version : Not getting right value with DB.getValue... not sure how this is possible.



celestian
July 7th, 2017, 02:58
I am trying to get the "castinitiative" value from a entry that I know for a fact has a number 8 in the value (see xml) but when I get it with DB.getValue it returns 0. Can anyone see what I'm doing wrong here? The use case for this is I am flipping through all spells and moving that castinitiative value to the "nodeSpell" and no longer on the nodeAction->cast type.

Here is the LUA:



function migrateSpellInitiative(nodeSpell,nodeAction)
local sName = DB.getValue(nodeSpell,"name","");
local sType = DB.getValue(nodeAction,"type","");
local nOrder = DB.getValue(nodeAction,"order",0);
local nInit = DB.getValue(nodeAction,"castinitiative",0);
Debug.console("manager_version2.lua","migrateSpellInitiative","nodeSpell",nodeSpell);
Debug.console("manager_version2.lua","migrateSpellInitiative","nodeAction",nodeAction);
Debug.console("manager_version2.lua","migrateSpellInitiative","sName",sName);
Debug.console("manager_version2.lua","migrateSpellInitiative","sType",sType);
Debug.console("manager_version2.lua","migrateSpellInitiative","nOrder",nOrder);
Debug.console("manager_version2.lua","migrateSpellInitiative","nInit",nInit);
if (sType == "cast") then
DB.deleteChild(nodeAction, "castinitiative");
if (nInit > 0) then
DB.setValue(nodeSpell,"castinitiative","number",nInit);
end
end
end



Here is the XML with the raw values/fields:



<id-00117>
<actions>
<id-00003>
<castinitiative type="number">8</castinitiative>
<order type="number">1</order>
<type type="string">cast</type>
</id-00003>
<id-00004>
<castinitiative type="number">0</castinitiative>
<heallist>
<id-00001>
<bonus type="number">3</bonus>
<dice type="dice">d8,d8,d8</dice>
</id-00001>
</heallist>
<order type="number">2</order>
<type type="string">heal</type>
</id-00004>
</actions>
<aoe type="string">1 creature</aoe>
<cast type="number">0</cast>
<castingtime type="string">8</castingtime>
<components type="string">V, S</components>
<description type="formattedtext">
<p>The <i>cure critical wounds </i>spell is a very potent version of the <i>cure light wounds </i>spell. The priest lays his hand upon a creature and heals <b>3d8+3 </b>points of damage from wounds or other damage. The spell does not affect creatures without corporeal bodies, those of extraplanar origin, or those not living.</p>
<p>The reversed spell, <i>cause critical wounds </i>, operates in the same fashion as other <i>causes wounds </i>spells, requiring a successful touch to inflict the <b>3d8+3 </b>points of damage. Caused wounds heal via the same methods as do wounds of other sorts.</p>
</description>
<duration type="string">Permanent</duration>
<level type="number">5</level>
<locked type="number">1</locked>
<memorized type="number">0</memorized>
<name type="string">Cure Critical Wounds</name>
<prepared type="number">0</prepared>
<range type="string">Touch</range>
<reversible type="number">1</reversible>
<ritual type="number">0</ritual>
<save type="string">None</save>
<school type="string">Necromancy</school>
<shortdescription type="string">Range: Touch, AoE: 1 creature, Duration: Permanent, Cast Time: 8, Save: None</shortdescription>
<source type="string">AD&D Core Rules</source>
<sphere type="string">Healing</sphere>
<type type="string">Divine</type>
</id-00117>



Here is the debug output. The value returned in nInit should be what the XML shows but it keeps returning 0.



Runtime Notice: s'manager_version2.lua' | s'migrateSpellInitiative' | s'nodeSpell' | databasenode = { spell.id-00117 }
Runtime Notice: s'manager_version2.lua' | s'migrateSpellInitiative' | s'nodeAction' | databasenode = { spell.id-00117.actions.id-00003 }
Runtime Notice: s'manager_version2.lua' | s'migrateSpellInitiative' | s'sName' | s'Cure Critical Wounds'
Runtime Notice: s'manager_version2.lua' | s'migrateSpellInitiative' | s'sType' | s'cast'
Runtime Notice: s'manager_version2.lua' | s'migrateSpellInitiative' | s'nOrder' | #1
Runtime Notice: s'manager_version2.lua' | s'migrateSpellInitiative' | s'nInit' | #0

LordEntrails
July 7th, 2017, 04:01
I'm not a coder, but you set the value of castinitiative twice in your xml. The second time it is set to 0, so I suspect that overrides the earlier set value of 8.

Though maybe these are different entities and the lua is calling the wrong one or...?

celestian
July 7th, 2017, 04:31
I'm not a coder, but you set the value of castinitiative twice in your xml. The second time it is set to 0, so I suspect that overrides the earlier set value of 8.

Though maybe these are different entities and the lua is calling the wrong one or...?

You are referring to id-4? Yes, it has a 0 value but im looking at the first one, which is 3.

spell.id-00117.actions.id-00003

The scope of that bit of code doesn't (shouldnt) even know that spell.id-00117.actions.id-00004 exists.

The odd thing about all of this is the code actually works like it should. I ran it and the spells were all updated as they should be even tho the debug for nInit was always 0. I am just curious WHY it's showing that so if I see it in the future I can be aware of it.

Nickademus
July 7th, 2017, 05:21
Just glancing, but I can tell you this. The code...
DB.getValue(nodeAction,"castinitiative",0);... gets the value of the child of databasenode stored in nodeAction with the name of 'castinitiative', or the value #0 if either:

nodeAction doesn't exist
nodeAction isn't a databasenode
nodeAction doesn't have a child called 'castinitiative'
nodeAction or castinitiative aren't set to public or owned by the player client (if not the GM)
castinitiative doesn't have a valid type
something goes wrong in the getValue function


So something isn't matching up between nodeAction, castinitiative, and the getValue function. Try removing the the default value and see if it gives you 'nil' for nInit.

DB.getValue(nodeAction,"castinitiative");

celestian
July 7th, 2017, 06:00
Just glancing, but I can tell you this. The code...
DB.getValue(nodeAction,"castinitiative",0);... gets the value of the child of databasenode stored in nodeAction with the name of 'castinitiative', or the value #0 if either:

nodeAction doesn't exist
nodeAction isn't a databasenode
nodeAction doesn't have a child called 'castinitiative'
nodeAction or castinitiative aren't set to public or owned by the player client (if not the GM)
castinitiative doesn't have a valid type
something goes wrong in the getValue function




debug shows that it does
debug shows that it is
XML code shows it
not sure how to set this?
xml code shows it set to number
dunno ;)


Your list was kinda the same list I kept going down repeatedly... that and copy/pasting the name for the value "castinitiative" thinking I had copied it wrong and was trying to get the wrong value.



So something isn't matching up between nodeAction, castinitiative, and the getValue function. Try removing the the default value and see if it gives you 'nil' for nInit.

DB.getValue(nodeAction,"castinitiative");

I actually tried that during my testing and it did give me nil.

Trenloe
July 7th, 2017, 06:05
Is the DB snip you include from a spell within the actions tab of a character sheet? Or is it a spell in the campaign data lists?

Trenloe
July 7th, 2017, 06:10
Additionally, if this code has ran just one, it could have already deleted the node with DB.deleteChild(nodeAction, "castinitiative");

The FG db.xml file gets saved every 5 minutes or so. It doesn't get saved just when there are changes to the made to the database. So, I'm guessing, but maybe that code has already ran before and deleted the "castinitiative" node, but the db.xml file hasn't saved yet to reflect the up-to-date data? So you think "castinitiative" is there, but in the FG database in memory it isn't??

You can force a save by using /save in the chat window.

celestian
July 7th, 2017, 06:49
Is the DB snip you include from a spell within the actions tab of a character sheet? Or is it a spell in the campaign data lists?

It's the actual spell record of the campaign, not a character sheet. I added a feature in my ruleset that allows you to add "actions" to a spell so when you drag/drop them onto a npc/pc they will populate in those locations.


Additionally, if this code has ran just one, it could have already deleted the node with DB.deleteChild(nodeAction, "castinitiative");

The FG db.xml file gets saved every 5 minutes or so. It doesn't get saved just when there are changes to the made to the database. So, I'm guessing, but maybe that code has already ran before and deleted the "castinitiative" node, but the db.xml file hasn't saved yet to reflect the up-to-date data? So you think "castinitiative" is there, but in the FG database in memory it isn't??

You can force a save by using /save in the chat window.

This output was the result of a first run...when the xml was as you saw (old proper values). I was replacing it with the xml that needed conversion and issuing a /reload to force it so I could see the results.

Trenloe
July 7th, 2017, 14:28
I was replacing it with the xml that needed conversion and issuing a /reload to force it so I could see the results.
You should only ever edit any campaign data, including db.xml, when the campaign is not running. Exit the campaign, make your changes, then load the campaign. Don't use /reload as this can have unpredictable results regarding changed campaign data, it is designed to reload changes to the ruleset code.

Nickademus
July 7th, 2017, 19:12
/reload doesn't save the database to the db.xml file. You need to use /save first to do that.

celestian
July 7th, 2017, 19:51
You should only ever edit any campaign data, including db.xml, when the campaign is not running. Exit the campaign, make your changes, then load the campaign. Don't use /reload as this can have unpredictable results regarding changed campaign data, it is designed to reload changes to the ruleset code.

Well, I've no idea how to bring up the console without loading the ruleset first and typing /console. That was the only way I could test but you are right it certainly had unpredictable results.


/reload doesn't save the database to the db.xml file. You need to use /save first to do that.

To be clear, I wasn't trying to save the database. I wanted to see the debug results of the "convert" to new version format. Thats why the reload after I had replaced the db.xml file.

I suspect the problem is as Trenloe suggests, unpredictable results when replacing the db.xml and reloading. The updated xml file was correct but the debug output was not showing the same thing.