Enable/Disable behavior

Kiki123987

  • Posts: 29
Hello,

I want to enable a scene behavior called "Kraft" on mouse click into a specific region.
In another Scene behavior I disabled the behavior "Kraft" on creation. Then I created an Actor called "MAUS" which is moved to the location where the mouse button is clicked. That works fine, so does the disabeling.
Now, when i click into the region and the actor MAUS is moved to this region, it should enable the scene behavior "Kraft", but it doesn't? Anyone knows what i am doing wrong?

The screenshots show the scene behavior that disables/should enable the "Kraft"-behavior and creates the mouse

BenjoKazooie

  • Posts: 29
I'm having the same problem. I can disable a behavior, but when I try to re-enable it nothing happens, even from within the same actor. I've tried it with both scene behaviors and actor behaviors.

Does disabling a behavior "deactivate" it like in the editor so that it just gets thrown out of the game?

Nomosoft

  • Posts: 122
I just ran into this issue, and I have an idea where the problem is. If Behavior B disables Behavior A before Behavior A runs its "When created" code, the "When Creating" code does not run when the behavior is re-enabled, and the behavior seems to disappear into the ether. Exactly why, I don't know, but that seems to be the case. I doubt the problem is actually that the "When Creating" code isn't running, more likely it's something _related_ to the "Created" behavior buried in the Stencyl libraries.

Unless I am mistaken, all "Created" behaviors in any given frame run before any "Update" behaviors. I've tested this experimentally and, in fact, I use it to my advantage in many of my behaviors. So, if you disable Behavior A in the first Update loop of Behavior B rather than in the "When Creating" event of Behavior B, you should be good to go, as you can be sure that Behavior A's "When Creating" code (or whatever necessary related code in Stencyl) has run. You can also go the "Do after x seconds" route, but that has always seemed very hacky and imprecise to me.

Edit: Just modified my "Behavior Toggle" behavior to use my solution, and it worked like a charm. Not ideal, but better than setting timers, in my opinion.

Edit 2: Except, it only seems to work when re-enabled from the same behavior that disabled it. Hmm.

Edit the third: OK, anything disabled then enabled BEFORE the scene has finished transitioning is broken. If I force everything to wait until AFTER the scene transition is through, it's fine. I threw some debug prints in, and every one that says "Enabling" _before_ the game reports "FINISHED entering" is lost, everything that comes after "FINISHED entering" enables and works just fine. So, I am slapping a "not (scene is transitioning)" into all the relevant behaviors.

« Last Edit: April 16, 2012, 01:18:01 am by Nomosoft »

BenjoKazooie

  • Posts: 29
Crack detective work, Nomo!

It seems as if the moral of the story here is "Stay away from In-Game Enable/Disable until it is less convoluted". For now I'm just dumping everything from 'when created' into a custom event block and triggering it when I want to "Enable" the behavior. Whatevs.

moltke

  • Posts: 42
Doesn't this mean that this: http://community.stencyl.com/index.php/topic,8205.msg51384.html#msg51384 ...remains a problem in 2.0, only in a slightly less buggy form?