celestian
April 20th, 2020, 07:41
I am attempting to have have the default token selection be the one that has "active" initiative if there is a pile of tokens.
I've setup Token.onClickDown = onClickDownADND; and that code is something alone these lines.
function onClickDownADND( target, button, image )
-- if host and not pressing control (targeting)
if not Input.isControlPressed() then
-- click left mouse on token
if button == 1 then
local ctwnd = nil;
local windowPath = nil
if User.isHost() then
ctwnd = Interface.findWindow("combattracker_host", "combattracker");
if ctwnd then windowPath = ctwnd.combatants.subwindow.list; end;
else
ctwnd = Interface.findWindow("combattracker_client", "combattracker");
if ctwnd then windowPath = ctwnd.list; end;
end
if ctwnd then
local nodeCT = CombatManager.getCTFromToken(target);
if nodeCT then
--
Debug.console("manager_token_adnd.lua","onClickDownADND","target",target);
for _, oToken in pairs(image.getTokens()) do
-- otoken is in a pile with selected token/target
if oToken.getPosition() == target.getPosition() then
Debug.console("manager_token_adnd.lua","onClickDownADND","oToken",oToken);
local nodeCT = CombatManager.getCTFromToken(oToken);
if nodeCT then
Debug.console("manager_token_adnd.lua","onClickDownADND","nodeCT",nodeCT);
local bActive = (DB.getValue(nodeCT, "active", 0) == 1);
Debug.console("manager_token_adnd.lua","onClickDownADND","bActive",bActive);
if bActive then
Debug.console("manager_token_adnd.lua","onClickDownADND","image.getSelectedTokens()",image.getSelectedTokens());
image.clearSelectedTokens();
image.selectToken(oToken, true);
Debug.console("manager_token_adnd.lua","onClickDownADND","image.getSelectedTokens()",image.getSelectedTokens());
return true;
end
end
end
end
--
end -- nodeCT entry didn't exist for token on map
end
end
end
end
When I use the above code the debug shows me the image.getSelectedTokens() is always the same, never removes "target" as selected and uses the selectToken(oToken,true).
What is the proper process to unselected/select a "selected" token programmatically ?
I've setup Token.onClickDown = onClickDownADND; and that code is something alone these lines.
function onClickDownADND( target, button, image )
-- if host and not pressing control (targeting)
if not Input.isControlPressed() then
-- click left mouse on token
if button == 1 then
local ctwnd = nil;
local windowPath = nil
if User.isHost() then
ctwnd = Interface.findWindow("combattracker_host", "combattracker");
if ctwnd then windowPath = ctwnd.combatants.subwindow.list; end;
else
ctwnd = Interface.findWindow("combattracker_client", "combattracker");
if ctwnd then windowPath = ctwnd.list; end;
end
if ctwnd then
local nodeCT = CombatManager.getCTFromToken(target);
if nodeCT then
--
Debug.console("manager_token_adnd.lua","onClickDownADND","target",target);
for _, oToken in pairs(image.getTokens()) do
-- otoken is in a pile with selected token/target
if oToken.getPosition() == target.getPosition() then
Debug.console("manager_token_adnd.lua","onClickDownADND","oToken",oToken);
local nodeCT = CombatManager.getCTFromToken(oToken);
if nodeCT then
Debug.console("manager_token_adnd.lua","onClickDownADND","nodeCT",nodeCT);
local bActive = (DB.getValue(nodeCT, "active", 0) == 1);
Debug.console("manager_token_adnd.lua","onClickDownADND","bActive",bActive);
if bActive then
Debug.console("manager_token_adnd.lua","onClickDownADND","image.getSelectedTokens()",image.getSelectedTokens());
image.clearSelectedTokens();
image.selectToken(oToken, true);
Debug.console("manager_token_adnd.lua","onClickDownADND","image.getSelectedTokens()",image.getSelectedTokens());
return true;
end
end
end
end
--
end -- nodeCT entry didn't exist for token on map
end
end
end
end
When I use the above code the debug shows me the image.getSelectedTokens() is always the same, never removes "target" as selected and uses the selectToken(oToken,true).
What is the proper process to unselected/select a "selected" token programmatically ?