Add behaviour at runtime

  • 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.

  • 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.

  • I've added 'enable/disable persist behavior' to the todo list.

  • Glad to hear it!

    Any clue about release date?

    Anyway, thanks!

  • 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.

  • neutrinox you can use Webstorage to save data, and then load it up on start of layout.

  • 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?

  • neutrinox Not really. Engine don't know if you are resetting layout or coming back from different one - that's for persist behavior is.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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!

  • 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" ?

  • shinkan

    Can you give me a example of a game in which persist behavior would be useful? Can this game get restarted after game over? Then what do you do with the persist behavior (if you cant reset it)?

    My point is this:

    If you can't reset persist behaviors, then it's useless for any game that need the option to be restarted (which is 100% of every video game I have ever played).

  • I understand your point. And I know that game after restart should look the same every time. I'm just saying that C2 don't know if You want to restart game or go back to previous layout - that's why You need to specify that.

    And like I in my first post it's doable using webstorage for example.

  • Hi!

    I get that Construct 2 doesn't know if we are restarting or going back to a layout. That's exactly why it would be so important to be able to tell construct to reset persist behaviors. That feature would make persistent behavior so much more useful.

  • Storing object as JSON in arrays and/or dictionaries is nice because you can get at the data whenever you want, and do with it whatever you want.

    That being said, the persist behavior is straight forward and easy. Enable/disable sounds like a good idea.

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