DICE PACKS BUNDLE
Page 1 of 2 12 Last
  1. #1

    Issue with getTokensWithinDistance

    When I run Token.getDistanceBetween on a client tied to a onMove function in a token, I get a different number then when I run it as host.
    It seems on player computers the onMove function is occurring based on the original location rather than the new location.

    EDIT: I should also add that I am using onMove to send OOB to run the command on the host so it could be a timing issue.
    EDIT2: the title of this thread is wrong, it's about getDistanceBetween not getTokensWithinDistance

    4.0.10
    Windows 10
    Last edited by bmos; May 4th, 2021 at 15:44.

  2. #2
    Can you spit out the info locally to see if it's because of the OOB?

    JPG

  3. #3
    Quote Originally Posted by Moon Wizard View Post
    Can you spit out the info locally to see if it's because of the OOB?

    JPG
    It's not the OOB situation.
    This code still has the issue:
    Code:
    local onMove = nil;
    local function auraOnMove(tokenMap)
    	--Debug.chat("in auraOnMove");
    	if onMove then
    		onMove(tokenMap);
    	end
    	checkRange(DB.findNode('combattracker.list.id-00003'), DB.findNode('combattracker.list.id-00001'));
    
    	--Debug.chat("finishing aura on move");
    end
    
    local updateAttributesFromToken = nil;
    function auraUpdateAttributesFromToken(tokenMap)
    	--Debug.chat("in auraUpdateAttributesFromToken");
    	if updateAttributesFromToken then
    		updateAttributesFromToken(tokenMap);
    	end
    
    	onMove = tokenMap.onMove;
    	tokenMap.onMove = auraOnMove;
    end
    
    local function checkRange(nodeSource, nodeTarget)
    	local sourceToken = CombatManager.getTokenFromCT(nodeSource);
    	local targetToken = CombatManager.getTokenFromCT(nodeTarget);
    	if not sourceToken or not targetToken then
    		return false;
    	end;
    
    	Debug.chat(Token.getDistanceBetween(sourceToken, targetToken))
    end
    
    function onInit()
    	updateAttributesFromToken = TokenManager.updateAttributesFromToken;
    	TokenManager.updateAttributesFromToken = auraUpdateAttributesFromToken;
    end
    I have trimmed my extension down to a test extension and attached it and my campaign here so you can reproduce easily:
    Attached Files Attached Files
    Last edited by bmos; April 28th, 2021 at 12:38.

  4. #4
    I'm testing this on v4.0.10 and v4.1; and I'm seeing the same information being printed on both GM and player clients. I'm loading up the GM and player client; connecting as "george" character; then using arrow keys to move george token up and down one square on both GM and player.

    I'm getting the same information on both player and client. I also added a Debug.chat with the token position to see if that was different, but they were the same too.

    Maybe I'm following different steps than you are?

    Thanks,
    JPG

  5. #5
    Quote Originally Posted by Moon Wizard View Post
    I'm testing this on v4.0.10 and v4.1; and I'm seeing the same information being printed on both GM and player clients. I'm loading up the GM and player client; connecting as "george" character; then using arrow keys to move george token up and down one square on both GM and player.

    I'm getting the same information on both player and client. I also added a Debug.chat with the token position to see if that was different, but they were the same too.

    Maybe I'm following different steps than you are?

    Thanks,
    JPG
    That's so strange... it's now working for me as well...
    Sorry to waste your time. I'll post here again if it happens again and I can reproduce it consistently.

  6. #6
    That would be great. I wouldn't be surprised with some variability of event timing/positioning with networking; so let me know.

    Regards,
    JPG

  7. #7
    It looks like I was wrong about the OOB issue.
    It is because of that. I will recreate the test ext to demonstrate this soon.

    occurs in at least 5e, 4e, pfrpg

  8. #8
    Here is a test campaign and ext to demonstrate the issue I'm running into with OOB timing.
    If it's working as intended, perhaps someone has a suggestion to get the same value for host and client?

    Steps to reproduce:
    1. open campaign with ext loaded
    2. open second instance connected to localhost
    3. claim a character and move that character's token using the client instance (token locking disabled)
    4. observe that chat messages show distance based on original square (before movement) which doesn't match the targeting distance
    5. move same player on host instance
    6. observe that chat messages show distance based on destination square (after each half step) matching targeting distance

    EDIT: occurs on both live and test branch (with latest updates as of 9:50pm EST May 11)
    Attached Files Attached Files
    Last edited by bmos; May 12th, 2021 at 02:51.

  9. #9
    Script events are generally called before the network updates go out, so we don't double dip on network updates when data is changed. So, the problem that you're running into is that your OOB message is being sent prior to the token movement network update is sent. Also, the network messages are processed in order, which means that your OOB message is processed before the network update.

    I did notice that the "onMove" event in FGC fires on network token movement as well as UI token movement; while FGU only fires on UI token movement. I'm looking into whether that is something we can enable without breaking anything else; but I'm not sure at this point.

    Regards,
    JPG

  10. #10
    Also, I noticed that you are assigning a new handler every time that a token attribute is updated. You should only be adding handlers directly to a token in a Token.onAdd event; or just capturing Token.onMove directly. I'm not sure if your extension is adding potentially tens to hundreds of handler instances or not.

    JPG

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
  •  
STAR TREK 2d20

Log in

Log in