Turrets do not function correctly after loading state via JSON.

0 favourites
  • 5 posts
From the Asset Store
State Machine
$10.99 USD
State Machine is a great tool for managing the state of anything in your game.
  • I’m having a recent issue involving turret-behavior objects.

    In my game, there’s a saving system that saves the position and the values of their internal variables into a key in a dictionary. During the loading of these objects, the system creates the objects and loads the state via JSON.

    After saving, closing the game, and opening it again, the turrets are loaded but do not work. I’ve tried making them target again, but it didn’t work.

    I realized the problem lies in the action: set from JSON.

    How did I find this out? I created a template to demonstrate how the problem occurs.

    In this template, you can add turrets by simply clicking on the orange area. Once created, the turrets will automatically aim and shoot at the red enemy.

    You can save the position of all turrets by clicking save, and load them after closing the game and reopening it. The game will automatically load the turrets if there is a save.

    The issue I mentioned above also happens in this template. After saving, closing the game, and reopening it, the turrets are loaded and positioned correctly, but they don’t shoot. However, after a few seconds, they start functioning normally, which doesn’t happen in my game.

    Does anyone know what might be happening? Could the 'set from JSON' action take too long to load, and during this loading, it deactivates the turret behavior?

    template:

    drive.google.com/file/d/1YZw0eo2uilxNvL7Mvh8Ikv3w9NqxuR-_/view

  • You probably need a construct dev, this could be different things. Maybe it takes time to find targets or maybe if the target is created before/after the turrets on layout start then it can't target it. Or what data is stored in Turret.AsJSON? maybe targeting data is not saved or is difficult to load. Seems though you are creating a workaround for already existing feature which is system save/load which should work fine.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You're right, the save/load system caused several issues in my mobile game, especially when I modified parts or objects in the layout. Loading would generate various bugs. The alternative I found was to create a system that saves the position and state of all important objects and recreates them in their positions based on the data stored in the dictionary.

    In my game, what I store using AsJSON is for the various object variables. In this template, I didn’t add variables to the Turret object because I didn’t see the need; it was just to test if the action "set from JSON" was causing the delay in the turrets firing.

    So far, the only thing I've really discovered is that this action sort of disables the turret behavior of the object, almost as if it takes some time to load.

    I believe you're right, and maybe only Ashley or another Construct 3 dev knows exactly what’s happening.

  • If you believe there is a problem with Construct please file an issue following all the guidelines - that's our process for sorting out anything that might be working incorrectly.

  • Thank you, Ashley. I'll send the details to you in the bug report.

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