2 Attachment(s)
CombatManager.getTokenFromCT unexpectedly returning nil
As part of the mook support I'm writing for the 13th Age ruleset, I thought it would be cool to be able to double click the mook mob NPC in the combat tracker to reset the image viewpoint to contain all the mooks, and to highlight them. Here is the overridden onDoubleClick function:
Code:
function onDoubleClick(x, y)
GlobalDebug.debugString("Token.onDoubleClick");
local bIsMookMob = (DB.getValue(window.getDatabaseNode(), "ismookmob", 0) ~= 0);
if not bIsMookMob then
return super.onDoubleClick(x, y);
end
local sMookMobPath = window.getDatabaseNode().getPath();
GlobalDebug.debugFormatted("Starting mook mob double click handling for %s", sMookMobPath);
local aTokenContainers = {};
for k,nodeCTMook in pairs(CombatManager.getCombatantNodes()) do
local sNodeMookMobPath = DB.getValue(nodeCTMook, "mookmob", "");
GlobalDebug.debugFormatted("sNodeMookMobPath for %s = %s", nodeCTMook.getPath(), sNodeMookMobPath or "nil");
if sMookMobPath == sNodeMookMobPath then
GlobalDebug.debugFormatted("found a match: node=%s refid=%s", DB.getValue(nodeCTMook, "tokenrefnode", ""), DB.getValue(nodeCTMook, "tokenrefid", ""));
local tokeninstance = CombatManager.getTokenFromCT(nodeCTMook);
if tokenInstance then
GlobalDebug.debugFormatted("Found mook with tokenInstance: id=%d", tokenInstance.getId());
local imageControl = ImageManager.getImageControl(tokenInstance, true);
if imageControl then
local sImageNodePath = imageControl.getDatabaseNode().getPath();
if not aTokenContainers[sImageNodePath] then
local width, height = imageControl.getImageSize();
aTokenContainers[sImageNodePath] = { image = sImageNodePath, xMin = width + 1, xMax = -1, yMin = height + 1, yMax = -1 };
end
local tokenX, tokenY = tokenInstance.getPosition();
aTokenContainers[sImageNodePath].xMin = math.min(aTokenContainers[sImageNodePath].xMin, tokenX);
aTokenContainers[sImageNodePath].xMax = math.max(aTokenContainers[sImageNodePath].xMax, tokenX);
aTokenContainers[sImageNodePath].yMin = math.min(aTokenContainers[sImageNodePath].yMin, tokenY);
aTokenContainers[sImageNodePath].yMax = math.max(aTokenContainers[sImageNodePath].yMax, tokenY);
if tokeninstance.isActivable() then
-- Set this mook active
tokeninstance.setActive(not tokeninstance.isActive());
end
end
end
end
end
-- Set the image view to contain all mooks.
for _,v in pairs(aTokenContainers) do
v.image.setViewpointCenter((v.xMin + v.xMax)/2, (v.yMin + v.yMax)/2);
end
end
And here is the output of the debugging statements in the above function when I try to run it:
Attachment 49289
You can see that it successfully finds the CT node, which has valid tokenrefnode and tokenrefid data. But the next call to CombatManager.getTokenFromCT returns nil and I'm not sure why. Any ideas?
db.xml: Attachment 49291