PDA

View Full Version : ActionsManager.registerModHandler for Table Roll Script



leozelig
May 3rd, 2021, 02:31
Hey everyone,

I'm not sure if I can articulate this clearly... I have a button on the character sheet that rolls a specified die on a specified table, and the roll is modified by one of the ability score modifiers. I want to set up a modRoll function that checks for any ability effects from the combat tracker. I tried this:



function onInit()
ActionsManager.registerModHandler("table", modRoll);
end


Here is my performRoll function:


function performRoll(draginfo, rActor)
local rRoll = getRoll(rActor, rTarget);

TableManager.performRoll(nil, rActor, rRoll, true);
end



The modRoll callback (not shown here) does not run. Does anyone have any ideas why this isn't working? Maybe this doesn't work with the TableManager.performRoll function?

Thanks,
Leo

Varsuuk
May 3rd, 2021, 03:42
I have only worked with MoreCore rollers thus far. I looked at this for two reasons, 1) everyone is always helping me - so figured take a look even if it isn't my expertise. 2) Looking is learning - maybe I'll actually remember what I find in months when do non MoreCore. But maily #1, I know my memory sucks.


I found in CoreRPG manager_actions.lua the following:


function applyModifiers(rSource, rTarget, rRoll, bSkipModStack)
local bAddModStack = ActionsManager.doesRollHaveDice(rRoll);
if bSkipModStack then
bAddModStack = false;
elseif GameSystem.actions[rRoll.sType] then
bAddModStack = GameSystem.actions[rRoll.sType].bUseModStack;
end

local fMod = aModHandlers[rRoll.sType];
if fMod then
local bReturn = fMod(rSource, rTarget, rRoll);
if bReturn ~= true then
rRoll.aDice.expr = nil;
end
end
...


The lookup is via rRoll.sType. I presume it is some named key. Maybe put a print right before this:
Debug.console(rRoll)
Debug.console(rRoll.sType) (to isolate clearer)

and after the
local fMod = aModHandlers[rRoll.sType];

Debug.console("fMod=", fMod)

or something?



----

Presumably rRoll's name matches the name you passed on the ModHandler?

leozelig
May 3rd, 2021, 11:12
Thanks, Varsuuk. I confirmed that rRoll.sType matches the ModHandler and bAddModStack is true. The ModStack works, but the modRoll function doesn’t run. I will try your suggestions to see what is getting passed to the applyModifiers function.

Varsuuk
May 3rd, 2021, 18:23
In middle of my own debugging at work (email alert caught my eye) ;) so can’t look even if had info just now. But, before forget, I tested this when I was adding my turn undead roll to my morecore based thing.

I tried my suspicion and recall I was right. Setting that flag just stops the mod box updates (prob same for the buttons, didn’t have any yet to test) but does not affect onModHabdler- that is called if you define it it is separate from the book flag.

leozelig
May 3rd, 2021, 22:14
Yes, that seems to be the case with bAddModStack. I changed the roll type from "table" to "critical", which is defined in GameSystem.actions, but that didn't help. I'm just wondering if it has something to do with the TableManager.performRoll function not going through the same action sequence.

Varsuuk
May 3rd, 2021, 22:46
You might want to look at MoreCore’s roller handling (just search on addModHandler or whatever called. I’m burnt out about to pass out on couch or would look.

I find tracing what gets done when a sample morecore_custom_dbdamage.lua or whatever sample handler is setup might give you clues?

Did you get to see what the logging said?
Love to help if can. If it’s in your DCC I have that Ruleset and could try adding your new code by hand into mine if it is limited to one or two file changes later tonight after nap :?

leozelig
May 3rd, 2021, 23:38
Here's the Debug output from applyModifiers:

rRoll
{ s'aDice' = { #1 = s'd20' }, s'nMod' = #1, s'sNodeTable' = s'tables.id-00039', s'sType' = s'table', s'sDesc' = s'[TABLE] Table 7-1: Artifact Checks [+1]', s'sOutput' = s'', s'bSecret' = bFALSE }

fMod
fn

It looks like sType is changing to 'table' after it gets passed to TableManager for the roll, even if I define the roll as something else in my getRoll function. But even if the roll type is 'table', the modRoll function isn't running.

I'm going to move on to something else, but let me know if you have any ideas.

Trenloe
May 4th, 2021, 08:51
Here's the Debug output from applyModifiers:

rRoll
{ s'aDice' = { #1 = s'd20' }, s'nMod' = #1, s'sNodeTable' = s'tables.id-00039', s'sType' = s'table', s'sDesc' = s'[TABLE] Table 7-1: Artifact Checks [+1]', s'sOutput' = s'', s'bSecret' = bFALSE }

fMod
fn
Is this from CoreRPG ActionsManager.applyModifiers? If so, add some debug to make sure that the if fMod then code is actually running. If it is, and debug in your first line of code in the registered function modRoll doesn't run (I'm making assumptions you've done this to confirm if the function is running) is not running, then it sounds like there's an issue with the registered function - as that code within if fMod then wouldn't run unless there's a mod handler function registered for the roll type.

leozelig
May 4th, 2021, 12:44
Yes, 'if fMod' is running. Here is the debug output for aModHandlers:

{ s'artifact' = fn, s'dice' = fn, s'init' = fn, s'airecognition' = fn, s'save' = fn, s'skill' = fn, s'cast' = fn, s'heal' = fn, s'table' = fn, s'check' = fn, s'damage' = fn, s'attack' = fn }

The mod handler for 'artifact' seems to be registering, but it doesn't run. The ActionArtifact script sends the roll data to TableManager for the roll, so I'm thinking that's where things are getting lost.

Trenloe
May 4th, 2021, 13:43
The mod handler for 'artifact' seems to be registering, but it doesn't run. The ActionArtifact script sends the roll data to TableManager for the roll, so I'm thinking that's where things are getting lost.
Any mod handler is based on the name of the action type name, stored in rRoll.sType. If you're calling TableManager.performRoll to make your roll, that sets rRoll.sType = "table" - so any handlers need to be registered with a name of "table". That seemed to be what you're doing based off post #1 but now you're mentioning "artifact". Can you take a step back and detail exactly what it is you're doing?

leozelig
May 5th, 2021, 02:23
Yes, I changed it from "table" to "artifact". Here's a little more detail on what I am trying to do:

I have 3 scripts with similar architecture: ActionArtifact, ActionCritical, and ActionFumble. The first two scripts roll on a table designated on the char sheet when the player rolls a critical hit or fumble. This is modified by the Luck ability score (adds mod to crit and subtracts from fumble), so the modRoll function is looking for effects that modify the Luck score. The ActionArtifact script rolls a d20 + Int mod on a designated table when the player double-clicks or drags the rollable field on the char sheet, so I need the modRoll function to account for effects that modify the Int score. Basically, when all three rolls are set as "table", the modRoll function for ActionFumble runs for all 3 scripts. That makes sense if each action type can only have one mod handler associated with it. Since TableManager changes the roll type to "table", creating unique action types for each script (artifact, critical, fumble) doesn't work. The scripts otherwise contain the standard getRoll and performRoll functions, so nothing fancy going on there.

Thanks for any help you can offer Trenloe. Clearly I am not understanding something about mod handlers, or I am simply bumping up against the limitations of the ruleset API.

leozelig
May 5th, 2021, 02:36
I'm going to try copying the TableManager.performRoll function to my scripts, removing the unnecessary parts and leaving rRoll.sType = "artifact", "critical", or "fumble". I will update this thread with my solution if it works.

leozelig
May 5th, 2021, 03:37
So, here's what ended up working for me. I inserted one line of code in the getRoll function (blue text), and I added the result handler for processing the table output. I simplified the code a little, but this is most of it:


function onInit()
ActionsManager.registerModHandler("artifact", modRoll);
ActionsManager.registerResultHandler("artifact", TableManager.onTableRoll);
end

function getRoll(rActor)
local rRoll = {};
rRoll.sType = "artifact";
rRoll.aDice = {"d20"};

local _,nodeActor = ActorManager.getTypeAndNode(rActor);
rRoll.nMod = DB.getValue(nodeActor, "artifactcheck.total", 0);

rRoll.sTable = "Table 7-1: Artifact Checks";
local sCustom = DB.getValue(nodeActor, "artifacttable", "");
if sCustom ~= "" then
rRoll.sTable = sCustom;
end

rRoll.sDesc = "[ARTIFACT CHECK] " .. rRoll.sTable;


-- Resolve table node
rRoll.nodeTable = TableManager.findTable(rRoll.sTable);
if not rRoll.nodeTable then
local sTableSansModule = StringManager.split(rRoll.sTable, "@")[1];
rRoll.nodeTable = DB.findNode(sTableSansModule .. "@*");
end

if rRoll.nodeTable then
rRoll.sNodeTable = rRoll.nodeTable.getPath();
else
rRoll.sType = "dice";
ChatManager.SystemMessage(Interface.getString("char_error_missingtable"));
end

return rRoll;
end

function performRoll(draginfo, rActor)
local rRoll = getRoll(rActor);

ActionsManager.performAction(draginfo, rActor, rRoll);
end


function modRoll(rSource, rTarget, rRoll)
local aAddDesc = {};
local aAddDice = {};
local nAddMod = 0;


if rSource then
local bEffects = false;

-- Get ability effect modifiers
local nAbilityMod, nAbilityEffects = ActorManagerMCC.getAbilityEffectsBonus(rSource, "intelligence");
if nAbilityEffects > 0 then
bEffects = true;
nAddMod = nAddMod + nAbilityMod;
end

-- If effects happened, then add note
if bEffects then
local sEffects = "";
local sMod = StringManager.convertDiceToString(aAddDice, nAddMod, true);
if sMod ~= "" then
sEffects = "[" .. Interface.getString("effects_tag") .. " " .. sMod .. "]";
else
sEffects = "[" .. Interface.getString("effects_tag") .. "]";
end
table.insert(aAddDesc, sEffects);
end
end

if #aAddDesc > 0 then
rRoll.sDesc = rRoll.sDesc .. " " .. table.concat(aAddDesc, " ");
end
for _,vDie in ipairs(aAddDice) do
if vDie:sub(1,1) == "-" then
table.insert(rRoll.aDice, "-p" .. vDie:sub(3));
else
table.insert(rRoll.aDice, "p" .. vDie:sub(2));
end
end

rRoll.nMod = rRoll.nMod + nAddMod;
end