-
February 10th, 2023, 15:43 #1
Strange Behavior When Scaling Tokens Via Script
In an extension I'm working on I'm trying to implement behavior wherein a user double-clicks on a token, and that token toggles between two different tokens images. To do this, I'm trying to create a brand new token with the same scaling and orientation as the original, then delete the original so that I'm left with the new token. However! I'm encounter two different (but possibly related) issues that might be bugs. They might also be me doing something wrong, but they definitely feel like bugs. Also, this is all the LIVE branch.
Attached to this post is a gif of the two issues on display. Below is the function I'm using to create do the work, with the relevant part in the middle bolded. Lastly, these tokens are not mapped to actors on the CT so I can't use the ct entry's space property to resize.
Code:function flipCardOnTable(token, image, cardnode, sIdentity) _bFlipping = true; -- First update the node backing the token CardsManager.flipCardFacing(cardnode, sIdentity, {}) local sNewToken = CardsManager.getCardFacingImage(cardnode); local x, y = token.getPosition(); local newToken = Token.addToken(DB.getPath(token.getContainerNode()), sNewToken, x, y); local nScale = token.getScale(); newToken.setScale(nScale) Debug.chat('old scale: ' .. nScale) Debug.chat('new scale: ' .. newToken.getScale()) newToken.setOrientation(token.getOrientation()); CardTable.updateTokenName(cardnode, newToken); token.delete(); CardTable.setCardTokenId(cardnode, newToken.getId()); _bFlipping = false; end
The attached gif is me double-clicking on a token consecutively to 'flip' between a card being face and face down on an image. Every time the new token comes in, it's smaller than the original.
This is where the second bit of weird comes in. In the script you can see I've put two Debug statements to display the old token's scale as well as the new token's scale. When I create the new token, the new scale is always set to 1, no matter what the old token's scale is set at. In the gif you can see this. Every time the new token comes in, getScale() reports that its scale is 1, but the old token's scale is correctly reported at whatever it actually was. This makes me think that something in setScale() isn't hooked up quite correctly, but I can't say for sure.
WeirdTokenScalingIssue.gif
-
February 10th, 2023, 19:44 #2
Mod: Moved to Workshop since that is usually the best place to discuss coding and custom extensions/ruleset issues.
Problems? See; How to Report Issues, Bugs & Problems
On Licensing & Distributing Community Content
Community Contributions: Gemstones, 5E Quick Ref Decal, Adventure Module Creation, Dungeon Trinkets, Balance Disturbed, Dungeon Room Descriptions
Note, I am not a SmiteWorks employee or representative, I'm just a user like you.
-
February 11th, 2023, 05:27 #3
You might also want to look at the token's container scale (token.getContainerScale()).
-
February 11th, 2023, 05:28 #4
-
February 11th, 2023, 16:20 #5
I just re did my tests with getContainerScale and I either mis-remembered or something changed, because now getContainerScale() is returning nil.
-
February 19th, 2023, 01:38 #6
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,282
I was just starting to look at this, because we're in the middle of a beta and I haven't looked at this section of the code in a very long time. One thing to remember is that several of the APIs changed between FGC and FGU. Based on this thread, I did a quick review of the "tokeninstance" API documentation, and made sure to clean it up.
A couple things that have changed relevant to this discussion:
* getContainerScale/setContainerScale was deprecated in FGU (as FGU handles sizing between tokens and layers differently).
* getScale/setScale are supposed to work in grid-relative scale in FGU. (i.e. 1.0 = 1x1 grid size)
My theory is either that the getScale/setScale are not working; or there are other triggers that are resizing the token as well (such as auto-scale option). I am fairly sure that setScale is working correctly, as it is used by the auto-token-scale option. (i.e. Space 1 in CoreRPG -> 1 scale (or 0.8 if 80% auto-scale option); Space 5 in 5E -> 1 scale (or 0.8)).
So, I'd need an example extension of where this is not working (simpler the extension, the less time it will take me to investigate), so I can look at it deeper to see how exactly you are using the APIs and what might be interacting with them.
Regards,
JPGFG Wish List - https://fgapp.idea.informer.com/
-
February 19th, 2023, 01:57 #7
-
February 19th, 2023, 03:09 #8
It was easier than I thought to put something together. I've attached a zip file that has a campaign and an extension. The campaign has a single image with a single token. If you double-click that token the extension will will flip between two tokens; the same as in the gif I shared. You can keep double-clicking to see this behavior. The extension has a single global script with two functions. There's a handful of comments in there to hopefully lend a little bit of context if needed.
Another new piece of weirdness that I discovered:
When I reloaded FG, the token was always scaled back to 1, no matter what it was at before. I don't recall if this happened in my original testing or not, but I did notice it here.
-
February 19th, 2023, 04:51 #9
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,282
Thanks, I'll try to take a look later this weekend.
The scaling back to 1 is because the auto-scaling currently triggers on every reload of the campaign; and if token is not linked to CT, then the auto-scale defaults to size 1. This has been modified in the Test/beta version to not auto-scale on reload.
Regards,
JPGFG Wish List - https://fgapp.idea.informer.com/
-
February 22nd, 2023, 16:36 #10
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,282
This should be fixed in the beta version currently in the Test channel.
Regards,
JPGFG Wish List - https://fgapp.idea.informer.com/
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks