Varsuuk
July 24th, 2020, 06:51
[EDIT: IGNORE THREAD - I forgot the fact that if a control is a dbsourced control it will create the XML fields when OPENED not just imported, the rest makes sense once remembered order of actions and this whole thread might confuse more than helps but can't delete it or my contents - if did would orphan responses. and prob be rude :) ]
I have a PreGen setup for this MoreCore extension (originally based off OSE and Tutorial)
The pregen does not have the ac.xxx fields nor the aac.xxxx fields in it. When I import from pregen and do /save I do not see any "ac" or "aac" entries - which is exactly what I expect.
But when I click on it, the behavior and logging indicates that it is not returning a nil from my "check"
What is the best way to check if a node exists? I presumed:
if DB.getChild(nodeChar, "ac.armour") == nil then
The code I have is confusing me, in some previous incarnation (before rearranged) I was getting "nil" when doing:
DB.getValue(dbNode, "ac.armour")
Here is the log part that matters:
Runtime Notice: s'---> onInit()'
Runtime Notice: databasenode = { charsheet.id-00001 }
Runtime Notice: bFALSE
Runtime Notice: s'initACFields'
Runtime Notice: databasenode = { charsheet.id-00001.ac.armour }
Runtime Notice: s'initAACFields'
Runtime Notice: databasenode = { charsheet.id-00001.aac.armour }
Runtime Notice: s'displayACSystemUsed'
Runtime Notice: s'---> DONE: onInit()'
The code is on the record_char_more.xml:
<root>
<!-- New WindowClass "charsheet_more" -->
<windowclass name="charsheet_more" merge="join">
<script>
function onInit()
Debug.console("---> onInit()")
if super.onInit() then
super.onInit()
end
local nodeChar = getDatabaseNode()
Debug.console(nodeChar)
local bIsAACEnabled = OptionsManager.isOption("AlternateRule_UseAscendingAC", "on")
Debug.console(bIsAACEnabled)
CharacterUpdate.initACFields(nodeChar)
CharacterUpdate.initAACFields(nodeChar)
OptionsManager.registerCallback("AlternateRule_UseAscendingAC", onARUseAscendingACChanged);
displayACSystemUsed(bIsAACEnabled)
Debug.console("---> DONE: onInit()")
end
The field I am checking first, for example, is:
function initACFields(nodeChar)
Debug.console("initACFields")
Debug.console(DB.getChild(nodeChar, "ac.armour"))
if DB.getChild(nodeChar, "ac.armour") == nil then
DB.setValue(nodeChar, "ac.armour", "number", 9)
DB.setValue(nodeChar, "ac.dex", "number", 0)
DB.setValue(nodeChar, "ac.bonus", "number", 0)
end
updateAC(nodeChar)
end
And by this point, the Debug prints that ac.armour node seems to exist if I read this right?
How, I thought getChild does not create it if not found?
The rest falls apart because I wanted to only reset fields on first creation. IF there is another way, it's fine to suggest it :) but still want to know why getChild returns a valid child.
Later in the XML (I had removed the onInit() for example: (I checked the chain of templates - I THINK - and see no auto setting of default or whatever)
<!-- Replace AC fields -->
<number_ctlink name="defence" merge="replace">
<anchored to="combatframe" position="insidetopright" offset="15,49" />
<tooltip textres="pc_tooltip_defence" />
</number_ctlink>
<!-- Extra AC fields -->
<totnumber name="ac_armour" source="ac.armour">
<anchored to="combatframe" position="insidetopright" offset="96,49" width="18"/>
<tooltip textres="char_label_armour_value"/>
<script>
function onValueChanged()
local nodeWin = window.getDatabaseNode();
Debug.console("AV update");
CharacterUpdate.updateAC(nodeWin);
end
</script>
</totnumber>
<totnumber name="ac_dex" source="ac.dex">
...
I have a PreGen setup for this MoreCore extension (originally based off OSE and Tutorial)
The pregen does not have the ac.xxx fields nor the aac.xxxx fields in it. When I import from pregen and do /save I do not see any "ac" or "aac" entries - which is exactly what I expect.
But when I click on it, the behavior and logging indicates that it is not returning a nil from my "check"
What is the best way to check if a node exists? I presumed:
if DB.getChild(nodeChar, "ac.armour") == nil then
The code I have is confusing me, in some previous incarnation (before rearranged) I was getting "nil" when doing:
DB.getValue(dbNode, "ac.armour")
Here is the log part that matters:
Runtime Notice: s'---> onInit()'
Runtime Notice: databasenode = { charsheet.id-00001 }
Runtime Notice: bFALSE
Runtime Notice: s'initACFields'
Runtime Notice: databasenode = { charsheet.id-00001.ac.armour }
Runtime Notice: s'initAACFields'
Runtime Notice: databasenode = { charsheet.id-00001.aac.armour }
Runtime Notice: s'displayACSystemUsed'
Runtime Notice: s'---> DONE: onInit()'
The code is on the record_char_more.xml:
<root>
<!-- New WindowClass "charsheet_more" -->
<windowclass name="charsheet_more" merge="join">
<script>
function onInit()
Debug.console("---> onInit()")
if super.onInit() then
super.onInit()
end
local nodeChar = getDatabaseNode()
Debug.console(nodeChar)
local bIsAACEnabled = OptionsManager.isOption("AlternateRule_UseAscendingAC", "on")
Debug.console(bIsAACEnabled)
CharacterUpdate.initACFields(nodeChar)
CharacterUpdate.initAACFields(nodeChar)
OptionsManager.registerCallback("AlternateRule_UseAscendingAC", onARUseAscendingACChanged);
displayACSystemUsed(bIsAACEnabled)
Debug.console("---> DONE: onInit()")
end
The field I am checking first, for example, is:
function initACFields(nodeChar)
Debug.console("initACFields")
Debug.console(DB.getChild(nodeChar, "ac.armour"))
if DB.getChild(nodeChar, "ac.armour") == nil then
DB.setValue(nodeChar, "ac.armour", "number", 9)
DB.setValue(nodeChar, "ac.dex", "number", 0)
DB.setValue(nodeChar, "ac.bonus", "number", 0)
end
updateAC(nodeChar)
end
And by this point, the Debug prints that ac.armour node seems to exist if I read this right?
How, I thought getChild does not create it if not found?
The rest falls apart because I wanted to only reset fields on first creation. IF there is another way, it's fine to suggest it :) but still want to know why getChild returns a valid child.
Later in the XML (I had removed the onInit() for example: (I checked the chain of templates - I THINK - and see no auto setting of default or whatever)
<!-- Replace AC fields -->
<number_ctlink name="defence" merge="replace">
<anchored to="combatframe" position="insidetopright" offset="15,49" />
<tooltip textres="pc_tooltip_defence" />
</number_ctlink>
<!-- Extra AC fields -->
<totnumber name="ac_armour" source="ac.armour">
<anchored to="combatframe" position="insidetopright" offset="96,49" width="18"/>
<tooltip textres="char_label_armour_value"/>
<script>
function onValueChanged()
local nodeWin = window.getDatabaseNode();
Debug.console("AV update");
CharacterUpdate.updateAC(nodeWin);
end
</script>
</totnumber>
<totnumber name="ac_dex" source="ac.dex">
...