How do I reset persistent objects on game over? (Solved!)

0 favourites
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • So, I love that there is a persist feature and it's come in quite handy for an object in my game (bonuses you can pick up scattered through the levels.) The problem i'm running into is, I want the bonuses to remain persistent while the game is going but on game over when the game restarts I need the objects to re-appear. Is there a way to reset the state of a persistent object and thereby restore all the bonuses on game over? If not, I'd love to see an option within objects with the persist behaviour like 'Reset State'.

  • ok well, i guess i didn't search enough. i found this https://www.scirra.com/forum/how-do-i-reset-a-game_t98072 thread which brings up the same issue. and it appears there is no solution currently?? seems like a bit of an oversight if you ask me?

  • Really..?

    Well, off the top of my head, I guess you could make a bunch of values for objects you want to reset and set them on creation of the object, and when you want them reset, revert to those values. Set an original X and Y value for instance, and when you reset, just place it at those coordinates.

  • Really..?

    Well, off the top of my head, I guess you could make a bunch of values for objects you want to reset and set them on creation of the object, and when you want them reset, revert to those values. Set an original X and Y value for instance, and when you reset, just place it at those coordinates.

    hey sushin, thanks for the suggestion. i'm certainly hoping i don't have to go through all that as i've scattered quite a few of these bonuses throughout the world. i can only imagine the time it would take to implement a system like your describing. i'd much prefer a solution to the problem as i feel the behavior is flawed in it's current state, but i suppose if it comes to that i'll have to bite the bullet and dig in

    thanks again for the reply.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > Really..?

    > Well, off the top of my head, I guess you could make a bunch of values for objects you want to reset and set them on creation of the object, and when you want them reset, revert to those values. Set an original X and Y value for instance, and when you reset, just place it at those coordinates.

    >

    hey sushin, thanks for the suggestion. i'm certainly hoping i don't have to go through all that as i've scattered quite a few of these bonuses throughout the world. i can only imagine the time it would take to implement a system like your describing. i'd much prefer a solution to the problem as i feel the behavior is flawed in it's current state, but i suppose if it comes to that i'll have to bite the bullet and dig in

    thanks again for the reply.

    It should be rather easy if you simply put all the objects in a family and give the family the initialization variables and events.

  • hmm yeah, i'm still very much a noob at this whole thing. i think i kind of understand but i'm not exactly sure how i would implement it. i was very excited when i found the persist behavior because i thought it solved the issue of people being able to endlessly consume the bonuses (thus making the leaderboards a joke) but this was before i had implemented a game over into the equation and wasn't really anything i had prepared for. i just assumed there would be either a way to reset the persist or barring that a way to simply reset the entire game (which isn't preferable since the user would have to redo the tutorial and that would get annoying on try 3 or 4 )

    the bonus object is simply one object so it wouldn't even require a family. but it is dragged out of the objects and placed in many different places across multiple layouts. now if i understand you correctly i could add an instance variable to each of the instances, i'm still not sure how i would set an original x and y value, that's not something i've encountered before. i'll try and find some tutorials. construct 2 is a never ending learning experience (that's why i love it.)

    but again, i'd love to see the persist behavior expanded a bit to allow for a much simpler solution (and judging from that other thread i found it looks like others would benefit from the change as well.)

  • Yeah, I thought I'd give my powerup objects the boolean instance variable (named "used"). When the player tags a powerup it is destroyed and the boolean is tripped (used = true). When a layout loads, if the object's "used" variable is true, destroy that instance of the object.

    It works, but I'm running into the same problem of not being able to restore those objects on a game over. Even if I set their boolean values back to "used=false".

    Would love to hear of a way to reset persistent object's instance variables!

  • transient Dunno if this is the answer you're looking for, but have you tried activating/deactivating by groups? In one of my game projects, I have a group with events that are about spawning objects continuously. Upon pause or game over, that group is 'deactivated' so that the spawning events don't trigger. Then on resume or restart, that group is 'activated' so that the spawning events trigger normally.

  • Hey guys, thanks for the suggestions. I spent all day today trying to think of a way to do this and came up with a super simple solution that works!

    On the beginning of the first layout I want to 'reset' to I added a 'On start of layout>System>Save' to a slot called 'Reset' (which will only trigger the first run) Then at game over simply Load the save slot reset and your golden! All the persistent objects restore themselves back to the initial save! So much easier than trying to program them individually WOOHOO hehe

  • Hey that's a great idea - thanks for sharing!

  • transient

    On Start Of Layout - System - Set TimeScale to 1

    The the default for the game. so what ever you add to that Layout should restart to it beginning.

    I hope this helps.

    I'm gonna try your way too to see which I like better

    Thanks

  • thank you this solved my issue too

  • Nice thought! This solution worket like a charm here, thank you!

  • Hey guys, thanks for the suggestions. I spent all day today trying to think of a way to do this and came up with a super simple solution that works!

    On the beginning of the first layout I want to 'reset' to I added a 'On start of layout>System>Save' to a slot called 'Reset' (which will only trigger the first run) Then at game over simply Load the save slot reset and your golden! All the persistent objects restore themselves back to the initial save! So much easier than trying to program them individually WOOHOO hehe

    Thanks you saved my a lot of headache! Even if before find this old tread I bashed my head on the code for a while

  • I was having a similar difficulty. I wanted enemies to respawn at a level's checkpoint but not collectables like coins. Here's my solution for anyone interested:

    When the an enemy is killed instead of destroying the instance, do

    instance_deactivate_object(this_enemy);

    I have it inside of an enemy state "DEATH" which does a few more things like the death animation etc.

    Then when the player dies I have him reappear at the checkpoint coordinates and do:

    instance_activate_all();

    And all the enemies respawn and my collectables are gone.

    You can switch on separate layers as well. Another situation I ran into was I wanted to be able to go into another room that is actually part of the current level I'm in and still have the items be gone. All I had to do was change the persistence of the room using,

    room_set_persistent( ind, val );

    I make all rooms persistent within a level until level exit is reached at which point all rooms in the level become non-persistent. That way I can have a multiple rooms connected to each other to form a level without having to have a million objects.

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