MostTornBrain
March 10th, 2022, 23:37
Hi,
I'm working on an extension for 2E that overrides the onLinkChanged() function in cta_entry.lua. Specifically, the existing 2E function is:
function onLinkChanged()
local node = getDatabaseNode();
-- If a PC, then set up the links to the char sheet
local sClass, sRecord = DB.getValue(node,"link","","");
--Debug.console("cta_Entry.lua","onLinkChanged","sClass",sClass);
if sClass == "charsheet" then
linkPCFields(DB.findNode(sRecord));
elseif sClass == "npc" then
-- linkNPCFields(DB.findNode(sRecord));
end
--onIDChanged();
end
and I am basically copying this function and adding some extra functionality on the "elseif" for "npc".
What confuses me: if I drag an NPC onto the combat tracker, my function gets called, but the sClass value returned from DB.getValue(node,"link","","") is nil. However, if I then save and reload my campaign, this same NPC returns sClass of "npc" when onLinkChanged() is called. What would be different between the active drag and drop of an NPC vs. reloading the campaign?
Is there any way I can get the equivalent of the sClass value when the drag and drop onto the combat tracker first happens? Obviously having to reload the campaign to get onLinkChanged() to detect an NPC is a bit unwieldy in regular use. Basically, I'm trying to know when an NPC is dropped onto the combat tracker so my extension can do some special handling of it, but my special handling only gets triggered if I reload the campaign.
Thanks for any ideas.
Cheers,
Brian
I'm working on an extension for 2E that overrides the onLinkChanged() function in cta_entry.lua. Specifically, the existing 2E function is:
function onLinkChanged()
local node = getDatabaseNode();
-- If a PC, then set up the links to the char sheet
local sClass, sRecord = DB.getValue(node,"link","","");
--Debug.console("cta_Entry.lua","onLinkChanged","sClass",sClass);
if sClass == "charsheet" then
linkPCFields(DB.findNode(sRecord));
elseif sClass == "npc" then
-- linkNPCFields(DB.findNode(sRecord));
end
--onIDChanged();
end
and I am basically copying this function and adding some extra functionality on the "elseif" for "npc".
What confuses me: if I drag an NPC onto the combat tracker, my function gets called, but the sClass value returned from DB.getValue(node,"link","","") is nil. However, if I then save and reload my campaign, this same NPC returns sClass of "npc" when onLinkChanged() is called. What would be different between the active drag and drop of an NPC vs. reloading the campaign?
Is there any way I can get the equivalent of the sClass value when the drag and drop onto the combat tracker first happens? Obviously having to reload the campaign to get onLinkChanged() to detect an NPC is a bit unwieldy in regular use. Basically, I'm trying to know when an NPC is dropped onto the combat tracker so my extension can do some special handling of it, but my special handling only gets triggered if I reload the campaign.
Thanks for any ideas.
Cheers,
Brian