Starfinder Playlist
  1. #1

    Tokeninstance.isVisible returns false when token is selected

    I discovered some strange behavior when working on an extension of mine, and I don't know if this is a bug or not. In my extension players can create a power action that targets all tokens within a certain radius around them. Naturally I check to see if a token is visible before targeting it, however it was discovered that when a token is selected and line of sight is enabled on a map, tokeninstance.isVisible() returns false, even if the token is otherwise visible. If the token is not selected, isVisible() returns true as expected.

    Here's the code I've got, with the relevant section bolded.
    Code:
    function targetAllWithinDistance(node, nDistance, sFaction, bIgnoreVisible)
    	local finaltargets = {};
    
    	local nodeCT = CombatManager.getCTFromNode(node);
    
    	if nodeCT then
    		local tokenCT = CombatManager.getTokenFromCT(nodeCT);
    		if tokenCT then
    			local targets = Token.getTokensWithinDistance(tokenCT, nDistance);
    
    			for index,token in ipairs(targets) do
    				local targetCT = CombatManager.getCTFromToken(token);
    
    				if sFaction == "all" or ActorManager.getFaction(targetCT) == sFaction then
    					local rTarget = ActorManager.resolveActor(targetCT);
    					local bIsVisible = token.isVisible();
    					Debug.chat(rTarget.sName .. " is visible?", token.isVisible());
    					if bIgnoreVisible or bIsVisible then
    						table.insert(finaltargets, targetCT);
    					end
    				end
    			end
    		end
    	end
    
    	if #finaltargets > 0 then
    		for _, targetCT in ipairs(finaltargets) do
    			TargetingManager.addCTTarget(nodeCT, targetCT);
    		end
    	end
    end
    Here is the questionable behavior with line of sight enabled on the map. You can see the debug statement in chat show that when a token is selected, isVisible is returning false for that token, but returning true if the token is not selected.

    And for reference, here is the extension working as expected when line of sight is disabled. The debug statements show that isVisible is true regardless of if the token is selected.

    I've attached the campaign zip and extension I'm using for the above examples for any further testing.

    Is this expected behavior? If it is, what should I be doing to test for token visibility that doesn't have this behavior?
    Attached Files Attached Files
    Last edited by Saagael; May 3rd, 2022 at 18:29.

  2. #2
    Thanks for reporting.

    I did find a couple minor bugs in the tokeninstance.isVisible code that I'll get patched for the v4.2.0 release. (selected token didn't see itself; host skipped some tokens when no tokens selected)

    However, I will caution you when using the tokeninstance.isVisible API in this way, since the isVisible check is the instantaneous check on whether the token is currently visible based on the current token selection. (i.e. whether any selected token can see it) So, if you want to use in this way; you might have to make sure that the token selection is updated to the PC executing the action before the isVisible check. (i.e. clearSelectedTokens, selectToken)

    Regards,
    JPG

  3. #3
    Quote Originally Posted by Moon Wizard View Post
    Thanks for reporting.

    I did find a couple minor bugs in the tokeninstance.isVisible code that I'll get patched for the v4.2.0 release. (selected token didn't see itself; host skipped some tokens when no tokens selected)

    However, I will caution you when using the tokeninstance.isVisible API in this way, since the isVisible check is the instantaneous check on whether the token is currently visible based on the current token selection. (i.e. whether any selected token can see it) So, if you want to use in this way; you might have to make sure that the token selection is updated to the PC executing the action before the isVisible check. (i.e. clearSelectedTokens, selectToken)

    Regards,
    JPG
    Thanks for the information. Is there a function somewhere that will select a token on a map? I didn't see anything in the Token library, in the tokeninstance class, or in TokenManager in CoreRPG.

    EDIT: I figured it out. Functions were hidden in places I didn't think to look (ImageManager and the imagecontrol object)
    Last edited by Saagael; May 8th, 2022 at 01:15.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in