(SOLVED) Weird interaction between "for each" and "trigger once"

0 favourites
  • 11 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • There appears to be something weird going on between "for each" and "trigger once". It appears that I have to say "trigger once" for every instance of an object for it to work when nested under "for each". You can see what I'm talking about in the video below.

    Is this problem caused because I coded this the "wrong" way? Should I just live with this kinda janky solution?

    Subscribe to Construct videos now
  • Hey man! Instead of adding the trigger once event, add the Stop loop action from System, right after your "Audio Stop..."

    Then you can move all your actions inside the Trigger Once event after the Stop loop.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just to further explain what were happening with your code...

    You were telling the program to check for each instance of Sprite_painting if the hangingProgress was higher or equal to 100, and if that condition was met it was executing the Trigger once for that particular instance. Then, when you executes the code a second time the program checks all instances again, BUT this time, because Trigger once was already called the program ignores it and you get an "infinite loop".

  • Hey man! Instead of adding the trigger once event, add the Stop loop action from System, right after your "Audio Stop..."

    Then you can move all your actions inside the Trigger Once event after the Stop loop.

    Thanks for responding. Unfortunately I don't think the "stop loop" did anything.

    Subscribe to Construct videos now
  • Could we see the events above that foreach? Is it nested in another event/condition?

  • Could we see the events above that foreach? Is it nested in another event/condition?

    It's not nested in anything else. Just in a group.

  • Oh... okay, there's the problem. The foreach loop is executing every tick because it is not inside in any triggered event. Although is nested in a group it doesn't mean it will execute your code once. I think the best place to put your code is inside the Mouse click event. It would mean that you'll have to refactor your code a little bit.

  • For example, you could create a function calling your foreach loop. Then call that function in Mouse click event.

    Something like this:

    Mouse On Left button Clicked on Sprite_painting: Call "Your Function"
    	...
    On "Your Function"
    	System For each Sprite_painting: ...
    
  • For example, you could create a function calling your foreach loop. Then call that function in Mouse click event.

    Something like this:

    > Mouse On Left button Clicked on Sprite_painting: Call "Your Function"
    	...
    On "Your Function"
    	System For each Sprite_painting: ...
    

    Having a function execute on the mouse click of a painting does it to all the paintings. The function doesn't know what painting I'm referencing.

    There doesn't appear to be a way around having the for each loop trigger every tick. How is the game suppose to know otherwise if the hangingProcess is >= 100?

  • But that's not the intended behaviour? To check all the paintings and if their hangingProcess is >= 100?

    If you want to check just for the painting that was clicked on, there's no need for the foreach loop.

    I would do something like this:

  • Well shucks. I just tried it and think that fixed everything. Didn't have time to work on the game again until now. I appreciate your help.

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