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

Get help using Construct 2

Post » Thu May 29, 2014 6:25 pm

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'.
Last edited by transient on Sat May 31, 2014 1:58 am, edited 1 time in total.
B
9
S
1
Posts: 72
Reputation: 1,391

Post » Thu May 29, 2014 6:42 pm

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?
B
9
S
1
Posts: 72
Reputation: 1,391

Post » Thu May 29, 2014 7:52 pm

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.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Thu May 29, 2014 9:42 pm

Sushin wrote: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.
B
9
S
1
Posts: 72
Reputation: 1,391

Post » Thu May 29, 2014 10:31 pm

transient wrote:
Sushin wrote: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.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Fri May 30, 2014 2:09 am

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 :P)

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.)
B
9
S
1
Posts: 72
Reputation: 1,391

Post » Fri May 30, 2014 2:17 pm

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!
B
9
S
1
Posts: 33
Reputation: 612

Post » Fri May 30, 2014 8:55 pm

@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.
yupenglee.com | @JustOnlyYu
B
14
S
3
Posts: 16
Reputation: 872

Post » Sat May 31, 2014 1:58 am

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
B
9
S
1
Posts: 72
Reputation: 1,391

Post » Sat May 31, 2014 4:35 am

Hey that's a great idea - thanks for sharing!
B
9
S
1
Posts: 33
Reputation: 612

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 10 guests