How do I trigger once per instance on boolean switch?

  • Hi all,

    I'm probably being quite dense about this but I can't figure out a simple solution for this problem:

    I have multiple instances of a sprite that has a boolean instance variable. On the boolean for a particular instance being switched on, that instance should perform an action.

    This doesn't work:

    sprite.boolean is On, trigger once | do action[/code:23qjfngw]
    
    It triggers the first time the boolean is on for any sprite and then that's it.  Nor does this work:
    
    [code:23qjfngw]For each sprite, sprite.boolean is On, trigger once | do action[/code:23qjfngw]
    
    I get why that these don't work, based upon how the picking system and trigger once functions. I know that I could work around this by using a number variable instead of boolean and using something like:
    
    [code:23qjfngw]On start sprite.no = 0;
    If sprite.no = 1|do action; sprite.no = 2;[/code:23qjfngw]
    
    ...but I'd like to try and preserve the use of the boolean if possible.
    
    Any ideas?
  • Maybe I understand it wrong, but why do you set the boolean to false after the action is done and set it back to true if you want to do the action again?

    System | For each sprite 
             sprite.boolean is On ->  | do action
                                        sprite.boolean=false
    [/code:t1ot89o9]
  • Asmodean That would work in some circumstances, but you may have situations where the boolean state needs to remain e.g. I only want sprites with the boolean On to react to a subsequent event.

  • I believe it's not possible with just one boolean instance variable and nothing else.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000 That's a pity. Ah well, at least I'm not being a complete idiot about it!

  • I guess you could add a second boolean and do:

    If sprite.boolean1 and !sprite.boolean2 | do action; set sprite.boolean2 true;[/code:3ge5743s]
    
    ...but if I'm going to do that I might as well use the number variable technique I mentioned above.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)