-
April 27th, 2021, 21:57 #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 10Last edited by bmos; May 4th, 2021 at 15:44.
bmos' extensions
he/them
-
April 27th, 2021, 22:04 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,559
Can you spit out the info locally to see if it's because of the OOB?
JPG
-
April 28th, 2021, 00:56 #3
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
Last edited by bmos; April 28th, 2021 at 12:38.
bmos' extensions
he/them
-
May 3rd, 2021, 18:16 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,559
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
-
May 3rd, 2021, 22:44 #5bmos' extensions
he/them
-
May 3rd, 2021, 23:59 #6
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,559
That would be great. I wouldn't be surprised with some variability of event timing/positioning with networking; so let me know.
Regards,
JPG
-
May 11th, 2021, 12:54 #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, pfrpgbmos' extensions
he/them
-
May 11th, 2021, 15:52 #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)Last edited by bmos; May 12th, 2021 at 02:51.
bmos' extensions
he/them
-
May 12th, 2021, 22:48 #9
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,559
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
-
May 12th, 2021, 23:03 #10
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,559
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