Call a function multiple times in a row.. possible?

Get help using Construct 2

Post » Sat Aug 13, 2016 10:07 am

Hi all,

searched the forums, did some testing but I might be overlooking something.

I want to call a function a bunch of times in a row, I sense it's not the way to go, but I don't know any better at the moment.

Instead of copy pasting with 'wait x seconds' between them, is it possible to have a function run an x amount of times in a row with waits between them?

Thanks. Regards R
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Sat Aug 13, 2016 10:11 am

You can use System > repeat X times for that :)

Just place that on the event and you can choose how many times you want it to execute


From the manual:

Loops
Loops can be stopped with the Stop Loop system action.

For
Repeat the event a number of times, using an index variable over a range of values. The index can be retrieved with the LoopIndex system expression and passing the name of the loop.

For Each
For Each (ordered)
Repeat the event once per picked instance. This only repeats for instances that have been picked by prior conditions. See how events work for more information on picking. For Each is commonly mis-used or used redundantly - actions already apply for each instance picked by conditions, so it often is simply not needed. However, if you fully understand how the event system works, it can be used to force the event to apply once per instance where the event system would not normally do that. The 'ordered' variant allows the order that the instances are iterated in to be defined by an expression. For example, ordering by Sprite.Y ascending will iterate the top instances on the screen first, moving downwards.

Repeat
Simply repeat the event a given number of times. This tests any conditions following it on every repeat, and if those conditions are met also runs the actions and any sub-events on every repeat.

While
Repeat the event until one of the other conditions in the event becomes false or a Stop loop action is used. Be careful not to create infinite loops which will cause the game to hang.
B
54
S
23
G
13
Posts: 751
Reputation: 12,418

Post » Sat Aug 13, 2016 10:24 am

Anonnymitet, you missed the waiting part. ;)

Image
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat Aug 13, 2016 11:15 am

Or if you dont want to wait x seconds but you think function may colide with each othet you can use wait for signal.
B
22
S
3
Posts: 74
Reputation: 1,515

Post » Sat Aug 13, 2016 7:39 pm

Thanks guys!

What does 'loopindex' do exactly though? I want an object to spawn (drop) bombs, but have the bombs dropped shortly after each other.

Now it seems like the bombs are dropped exactly 1 second after each other. I want to decrease that time, I tried changing loopindex+1 to loopindex+0.2 for example but that doesn't change anything. I'm confused.

Thanks. - R
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Sat Aug 13, 2016 7:55 pm

Multiply: loopindex*0.2
ImageImageImage
B
71
S
21
G
233
Posts: 3,696
Reputation: 130,368

Post » Sat Aug 13, 2016 8:35 pm

Thanks, blackhornet. Did the trick.
B
13
S
7
G
4
Posts: 143
Reputation: 3,581

Post » Sat Aug 13, 2016 9:04 pm

Rudi55 wrote:What does 'loopindex' do exactly though?

Loopindex is well, the loop index.
If you're in the third iteration of a loop, loopindex will be equal to 3.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sun Aug 14, 2016 7:45 pm

Coin-coin le Canapin wrote:
Rudi55 wrote:What does 'loopindex' do exactly though?

Loopindex is well, the loop index.
If you're in the third iteration of a loop, loopindex will be equal to 3.


It would actually be 2 since loop indices are 0-based :)
B
46
S
14
G
7
Posts: 603
Reputation: 8,116


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests