Check for number of items?

Get help using Construct 2

Post » Sat Jul 14, 2012 10:04 pm

Hi, I have a game inwhich the player has to collect stars (original I know) but I can't figure a way to check if all the stars on the layout have been picked up before allowing them to continue.

I have a block that's in the way of the exit, once all stars are gone the block moves. I've tried checking if the star sprite IS ON LAYER (and inverted) but it doesn't work.

I have 2 layouts using the same event sheet, is it because the stars on the other layout are still there or should the event react on the layout that's currently playing?

Cheers.

http://dl.dropbox.com/u/74633005/plat.capxvandinz2012-07-14 22:05:24
B
19
S
5
G
4
Posts: 208
Reputation: 3,960

Post » Sat Jul 14, 2012 10:18 pm

Try sprite.count.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Jul 14, 2012 10:56 pm

How are you starting your layout? Are you created the sprites at layout in the event sheet. Or have you created and placed your sprites manually in the layout editor?

A basic fix is to have a global/instance variable. If you create sprites at the start of layout, then add one to that value per sprites. Alterntively if your sprites are already place before the start of layout. You could instead use "for each" and add 1 to the value of the variable.

Then when your player collects the sprites, subtract 1 from the value per sprite.

When the variable = 0 then all the sprites have been collected, the door move etc....
B
85
S
31
G
14
Posts: 106
Reputation: 16,440

Post » Sun Jul 15, 2012 6:52 am

I have this in my project, but I added 1 each time something is collected, then told system to look for the specific number of items. Same thing, essentially.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Tue Jul 17, 2012 5:11 pm

Thanks all. I've tidied it up a lot and found out I can include one event sheet in another so now I've put all the major things in one sheet and each level has it's own variable / stats for the number of stars. I'm adding them manually in design time and want to keep it that way because I'm thinking of adding hidden stars etc, so it'll be easier for me to impliment. Still learning with Construct but getting there.

Cheers.
B
19
S
5
G
4
Posts: 208
Reputation: 3,960


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, jul and 22 guests