Mooooaaaarrrr MoreCore!
Printable View
Mooooaaaarrrr MoreCore!
I have another question. I am trying to set up certain windows on my items screen to lock when I hit the lock icon. This is the code I have so far:
I took it from 5E and made some adjustments. As it sits now, it works with no problem, but the two commented out fields do not lock. If I uncomments then, I get the error:Code:function onInit()
update();
end
function VisDataCleared()
update();
end
function InvisDataAdded()
update();
end
function updateControl(sControl, bReadOnly)
if not self[sControl] then
return false;
end
return self[sControl].update(bReadOnly);
end
function update()
local nodeRecord = getDatabaseNode();
local bReadOnly = WindowManager.getReadOnlyState(nodeRecord);
local bWeapon = ItemManager2.isWeapon(nodeRecord);
local bArmor = ItemManager2.isArmor(nodeRecord);
local bSection1 = false;
if updateControl("type", bReadOnly) then bSection1 = true; end
if updateControl("range", bReadOnly) then bSection1 = true; end
local bSection2 = false;
-- if updateControl("damagerating", bReadOnly) then bSection2 = true; end
-- if updateControl("resistance", bReadOnly) then bSection2 = true; end
if updateControl("effect", bReadOnly) then bSection2 = true; end
local bSection3 = false;
if updateControl("size", bReadOnly) then bSection3 = true; end
if updateControl("qualities", bReadOnly) then bSection3 = true; end
if updateControl("cost", bReadOnly) then bSection3 = true; end
local bSection4 = true
notes.setReadOnly(bReadOnly);
divider.setVisible(bSection1 and bSection2);
divider2.setVisible((bSection1 or bSection2) and bSection3);
divider3.setVisible((bSection1 or bSection2 or bSection3) and bSection4);
end
The difference between those fields and the others are those two are number fields and everything else is a string field. However, when I look at the code in 5E, they have this on numbers and strings, and it works fine. The only big difference was I got rid of the bID bit, because I don't want to have non-ID settings.Quote:
attempt to call field 'update' (a nil value)
What template are you using to implement those fields?
The scripts associated with those templates must have an update function, which is the error reporting when you uncomment.
There are some templates in CoreRPG that implement those functions for strings and numbers already that you can reuse. If you’re making a custom field, you’ll need to implement your own script for those fields.
Make sure to use a multi-file text search with a good text editor to track back the templates to see what is being inherited.
Regards,
JPG
I was able to fix it. Upon looking back at the code I borrowed from, I realized I was using the wrong template for the number fields. I was off by one letter. Once I fixed that, it was all set.
You all have been so helpful.
This is in the LUA file. As it stands, when I open the character sheet and I go to Attributes I have a number default for these fields. After visiting the Attributes, when I run through the cycler to activate this code, it works perfectly fine. However, if I create a new character, and do not go to the Attributes page, once I start cycling, I get an error saying setChild is a nul value. I assume it's because the field has yet to be created in the DB. How can I change the code to have it create the DB fields if it's not been created yet?Code:function rankchange(draginfo, winFrame)
local nodeWin = winFrame.getDatabaseNode();
local curRank = DB.getValue(nodeWin, "rank");
DB.setValue(nodeWin, "reputation.rank", "string", curRank);
DB.setValue(nodeWin, "reputation.reputation", "number", 10);
if DB.getValue(nodeWin, "reputation.rank") == "Ensign" then
nodeWin.getChild("reputation.privilege").setValue(1);
nodeWin.getChild("reputation.responsibility").setValue(20);
elseif DB.getValue(nodeWin, "reputation.rank") == "Lieutenant JG" then
nodeWin.getChild("reputation.privilege").setValue(1);
nodeWin.getChild("reputation.responsibility").setValue(20);
elseif DB.getValue(nodeWin, "reputation.rank") == "Lieutenant" then
nodeWin.getChild("reputation.privilege").setValue(2);
nodeWin.getChild("reputation.responsibility").setValue(19);
elseif DB.getValue(nodeWin, "reputation.rank") == "Lieutenant Commander" then
nodeWin.getChild("reputation.privilege").setValue(2);
nodeWin.getChild("reputation.responsibility").setValue(19);
elseif DB.getValue(nodeWin, "reputation.rank") == "Commander" then
nodeWin.getChild("reputation.privilege").setValue(3);
nodeWin.getChild("reputation.responsibility").setValue(18);
elseif DB.getValue(nodeWin, "reputation.rank") == "Captain" then
nodeWin.getChild("reputation.privilege").setValue(4);
nodeWin.getChild("reputation.responsibility").setValue(17);
else
nodeWin.getChild("reputation.privilege").setValue(1);
nodeWin.getChild("reputation.responsibility").setValue(20);
end
end
Use <dbnode>.createChild - https://www.fantasygrounds.com/refdo...cp#createChild