bladedpenguin's Recent Forum Activity

  • The original Z indices may not be valid, but thier order may be. You can sort them and then either Move to Top or Move to Bottom, which should recreate the original order, albeit in an inefficient way.

  • Under Application Properties, change Sampling to Point.

  • You can use linear interpolation functions to change the player's size based on thier X. Have a read up on lerp in the manual.

    Player.Width = lerp(30, 5, Player.X/PyramidX)

    Player.Height = lerp(30, 5, Player.X/PyramidX)

    You can also affect the jump height and walking speed with the same function, to add to the illusion.

  • If I understand Persist correctly, it only keeps things on the same layout. I want to take things to a different layout, like Global, but only for specific instances. This would also give me the freedom to lock items away as a string for a while.

  • Awesome! at first glance, this is really close to what I want to do!

  • Problem Description

    JSON strings created with Sprite.asJSON

    Attach a Capx

    Yes

    Description of Capx

    The demo allows you to create sprites with C. You can manipulate them by clicking, and destroy them by right clicking. Press S on a sprite to save it, then press L on another sprite to give it the same position, color, and instance variables as the first sprite. Click the button to change layout.

    Steps to Reproduce Bug

    • Press C to create a sprite
    • Click on the sprite to change it's instance variables
    • Press S on the sprite to save it as a JSON string.
    • Click the button to change layouts
    • Press C to create a new sprite
    • Press L on sprite to load JSON data into sprite
    • ???
    • Sprite is Gone?

    Observed Result

    Sprite Disappears instead of loading from JSON

    Expected Result

    I expect the sprite to take the same position, color, and instance variables that it has on the layout where it was saved.

    Affected Browsers

    • Chrome: (YES)
    • FireFox: (YES)
    • Internet Explorer: (YES)

    Operating System and Service Pack

    Windows 7 SP1

    Construct 2 Version ID

    r199 + r200

  • I've updated my demo so it clearly shows what is going on. You can press C to create a new sprite, and you can click on it to update it's state. You can hover over a sprite and hit S to save it's state, and then L to load. Loading works just fine if you don't switch layouts, and when a sprite gets Set From JSON, it moves to the correct spot and gets it's color and variables set correctly. If you switch layouts though, the sprite is destroyed when you try to load it.

  • I create a sprite on layout1, then save a JSON snapshot of it. When I move to layout2, I create a new sprite and when I try to apply the JSON snapshot, the new sprite is destroyed. It works fine if I don't switch layouts.

  • If there is lots of bouncing etc, you might look into the physics behavior, but that has the potential to add lots of additional complexity.

  • Thanks! I was able to resolve the issue with the JSON being "". Have a look at that demo I posted: it has the same issue as my main game.

  • I'm working on a behavior that is able to save Objects and restore them later on. I figured out how to save the object's sid and look it up later to get the object type for creating it, but when I try to "set from JSON" on a new layer, the object gets destroyed. I am reading the JSON that I get from asJSON, and it looks like the issue might be related to the layer SID that is stored.

    I was wondering if there is a way to call the asJSON Expression from the SDK, and then later restore it in a way analogous to the "set from JSON" Action?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I was looking through the source hoping that perhaps the layer SID was causing the problem, but that doesn't seem to be the case. Can I partially set from JSON? If I remove a few elements from the JSON, can I still load from JSON and keep the other values as they are when the Item is created? I also noticed that the issue is independant of whether layouts are changed.

    Should I give up and go to some kind of abstract Inventory system? I'm hesitant to do that, since Construct 2 doesn't really handle abstract objects very well: You can't put them in data structures. It seems much more complicated to hang custom events on an array inventory....

    Edit: here is the JSON, after the "l" element was removed.

    {"c2":true,"ivs":{"4983201361434822":"2d12"},"w":{"x":40,"y":214.20833333333331,"w":24,"h":24,"zi":16},"behs":{"2355029582157182":{"SlotUID":611},"3459439661079695":{"enabled":true},"8791895563351892":{"dx":0,"dy":0,"cancelStep":0,"enabled":true,"stepMode":0,"pxPerStep":5}},"data":{"a":9827539049161972,"f":12,"cas":0,"fs":0,"ar":0,"at":0}}[/code:3991b27o]
    
    More Edit: Using firebug, I was able to catch [code:3991b27o]SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
    http://localhost:50000/commonace.js
    Line 609[/code:3991b27o] I'm going to look into why this instance is being passed an empty string. I've attached a screenie of the test event I created. I'd be inclined to leave a capx, but I am using a bunch of 3rd party behaviors.
    
    In this screenshot, Save Item and Create Instance are both functions from a little custom behavior I made which is able to save the object type of an unknown sprite, and respawn it from sid. It seems to work correctly. If I remove the Set From JSON line, it seems to properly creates a MeleeWeapon or FryingPan or Boots or whatever. I can upload that behavior if someone is interested.
    
    Edit: caught a major derp in the above screenshot. ItemJSON is now properly set to Item.asJSON, and everything works, at least in this test case without changing layouts. This is the same as my test case. I notice that it does NOT work if I strip out the layer sid, so that must be important somehow. It's also the only data in that JSON that seems like it might be mismatched.  Should I create a JSON mangler to replace the layer sid with the sid of the new "UI" layer?
    
    To confirm: I have my main project behaving the same way as this demo, which is able to save and restore sprites from JSON, but it just destroys the sprite whenever I try to SetFromJSON on a different layout from the one where the JSON was created. Help!
bladedpenguin's avatar

bladedpenguin

Member since 5 Feb, 2015

None one is following bladedpenguin yet!

Trophy Case

  • 9-Year Club
  • Email Verified

Progress

10/44
How to earn trophies