Trigger event once for each time it is true.

Get help using Construct 2

Post » Sun Jun 02, 2013 12:49 pm

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.Stiivais2013-06-02 14:35:45
B
10
S
1
Posts: 163
Reputation: 1,436

Post » Sun Jun 02, 2013 1:11 pm

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

Screenshot :

http://docs-share.com/image.php?di=CQUC

TheMax980002013-06-02 13:12:05
B
4
S
1
Posts: 24
Reputation: 390

Post » Sun Jun 02, 2013 1:16 pm

@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.

:)


Blacksmith2013-06-02 13:19:45
B
33
S
6
G
7
Posts: 494
Reputation: 8,252

Post » Sun Jun 02, 2013 1:34 pm

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: https://dl.dropboxusercontent.com/u/80437109/once%20while%20true.capx.

Now i just feel bad for wasting forum space.
B
10
S
1
Posts: 163
Reputation: 1,436

Post » Sun Jun 02, 2013 2:06 pm

@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.

B
33
S
6
G
7
Posts: 494
Reputation: 8,252


Return to How do I....?

Who is online

Users browsing this forum: Phacanu, sean080 and 4 guests