0 Favourites

Trigger event once for each time it is true.

  • First off, i have little to no prior experience in programming (it starts only next year for my school course), so i am not exactly familiar with the logics of programming (so i would like you to explain the concepts as simple as possible).

    The problem: Let's imagine the following scenario - i have a time based system for my application/game, where a variable is increased by 1 every second up until it hits 10, then it is brought back to 0, creating a looping clock or something similar.

    Let's say, that i want to have an object spawned for every time the variable is 5.

    If i put a simple "while true" condition, then the object will be spawned every tick for the duration of the second, which is likely to spawn way more objects, than i need. If i add a "trigger once while true" condition, then the object will be spawned only for the first iteration, meaning, that the second time the clock hits 5, nothing will happen.

    //Mistake here: i misinterpreted the "trigger once while true" condition, however i made an example at the bottom of this page.

    Is there an efficient way, to trigger an action to execute only once per occurrence of the conditions being true? (that doesn't require creation of extra variables, local variable or such?)

    What i have tried (inneficient method):

    1.) Creating a variable "is triggered" and putting "is 1?" in the conditions for my event.

    2.) Putting "set to 0" in the actions of my event.

    3.) Somehow resetting the variable to 1 after conditions are no longer true.

  • Simply use "System" --> "Trigger once while true" condition.

    Screenshot :

    docs-share.com/image.php

  • Stiivais,

    The 'Trigger once while true' condition should work for you.

    If you are already using a variable to count from 0-10, you could try setting up an event which states:

    • 'Your variable' = 5 && Trigger once while true

    -> Spawn your object

    This way every time your variable goes through it's count (0-10), and hits 5 it should trigger!

    Note: Trigger once while true, only means that it will trigger the condition once, every time it is true.

    :)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Hmm, not sure what i was doing wrong prior to this, but upon trying to make an example it indeed seems to be working. >_<

    Go figure...

    Here is the example i made: dl.dropboxusercontent.com/u/80437109/once%20while%20true.capx.

    Now i just feel bad for wasting forum space.

  • Stiivais,

    Glad you've got it working now! Don't worry it takes a while to become familiar with some of this stuff, I'm sure you'll be up and running in no time.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
220 14,883
Tom's avatar
Tom Construct Team Founder
Unread hot topic
234 61,226
DARKSETH's avatar
DARKSETH
Unread hot topic
0 Favourites
Time to move forward?
110 9,561
GG-Works's avatar
GG-Works