Add behaviour at runtime

Get help using Construct 2

Post » Thu Jun 06, 2013 11:13 am

I need to enable/disable the Persist behaviour at runtime because some instances must be persistible depending upon conditions, so the current implementation of the Persist behaviours falls short.
I've tried to create a custom behaviour with no luck, surely because the logic that triggers the real Persist actions is hidden inside Construct2 code, so the Persist behaviour is merely a flag to trigger it.

We've spent many weeks developing a quite big game and we have recently purchased the license of construct, but we're really stuck with this...
Do the Construct2 team has any prevision on implementing this shortly?

Is there any way to add/remove the Persist behaviour at runtime?

Is there any plugin outthere that allow adding a behaviour to a concrete instance, not just to the prototype?


Thanks in advance to whoever brings light on this.
B
3
Posts: 2
Reputation: 229

Post » Thu Jun 06, 2013 11:28 am

The global question, "add behavior at runtime", has a simple answer : no, at least impossible right now with C2. In most case, behavior can be enabled/disabled, but not in your particular case.
I see only 2 ways of doing this, both requiring maybe quite some implementation, depending on your project/project size.
The first one would be to use families, and have 2 objects in it : one with the persist behavior, the other without it. You could replace all the occurence of your pseudo-persisting object by the family in the events, and you would have to "transfer" the datas from the persisting object to the non-persisting one (or the other way) when you want to change the persist behavior.
The second one would be to use the load system. Every object that is savable has a "toJSON" function, letting you store your object in a string. There is also a "loadFromJSON" function. So you would have to remove the "persist" behavior, and save/load at each start/end of layout, depending if you want the object to persist or not.

I would personally try to use the second options that seems more... implementable whatever the project.
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Thu Jun 06, 2013 1:51 pm

I've added 'enable/disable persist behavior' to the todo list.
Scirra Founder
B
383
S
224
G
86
Posts: 24,106
Reputation: 190,410

Post » Mon Jun 10, 2013 11:06 am

Glad to hear it!

Any clue about release date?


Anyway, thanks!
B
3
Posts: 2
Reputation: 229

Post » Sat Feb 15, 2014 9:07 pm

This would be a very important feature to have!

I'm using persist behavior to remember collected items inside levels. The problem is, there doesn't seem to be any smart way of restarting the game so that everything resets. Having to manually place all the level items after a game over kind of defeats the purpose of the persist behavior.
B
9
S
1
Posts: 97
Reputation: 715

Post » Sat Feb 15, 2014 9:10 pm

@neutrinox you can use Webstorage to save data, and then load it up on start of layout.
ImageImageImageImage
B
156
S
64
G
41
Posts: 2,588
Reputation: 34,601

Post » Sat Feb 15, 2014 9:14 pm

@shinkan Yes but doesn't that kind of defeat the purpose of persist behavior? It would be such an easy way to remember stuff, IF ONLY there was a way to reset it when needed. If you can't reset persist behavior, then how can you handle game over situations?
B
9
S
1
Posts: 97
Reputation: 715

Post » Sat Feb 15, 2014 9:28 pm

@neutrinox Not really. Engine don't know if you are resetting layout or coming back from different one - that's for persist behavior is.
ImageImageImageImage
B
156
S
64
G
41
Posts: 2,588
Reputation: 34,601

Post » Sat Feb 15, 2014 9:37 pm

@shinkan
Yes but the whole purpose of persist behavior is to let you avoid manually placing items and characters in your layout when re-entering it.

Now if you give your player the option to restart the game (which every game should of course do) then you still need manual placement of items and characters. So you can only really use persist behavior if you don't need to make restarting the game possible. I'm hoping for someone to prove me wrong!neutrinox2014-02-15 21:39:51
B
9
S
1
Posts: 97
Reputation: 715

Post » Sat Feb 15, 2014 9:52 pm

@neutrinox Yeah, thats true. Persist behavior was made with reentering layouts in mind. But like I said. Reentering layout and restarting layout is one and same thing.

What do you mean by "you still need manual placement of items and characters" ?
ImageImageImageImage
B
156
S
64
G
41
Posts: 2,588
Reputation: 34,601

Next

Return to How do I....?

Who is online

Users browsing this forum: ankas, Baidu [Spider], iBarin, whitephon, WhosWho and 15 guests