[r154] For Each and Trigger Once

0 favourites
  • 11 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • Link to .capx file (required!):

    dl.dropboxusercontent.com/u/73774002/foreach-triggeronce.capx

    Steps to reproduce:

    1. Hit any key

    2. Hit any key again

    Observed result:

    First instance behaves properly, triggers once.

    Second instance does not.

    Expected result:

    All instances should trigger once.

    Operating system & service pack: Win7x64sp1

    Construct 2 version:r154

    =====

    With how it's setup, it should trigger once per instance that is TRUE. It only triggers once for the first instance that is TRUE, but every tick for the rest of the instances.

    If you remove the For-Each, it functions as expected.

    =====

    I'm currently using For Each along with Trigger Once because I need it to trigger once per object that has the boolean, and half of the code breaks if I remove the for-each, and the other half breaks with the for-each.

  • Thndr - interesting, it does appear that the Trigger Once is not 'remembering' that it was previously triggered. However, I believe that the For each Text that you have is not required because of how C2 events are designed. If you substitute a 2 condition event (essentially your sub-event) in place of the for loop:

    Text - Is Variable 1

    System - Trigger once

    and use the above to append the text.number then the events work as you intend. I'm only commenting because it took me ages to understand how the event system is designed to work and I don't think you should use the 'For each' loop for a condition check like this - it just slows things down.

    Having said all of that, I have no idea why the condition check as you have it should only work on text 0 and not the others...

    Ed.

  • Closing as won't fix - 'trigger once' really does not make any sense in a loop, so I'm not sure what you're expecting it to do. 'Trigger once' more accurately means 'run this tick if did not run last tick'.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got around it by using functions and disabling previous boolean after it has ran so it only triggered once. instead of every tick.

    Ashley Well even if it's supposed to be "Run this tick if it did not run last tick", it does that but only for the first instance. The instances other than the first go "Run every tick", ignoring the trigger once.

    Understandable if it's an issue not worth fixing as it's a bug that happens with crappy code.

    Colludium

    It's an obscure problem and I was doing quick code when I came across it. There are better ways to do it (as what I already have done), but it just looked broken due to that without the "For Each Text", the events runs for each Text and function as expected.

    When you have a 2 condition event like that running every tick, it's implying the "For Each" in it's picking (as far as I know). I wanted to pick 1 object and run a group of events for that specific object for every instance of that object. Without the For-Each it was breaking as when I trying to select other objects linked to it, it affected many things I did not want.

    Using UID and functions I segmented the code, and forced picking by UID through the function instead of picking by Current Instance in For-Each loop. Still using a For-each for the first part, but since it's for-each I just grab the UID and have it run the function when I have it set to turn off the boolean as an action rather than looking to see if the boolean was just turned off.

  • Well, perhaps I meant to define it in terms of what it does: it makes events that are true for several ticks only run on the first tick they're true. I don't think it's clear what it ought to do when in a subevent to a loop, since the definition of "true for several ticks" no longer really makes any sense. So I'm happy to leave it doing whatever it happens to do with the current implementation.

  • Well, perhaps I meant to define it in terms of what it does: it makes events that are true for several ticks only run on the first tick they're true. I don't think it's clear what it ought to do when in a subevent to a loop, since the definition of "true for several ticks" no longer really makes any sense. So I'm happy to leave it doing whatever it happens to do with the current implementation.Well for a "For Each" loop wouldn't it be based on instance where if it did that action last tick for that specific instance instead of checking if that part of the loop ran at all? Unless I'm misunderstanding the implied For-Each in the code if you removed the loop condition.

    If so then I'll have to be more careful with those loops and have learned my lesson on what they don't do. (Sometimes I add them to make sure something runs for every instance)

  • No - 'trigger once' ignores instances completely, because it's a system condition.

  • No - 'trigger once' ignores instances completely, because it's a system condition.Ah, okay then.

    Although wouldn't it still track the instances of the previous picked conditions?

  • Ashley

    Thndr

    Guys please help!

    for the past 2 days i am trying to figure out what is going on until i stumbled on this thread.

    i have 3 instances of a scml animation(spriter).it is in a container with a sprite box background and i run it every tick on top of it.

    i have a LOS (line of sight ) behavior on my sprite box

    if "sprite box" has LOS on player----set scml animation to "walk"

    if "sprite box" has NOT LOS on player----set scml animation to "IDLE"

    if i use this, then the animation gets stuck on the first frame (no tweening no nothing)because i think it runs every tick so it resets 60 times per second.

    if i add a sub-event "trigger once while true" it works(the animation) up to the moment it switches between LOS and NOT LOS and the reason is in what Ashley said that it is a system condition and does not pick instances!so only one instance switches between idle and walk and the rest stay on the previously played animation (wish i knew that 2 days ago :p)

    so any ideas on what to do to solve this?

  • Roccinio

    instead of doing a for_each then triggering once via condition, you do for_each and have an instance variable you check

    If the variable is true to do what you want it to do and then at the end of that you set the variable to another value

    Most likely you'll just use 1 and 0 for TRUE and FALSE.

    This way it goes through, and triggers only if it's TRUE, then immediately set to FALSE after triggering. You set the variable to TRUE next time you want it to trigger for that instance.

    Basically it's the manual way of "Trigger Once", since when it's true, you set it to false the first time it runs so it doesn't run again next tick.

    The closed bug forum isn't really a good place to get support, but at least you searched the forums :)

  • Thndr

    hi friend!

    take a look here

    scirra.com/forum/trigger-once-and-instances_topic86899.html

    and let me know

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