JSON data types(Sprite frame data type)

0 favourites
  • 4 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • I don’t know if this is a bug or an undocumented change.

    Before r376, if we have a JSON like this:

    	{
    	"animals":[
    	{"animal":"dog", "frame": "1"}
    ]	
    }
    
    

    And then, if we get that value from “frame” with JSON.Get(".frame"), let’s say to set a sprite frame animation, it will treat the “1” as an integer and will set the sprite animation to frame 1, doing a Implicit type conversion.

    But after r376, it only works if we have the “frame” value as an actual integer:

    	{
    	"animals":[
    	{"animal":"dog", "frame": 1}
    ]	
    }
    
    

    This can cause a few bugs if a developer, for some reason started doing as the first example.

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Since r376 you can set animation frames by tag too, it is done by checking the type (set frame by number if number, set by tag if string). So this is intentional I think, but yea I have also seen a lot of people on the Construct Discord getting tripped up by this..

  • Since r376 you can set animation frames by tag too, it is done by checking the type (set frame by number if number, set by tag if string). So this is intentional I think, but yea I have also seen a lot of people on the Construct Discord getting tripped up by this..

    That makes sense. I appreciate the feedback.

  • You're absolutely right! It can be frustrating to encounter such an undocumented change, especially if it breaks existing code. Here's a breakdown of the JSON data type issue for sprite frame data in Construct 3.

    In Construct 3 versions before r376, JSON.Get would implicitly convert string values like "1" to integers when used to set sprite animations.

    After r376, this implicit conversion no longer happens. The data type mismatch can lead to errors if your code relies on the old behavior in NYStateofHealth.

    Using the same JSON data, JSON.Get(".frame") would now return the string "1".

    If your code expects an integer and tries to use "1" directly, it might cause errors.

    I‘m still on r388.2, but it looks like it was “fixed” in r390.

    Release notes:

    “Sprite: for backwards compatibility, 'Set animation frame' now treats numerical strings like "2" as indices instead of tags”

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)