View Full Version : registerTargetingHandler error
psicodelix
February 26th, 2026, 07:51
Hello,
I have detected a problem in ActionsManager.registerTargetingHandler. What happens is that when a roll is made with a click and the system determines the targets, the TargetingHandler function is called correctly. But when drag and drop is used, it is not.
I have traced the problem to this CoreRPG function:
function getTargetingGroups(rSource, vPreTargeted, rRolls)
if not rRolls then
return { { } };
end
local tResults;
if vPreTargeted then
if (type(vPreTargeted) == "table") and (#vPreTargeted > 0) then
tResults = vPreTargeted;
else
tResults = { { vPreTargeted } };
end
end
if not tResults then
if ModifierStack.getTargeting() then
tResults = ActionsManager.getTargeting(rSource, rTarget, rRolls.sDragType, rRolls);
else
tResults = { { } };
end
end
GameManager.callEventFunctions("onActionPostTargeting", rSource, tResults, rRolls);
return tResults;
end
when drag and drop is used, the vPreTargeted parameter is not null, and the tResults structure is created, and therefore it does not enter the second part, where ActionsManager.getTargeting is called, which is where the call to the TargetingHandler function seems to be triggered.
In previous versions of CoreRPG this did work. Am I missing something?
LordEntrails
February 26th, 2026, 15:36
Is this only when in the test channel? If this is the live channel I can move this to the regular House of Healing. This sub is for the public beta test via the Test channel (which is not currently active)
psicodelix
February 26th, 2026, 15:43
oh, yes, sorry, it is in the live channel.
Moon Wizard
February 27th, 2026, 03:00
Where are you dragging and dropping that you're seeing that? It appears to be working for me in the 5E ruleset.
When I drag and drop into the chat window (or the desktop) in the 5E ruleset; it has a nil value for vPretargeted, and used the targets from the map/CT.
When I drag and drop onto a token in the 5E ruleset; it has the actor structure for the creature from the combat tracker represented by the token.
(I added a debug output at the beginning of getTargetingGroups specifically to return the value.)
Regards,
JPG
psicodelix
February 27th, 2026, 09:22
This is in an old custom ruleset. The problem occurs when dropping from the character sheet onto the Combat Tracker window.
The ruleset has code similar to the following to generate a roll:
function onButtonPress()
return action();
end
function onDragStart(button, x, y, draginfo)
return action(draginfo);
end
function action(dragInfo)
GameSystem.actions["btnTestRollAction"] = { sTargeting = "each" }
ActionsManager.registerResultHandler("btnTestRollAction", manager.onResult);
ActionsManager.registerTargetingHandler("btnTestRollAction", manager.onTargeting);
local rRoll = { sType = "btnTestRollAction", sDesc = "Test", aDice = "d20", nMod = 0, nBonuses = 0};
local rCreature = ActorManager.resolveActor(window.getDatabaseNode() );
if dragInfo then
ActionsManager.encodeActionForDrag(dragInfo, rCreature, "btnTestRollAction", rRoll);
end
ActionsManager.performAction(dragInfo, rCreature, rRoll);
return true;
end
That roll must call a custom TargetingHandler function (manager.onTargeting). If the roll is made with a double click, that function is called correctly, but when dragging and dropping, it is not.
Moon Wizard
February 27th, 2026, 21:49
The execution order is: decodeActionFromDrag->actionRoll->getTargetingGroups->getTargeting->customHandler
The getTargeting->customHandler segment is not called if vPretargeted is not null.
The debugs I showed above were placed at the start of getTargetingGroups; and look to be correct.
So it most likely is getting modified elsewhere, on the decode/actionRoll/etc.
I know that RSW overrides ActionsManager pieces; so I would look closely at those.
Also, note, the handlers are meant to be registered globally; not on demand.
Regards,
JPG
psicodelix
February 28th, 2026, 07:49
Yes, I reduced the example to a minimum to avoid any external interactions.
The fact is that I've tested the same example with version 4.8 of CoreRPG and it works as expected.
The issue is that in version 4.8, only the getTargeting function existed, and CoreRPG always called the TargetingHandler function (see attached screenshot).
In version 5.1, that function has been split into two: getTargetingGroups and getTargeting, and getTargeting is not called when drag-and-drop is used, so the TargetingHandler is not called (see attached screenshot).
I would therefore like to propose that the call to the TargetingHandler function be changed to the getTargetingGroups block, so that, if it exists, it is made in any case.
Regards,
Alberto
Moon Wizard
February 28th, 2026, 17:04
I'm not following the issue; or the use case. Can you walk me through what is trying to be done?
As I mentioned above, drag and drop is working fine for me. (as the value is null when dropped on chat window; and correct when dropped on a token)
Regards,
JPG
psicodelix
March 1st, 2026, 09:12
The problem lies in the call to the TargetingHandler function.
My example defines a TargetingHandler function as follows:
ActionsManager.registerTargetingHandler("btnTestRollAction", manager.onTargeting);
The manager.onTargeting function should always be called when a roll is made, after resolving the targeting, but this is not always the case.
As you can see in the following video, when the roll is made by clicking, the function is called, but when it is made by drag-and-drop, it is not, for the reason I mentioned above.
https://youtu.be/7aiQcxTBLA4
Moon Wizard
March 1st, 2026, 21:50
Just pushed a new version of CoreRPG to address. Please run a new Check for Updates.
Regards,
JPG
psicodelix
March 6th, 2026, 11:23
Ok, its working now, thank you.
Powered by vBulletin® Version 4.2.1 Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.