FG Spreadshirt Swag
Page 1 of 2 12 Last
  1. #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 first bit of weird is that whenever the new token is created it is automatically scaled down by a factor of 1.414. At first I thought this was because some other handler was detecting a new token and applying a scale to it. But this happens when I turn off the game option to automatically scale tokens. It happens when I override TokenManager.autoTokenScale so it does nothing. I even opened up CoreRPG, commented out TokenManager.autoTokenScale, and yet the created tokens still get scaled down. I have no idea what's doing this scaling, but it feels like it shouldn't be happening.

    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

  2. #2
    LordEntrails's Avatar
    Join Date
    May 2015
    Location
    -7 UTC
    Posts
    17,094
    Blog Entries
    9
    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.

  3. #3
    You might also want to look at the token's container scale (token.getContainerScale()).

  4. #4
    Quote Originally Posted by DCrumb View Post
    You might also want to look at the token's container scale (token.getContainerScale()).
    I tried messing with that, mixing that with the token scale in various combinations but it didn't seem to do anything different.

  5. #5
    I just re did my tests with getContainerScale and I either mis-remembered or something changed, because now getContainerScale() is returning nil.

  6. #6
    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,
    JPG

  7. #7
    Quote Originally Posted by Moon Wizard View Post
    getContainerScale/setContainerScale was deprecated in FGU (as FGU handles sizing between tokens and layers differently).
    It's good to know that I don't need to worry about this piece.

    Quote Originally Posted by Moon Wizard View Post
    getScale/setScale are supposed to work in grid-relative scale in FGU. (i.e. 1.0 = 1x1 grid size)
    This was my assumption, so thanks for confirming.

    Quote Originally Posted by Moon Wizard View Post
    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.
    I'll see if I can put together a simpler example this week. Thanks for looking into it.

  8. #8
    Quote Originally Posted by Moon Wizard View Post
    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.
    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.
    Attached Files Attached Files

  9. #9
    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,
    JPG

  10. #10
    This should be fixed in the beta version currently in the Test channel.

    Regards,
    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
  •  
Starfinder Playlist

Log in

Log in