Hi,
I've had some success going forward with the "catname" problem. The problem is the recalc() function, which is called from three places in the windowclass "charsheet_skillcategory". If I move the recalc functions code to the two controls that calls it and modify it a bit, then that code works, the category bonuses are correctly calculated.
For the "catname" label:
Code:
function onValueChanged
if super and super.onValueChanged then
super.onValueChanged()
end
local name = getValue()
Debug.console("category", name)
local value = window.windowlist.getBonus(name)
Debug.console("bonus", value)
window.bonus.setValue(value)
end
and for the "bonus" basicnumber control:
Code:
function onValueChanged
if super and super.onValueChanged then
super.onValueChanged()
end
local name = window.catname.getValue()
Debug.console("category2", name)
local value = window.windowlist.getBonus(name)
Debug.console("bonus2", value)
bonus.setValue(value)
end
**************
So, so far so good, but the function recalc() is also called by the update() function which in turn is called by the onInit() function the first time you click on the skill tab. The update function can access the bonus control and make it visible, so it has access to the "bonus" control. If I edit the update() function, like below, and reload the ruleset and click on the Skill tab, then the debug statement "Debug.console("category4", name)" displays "s'category4' | s''". That is, it cannot access (or find) "catname", but it can access "bonus". The later is easy to verify because category names and bonus values are visible. The controls "bonus" and "catname" sould be in the same scope, right? So why can't I access "catname"?
Code:
function update()
print("update()")
local sOptionHRSCB = OptionsManager.getOption("HRSCB")
if sOptionHRSCB == "on" then
local node = windowlist.window.getDatabaseNode().createChild("abilities")
node.onChildUpdate = recalc
bonus.setVisible(true)
bonuslabel.setVisible(true)
local name = catname.getValue()
Debug.console("category4", name)
local value = windowlist.getBonus(name)
Debug.console("bonus4", value)
bonus.setValue(value)
else
bonus.setVisible(false)
bonuslabel.setVisible(false)
end
end
**************
The recalc() function is also accessed when a characteristic on the Main tab is changed (the line node.onChildUpdate = recalc in the update() function). When you access recalc() this way it throws an "attempt to index global" error. And it doesn't seem to mather what statement you put first in the function.
When I change the recalc() functions code and inserts a few debug statements and a print statement, like this:
Code:
function recalc()
print("recalc()")
local name = catname.getValue();
Debug.console("category3", name)
local value = windowlist.getBonus(name);
Debug.console("bonus3", value)
bonus.setValue(value);
end
Then I get the error: "attempt to index global 'print' (a nil value)". If I change the print statement to a debug statement, the error messages changes to "attempt to index global 'Debug' (a nil value)". There are two recalc funcions in record_char_skills.xml, so I renamed the recalc() function in charsheet_skillcategory to recalcat(), but that didn't have any effect. What would make a statement in a function throw "attempt to index global", regardless of what statement it is?
**************
Finally, It's worth noting that the code seems to work fine in FGC, from what I can tell.
/Peter