How do I Save object state?

0 favourites
  • 6 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.
  • Hello, can anyone help me in the situation below.

    how can i save the status of an object and when it loads the game it is no longer there? such as

    The player takes a coin and, this coin is destroyed, he saves the game and exits, when it comes back in the phase of that coin is no longer because it was already taken.

    already used or behavor persist but I can not save this status where the currency was already taken.

    someone help?

  • Have you tried using savegames?

  • savegame doesn't work for me, I'm using localstorage

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Then you'll have to manually store what coins were taken and destroy them on start of layout. You could save the X and Y of the coin when it's taken in an array with array.push that you then save to local storage with array.asjson

    When the game is loaded you load the data back into the array and loop through the stored coordinates with pick nearest coin > destroy

  • savegame doesn't work for me, I'm using localstorage

    Why don't savegames work? They should do exactly what you want.

  • Just guessing now but I also personally never use savegames. I always end up using localstorage.

    (Correct me if I'm wrong) The thing with savegames are that they save absolutely everything. It's a complete snapshot of the current game state, like a savestate in an emulator. This can work but sometimes you don't want that. I'd argue that you almost never want that.

    Lets say I have a game where I collect coins. When I die the game over screen shows and that's when I want to save them. But if I make a savestate there I will always load into the game over screen instead of ending up in the menu screen. Not to mention that you actually need to save a single number and you save an entire snapshot unless you manually exclude every single sprite/object. Also iirc you can't save variable A but not B so when you load, both A and B will be loaded but you don't want to load B because it's not something you want saved. Something you can work around... but you'll have to work around

    It's a bit of an all or nothing solution and lacks some granularity imo. Sure will work in some cases, but I also get reminded about all the times I tried to savescum in a game and made a savestate that loaded me right into the deathpit :P

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