How do I count # of sprites in all layouts

Just started using Construct 2? Post your questions here

Post » Sun Sep 04, 2016 2:28 pm

Hello. I wonder if the count can count sprites in all layouts AND/OR in layout which player is not at the present.

For example if my game has 100 levels and I´d like to show how many stars to collect in each level. Could the game count those stars in each layout (player can revisit layouts and collect stars the missed first time. Stars have persist behaviour).

I wonder if count function has somekind of way of doing this. I am sure it could be done other ways but it might be too heavy since there are many levels?
B
30
S
15
G
17
Posts: 137
Reputation: 10,873

Post » Sun Sep 04, 2016 3:43 pm

You just use a global variable that starts at 100 for the total. You can use a global variable for each level that has a stars total. When one is collected you subtract 1 from the total and the level total.
B
47
S
18
G
84
Posts: 2,266
Reputation: 49,786

Post » Sun Sep 04, 2016 4:02 pm

plinkie wrote:You just use a global variable that starts at 100 for the total. You can use a global variable for each level that has a stars total. When one is collected you subtract 1 from the total and the level total.


Yes. This is the answer to total number but for each levels... that needs a different solution. Maybe I just leave it if the count function can only count in one layout as there is not stars.count(layoutname) kind of function I suppose.
B
30
S
15
G
17
Posts: 137
Reputation: 10,873

Post » Sun Sep 04, 2016 4:26 pm

"You can use a global variable for each level that has a stars total." You just make a global variable for each level, level1_starcount, level2_starcount. Assuming you know the amount of stars and in what level and they are not procedurally generated or something. You just set level 1 to 5, level 2 to 5, total is 100 etc. Then when you collect a star in level1 you subtract 1 from level1_starcount and the total.
B
47
S
18
G
84
Posts: 2,266
Reputation: 49,786

Post » Sun Sep 04, 2016 5:48 pm

Ok. I guess the answer is that count function only works at the current layout. That solution you gave could be useful. Thanks.
B
30
S
15
G
17
Posts: 137
Reputation: 10,873

Post » Sun Sep 04, 2016 6:32 pm

They are global variables, you can access them any time. Just be sure to 'include' the event sheet that contains them.
B
47
S
18
G
84
Posts: 2,266
Reputation: 49,786

Post » Tue Sep 06, 2016 11:19 am

Just realized that it would make a heavy code since every time player grabs a star the game needs to know at what layout it´s running (on one event sheet).

Maybe array could solve the heaviness.
B
30
S
15
G
17
Posts: 137
Reputation: 10,873

Post » Wed Sep 07, 2016 12:06 am

Then you assign the stars a variable for what level they're in. I'm pretty sure you only need variables here, no reason for an array, unless you want to explain exactly what you're doing.
B
47
S
18
G
84
Posts: 2,266
Reputation: 49,786

Post » Wed Sep 07, 2016 5:15 am

plinkie wrote:Then you assign the stars a variable for what level they're in. I'm pretty sure you only need variables here, no reason for an array, unless you want to explain exactly what you're doing.


That´s actually a very good idea! Thank you again!
B
30
S
15
G
17
Posts: 137
Reputation: 10,873


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests