How do I Add together the collected stars in all my levels?

Get help using Construct 2

Post » Mon Aug 01, 2016 8:02 am

Might be simpler to just use the Persist behavior to make sure the stars don't respawn when you change layouts. That way you can just add 1 to your variable every time you collect a star, since you won't be able to recollect them.
B
52
S
24
G
18
Posts: 295
Reputation: 13,090

Post » Mon Aug 01, 2016 8:21 am

Sup with that? wrote:Might be simpler to just use the Persist behavior to make sure the stars don't respawn when you change layouts. That way you can just add 1 to your variable every time you collect a star, since you won't be able to recollect them.


I would have to change the level select screen if I did that, but that could work.
B
24
S
9
Posts: 109
Reputation: 2,002

Post » Tue Aug 02, 2016 1:11 am

https://www.dropbox.com/s/aw4oymi5f419c ... .capx?dl=0

Hmm it got a bit complicated.

Basically - Each star is assigned unique values for its position in the array as instance variables. I used a loop to create the stars and assign values on one layout, you might do it manually as you design your levels.

When it is collected (click), a 1 is recorded in the array at that star's unique position.

Then, the function "CountTotal" goes through and adds up all the values inside the array to get the total number of stars collected, and displays it.

I've added in events to save and load the array and current state of each star via LocalStorage as well, so it is persistant. You can right click to clear all data.
Mistakes were made.
B
52
S
26
G
108
Posts: 1,605
Reputation: 61,131

Post » Tue Aug 02, 2016 2:57 am

oosyrag wrote:https://www.dropbox.com/s/aw4oymi5f419cmx/ArraySave.capx?dl=0

Hmm it got a bit complicated.

Basically - Each star is assigned unique values for its position in the array as instance variables. I used a loop to create the stars and assign values on one layout, you might do it manually as you design your levels.

When it is collected (click), a 1 is recorded in the array at that star's unique position.

Then, the function "CountTotal" goes through and adds up all the values inside the array to get the total number of stars collected, and displays it.

I've added in events to save and load the array and current state of each star via LocalStorage as well, so it is persistant. You can right click to clear all data.


Thanks a bunch! You've really helped me out a lot! :D :D :D
B
24
S
9
Posts: 109
Reputation: 2,002

Post » Tue Aug 02, 2016 3:03 am

Hey oosyrag, I'm having trouble downloading the capx... Dropbox is acting up for whatever reason. -_-
B
24
S
9
Posts: 109
Reputation: 2,002

Post » Tue Aug 02, 2016 3:05 am

I was able to download it... although it is my own dropbox. I'm not sure how to help there.
Mistakes were made.
B
52
S
26
G
108
Posts: 1,605
Reputation: 61,131

Post » Tue Aug 02, 2016 3:40 am

oosyrag wrote:I was able to download it... although it is my own dropbox. I'm not sure how to help there.

I waited a bit and tried again, it worked this time! I'll let you know if I get it working!
B
24
S
9
Posts: 109
Reputation: 2,002

Previous

Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 23 guests