inconsistent results using state machine

0 favourites
  • 5 posts
From the Asset Store
State Machine
$10.99 USD
State Machine is a great tool for managing the state of anything in your game.
  • So for some reason, I'm really struggling with state machines in C3, specifically relating to when there are more than one instance working in a layout. I have a typical example below which, to my eyes, should work.

    Basically, each enemy has an 'enemyState' variable (which is assigned at the family level). This particular enemy is idle until having LoS to player, at which point they move to 1. During state 1, enemy flies around and starts counting down to release a burst attack. Once the burst attack is over, enemy goes back to state 1 and flies around a bit more.

    Should work fine. And it does, until a second bat instance enters state 1. At this point, the bats will move between states but not run any lines that are inside the 'trigger once' blocks. In the past, I had my set animation lines in there until realising that they weren't being activated unless I moved them out.

    Logically, I can't see why this works when there is one instance in play, but breaks as soon as a second one enters. Surely the condition is selecting the correct instance that is triggering the state machine? I thought that maybe I needed a 'for each' block in there, but that made no difference whatsoever, whether I put the 'for' block in each state condition, or make one parent 'for' block and have all the state conditions to be sub-events of it, makes no difference.

    So either I'm missing something very obvious or I don't know what. But I'd love a bit of help on this one just to stop me making similar mistakes in the future.

    Cheers

  • In typical fashion, I found an effective work around to this as soon as I posted all of that ^. However, it still doesn't answer my question regarding the 'trigger once' block.

    If I take all the stuff from the trigger once blocks and move the to the state that is triggering the change of condition (so exactly how I'm handling the animation changes) then it all works as intended.

    But like I said, why would those trigger once blocks not register if there is more than one instance on the screen?

    ...

    Is it because the 'trigger once' has no other condition in the same block? Surely not?

  • Never ever use "Trigger once" condition when multiple instances are involved! It doesn't work per instance, as long as one enemy has state=1, this condition will not be triggered for other enemies. If I had to name one thing in Construct that causes most problems and bugs when used incorrectly, it would be "Trigger once" condition :)

    Instead, add more states, for example: got LoS, set state=1; started timer, set state=2; started burst, set state=3 etc.

    But personally I don't like state machine events that are running on every tick. I prefer to do this with functions and "For each" loops, you have a much better control over it:

    "For each" are important, because LoS and Timer may be triggered in one tick for multiple enemy instances.

  • Add a boolean instance variable within the iceBat.

    Replace "Trigger once" with checking if that instance variable is false.

    In the actions of the "Trigger once" event add an action to set the value of this instance variable to true.

    Make sure to set the value to false when changing state for example.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okay, thanks guys. I'm not sure why, but I find managing state machines in C3 to be so much more confusing than in other languages. Maybe it's related to the event sheet system, I don't know. Anyway, think I've got it all sorted now, guess once you know what the problem is, you can start looking for a better solution.

    Cheers

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