[SOLVED] How do I create 10 objects using a loop?

Get help using Construct 2

Post » Sun May 29, 2016 11:30 pm

Message: PixelLab can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
SOLVED HERE: viewtopic.php?f=178&t=176897&p=1043772#p1043772

----------------

I'm trying to create 10 objects using the Repeat loop. I have tried many different things, like

this:
Image

and this (the Cooldown variable is set to 1): Image

but it just keeps creating a seemingly infinite amount like this: Image


I'm getting a bit frustrated, and any advice would help.
Last edited by PixelLab on Mon May 30, 2016 2:03 pm, edited 1 time in total.
B
8
Posts: 24
Reputation: 345

Post » Sun May 29, 2016 11:39 pm

The system is triggering your loop every step
you need a trigger
ex:
system>on start of layout
.........>repeat 10 times............>system create sprite on layer 1 at(floor(random(100,500),100)
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sun May 29, 2016 11:43 pm

I tried this:
Image

and it did not work. Am I misunderstanding what you mean by "trigger"? Either way, thanks for the tip.

---

EDIT: I see what you mean. I added a "Trigger once" to the first condition, and now the only problem is that the balls are all created at the same time. I'll try moving around the wait condition. Thank you for the help!
B
8
Posts: 24
Reputation: 345

Post » Mon May 30, 2016 12:13 pm

What granpa says is this: you can only run this once. At the moment it runs every tick.

The events (roughtly) run top down. When it comes to the end, it starts again at the top. One time top down = 1 tick.
So, your creation block runs once, the system starts again on top, it runs again (making more objects), it runs again and again and again, in fact it never stops.

One way to make that event run only once is to make an 'on start of layout condition' (under system) and bring whole that creation blok as a subevent under that 'on start of layout'.

An other way is to make a 'Trigger once while true" condition. And bring whole that creation blok as a subevent under that.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon May 30, 2016 12:57 pm

As grandpa and 99Instances2Go said, your event (Repeat 10 times: create obj) runs every tick, that's about 60 times per second, making an unlimited amount of objects.
I recommend you doing this:

System|On start of layout
(Right click, add another condition or key C)
System|Repeat 10 times
-> Create obj
B
32
S
7
G
4
Posts: 398
Reputation: 4,591

Post » Mon May 30, 2016 1:40 pm

I really appreciate the advice, but I don't want these to spawn at the start of the layout. I want to create enemies in waves, and so some waves will come after others.

So, here is a method that works:
Image
When the conditions are met, create a ball, wait, create, wait, repeat.

So now, I try replacing that SAME SPOT with "repeat", because that is what I want to repeat:
Image

And it does not work. Note that I DO use "trigger once". The problem is that it is not waiting. It creates the objects all at once; instead of actually completing the loop 10 times, it seems to want to do each step 10 times before moving on to the next:
Image


Can anyone tell me how to create things in waves without having to make a huge block of copy pasted commands like the first image in this post? Getting a bit frustrated.
B
8
Posts: 24
Reputation: 345

Post » Mon May 30, 2016 2:12 pm

PixelLab wrote:And it does not work. Note that I DO use "trigger once". The problem is that it is not waiting. It creates the objects all at once; instead of actually completing the loop 10 times, it seems to want to do each step 10 times before moving on to the next:

Can anyone tell me how to create things in waves without having to make a huge block of copy pasted commands like the first image in this post? Getting a bit frustrated.

I'm wondering this, too. It seems like the Repeat loop executes the actions (10) times in a row, without going down (waiting).
B
32
S
7
G
4
Posts: 398
Reputation: 4,591

Post » Mon May 30, 2016 2:14 pm

Create a Every X seconds condition. Set X to you liking.
Bring the creation blok as a sub under that condition. So:

Condition every x seconds
Sub condition repeat 10 times
Action create the objects.

Or, use a timer. Give any object a timer behaviour.

Condition:
Trigger once while true
Action
'any object' > start timer > X seconds > tag "wave"

New condition
On timer "wave"
repeat 10 times
action
create the objects.

If you only want to create 1 object each time, lose the repeat.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, gskunk, richcoz81, zenox98 and 57 guests