How do I spawn only 10 sprite

Just started using Construct 2? Post your questions here

Post » Mon Aug 29, 2016 8:28 pm

how do i when system start Create only 10 sprite
B
17
S
7
G
7
Posts: 205
Reputation: 5,335

Post » Mon Aug 29, 2016 8:45 pm

On start (For 1 to 10) > Create sprite. For is the system loop condition with index 1 to 10.
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Mon Aug 29, 2016 9:02 pm

@plinke

and how now i say
For each Sprite set +1 level

so all sprite have L1, L2,L3,L4 Instance variabe (L=level)
B
17
S
7
G
7
Posts: 205
Reputation: 5,335

Post » Mon Aug 29, 2016 10:01 pm

There might be an even simpler way but I would do it by :
On start (For 1 to 10) > Create Sprite, set level to GLOBALVAR

And then separately to set the global variable
On sprite created > Add 1 to GLOBALVAR
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Mon Aug 29, 2016 10:51 pm

Or (For 1 to 10) - Create Sprite, set level to loopindex
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Mon Aug 29, 2016 11:21 pm

B
17
S
7
G
7
Posts: 205
Reputation: 5,335

Post » Mon Aug 29, 2016 11:26 pm

That should be fine, but yeah the loopindex mentioned is the short form I was looking for, try that. Also in what way is it not working? Have you run it in debug to check that the level instance variables are correct?
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Mon Aug 29, 2016 11:41 pm

That will not work. The loop runs in its entirety before continuing to the next event. So all 10 sprites will be created with the same number, THEN the instance variable will increment 10 times.

Try simply adding 1 to level in the loop actions instead of on sprite created.

So

Create object
Set level to level
Add 1 to Level
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Mon Aug 29, 2016 11:48 pm

Yeah within the loop should be fine. The other method should work though because On created is a trigger and just acts when the object is created, ignoring the normal flow.
B
46
S
16
G
73
Posts: 2,084
Reputation: 43,677

Post » Tue Aug 30, 2016 12:13 am

Oops, silly me, you're right.

I did notice when I tried it as shown in the screen shot, the first object created starts at level 2. This is because you have the initial object placed in the editor, which will trigger level to increase to 1 immediately. Then in your loop, you create the first one, which increases the level global variable to 2, then that gets set to the instance variable.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests