Need help with adding all collected stars together!

Get help using Construct 2

Post » Fri Sep 02, 2016 10:43 pm

Okay. I have no idea what the issue is at this point, but this is what's been going on, and it's bonkers.

I have an array called StarCountArray for the stars. At first, I had it set up so that after you get a star, it would set the XY value of the star from 0 to 1, then it would add the total to a Global variable called Totalstars using a Function called AddStars.

So like this:

On Function "AddStars" ---------------Set Totalstars to 0
subevent -For Each XY element ---------------- Add StarCountArray.CurValue to Totalstars

It worked like a charm, but I realized that if you got a star, then left the stage to the level select, it would still count up the total amount of stars collected, which isn't what I want.

So I tried something else.

Keeping the same function, I made 3 new global variables:

CountUp1
CountUp2
CountUp3

After you pick up a star, depending on which one you picked up, it would change the value of the corresponding variable to 1.

Then I made an event for when you reach the goal.

After you reach the goal, I have a For Each loop that sets the StarCountArray value of each star in the layout to it's corresponding CountUp variable.

I know it sets the right values because I made 3 Sprite Text objects to keep track of it, setting their values to the StarCountArray values, and every value became 1 when you reached the end of the level.

In the same For Each loop, after it does the action mentioned above, it does the AddStars Function to add the stars to the Totalstars variable.

Sounds like it should work then, right? Well... No. No it doesn't. The value of Totalstars becomes 1. ALWAYS. even after I clear another level and get all of the stars on that one. The value of Totalstars stays at 1 no matter what, but only after I clear the first level. I've looked over it several times to find errors. I couldn't find anything wrong. It doesn't make any sense.

If you read my essay of a topic, I thank you. If you think that you know what the issue is, or you think that there's something else I could try, then PLEASE tell me. I will be eternally grateful! :mrgreen:
B
24
S
9
Posts: 113
Reputation: 2,012

Post » Fri Sep 02, 2016 10:57 pm

Do you have an example capx by any chance? :shock: I tried to make one from scratch, then figured it would be easier if you'd supply a simplified example capx file.
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Fri Sep 02, 2016 11:26 pm

Gmoney wrote:Do you have an example capx by any chance? :shock: I tried to make one from scratch, then figured it would be easier if you'd supply a simplified example capx file.


It may take a bit, but I can make one.
B
24
S
9
Posts: 113
Reputation: 2,012

Post » Sat Sep 03, 2016 12:03 am

Gmoney wrote:Do you have an example capx by any chance? :shock: I tried to make one from scratch, then figured it would be easier if you'd supply a simplified example capx file.


Here's how it was before: https://www.dropbox.com/s/lfgmt1x6jvmt4 ... .capx?dl=0

And Here's how it was after I changed it: https://www.dropbox.com/s/kg46pa7qari2b ... .capx?dl=0
B
24
S
9
Posts: 113
Reputation: 2,012

Post » Sat Sep 03, 2016 12:49 am

Thank you for the capx update, Aquanex2.

I've looked into the issue and found the 'after' example is not adding any stars to the StarCountArray.

Before
Image

After
Image

Meaning there's no link between 'CountUp1/2/3' variables and 'AddStars' after the change.

I have one more question for you.

Why would you need an array to store number of stars collected?

I think we can take an easier path and store the numbers directly to the variable.

Here's an example capx I made to demonstrate.

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

This is what would happen when I'd go to the 'Level Select' screen without clearing the score.

1. Collect a star.
2. Click [Go to level select without clearing score].
3. Click [Go back].
4. Score is still 1.

This is what would happen when I'd go to the 'Level Select' screen after clearing the score.

1. Collect a star.
2. Click [Go to level select after clearing score].
3. Click [Go back].
4. Score is 0.

Function and array are a superb way of organizing the overall code, but I tend to avoid them because they could be more troublesome to troubleshoot once things start to get tangle up along the way.
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Sat Sep 03, 2016 1:10 am

Gmoney wrote:Thank you for the capx update, Aquanex2.

I've looked into the issue and found the 'after' example is not adding any stars to the StarCountArray.

Before
Image

After
Image

Meaning there's no link between 'CountUp1/2/3' variables and 'AddStars' after the change.

I have one more question for you.

Why would you need an array to store number of stars collected?

I think we can take an easier path and store the numbers directly to the variable.

Here's an example capx I made to demonstrate.

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

This is what would happen when I'd go to the 'Level Select' screen without clearing the score.

1. Collect a star.
2. Click [Go to level select without clearing score].
3. Click [Go back].
4. Score is still 1.

This is what would happen when I'd go to the 'Level Select' screen after clearing the score.

1. Collect a star.
2. Click [Go to level select after clearing score].
3. Click [Go back].
4. Score is 0.

Function and array are a superb way of organizing the overall code, but I tend to avoid them because they could be more troublesome to troubleshoot once things start to get tangle up along the way.


I can't use the capx because I'm using version 233. It's the most recent stable beta.
But I see what you are saying.

The reason I used an array is because of something someone else showed me, and it seemed to work.
B
24
S
9
Posts: 113
Reputation: 2,012

Post » Sat Sep 03, 2016 1:12 am

Did you clear the level once you got all the stars?
B
24
S
9
Posts: 113
Reputation: 2,012

Post » Sat Sep 03, 2016 2:30 am

From my example or from the 'after' version? :mrgreen:

I did, for all three capx files.

I collected all the stars, but the level didn't clear, so I had to jump to the goal in order to restart the level.

My example had reset the stars to 0 after I reached the goal, just like the 'before' version.

There was no change for the 'after' version though.. The stars were not collected and the level just restarted after I jumped into the goal.
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Sat Sep 03, 2016 2:45 am

Gmoney wrote:From my example or from the 'after' version? :mrgreen:

I did, for all three capx files.

I collected all the stars, but the level didn't clear, so I had to jump to the goal in order to restart the level.

My example had reset the stars to 0 after I reached the goal, just like the 'before' version.

There was no change for the 'after' version though.. The stars were not collected and the level just restarted after I jumped into the goal.

The way that I wanted to do it is to add the stars to the total stars after you got the stars and beat the level.
B
24
S
9
Posts: 113
Reputation: 2,012

Post » Sat Sep 03, 2016 3:43 am

You mean like this one? :mrgreen:

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

Game complete scenario

1. Added 2 more stars.
2. When all 5 stars are collected, the level clears.
3. Player is taken to the 'Complete' layout.
4. The message shows 'Collected all 5 stars! You have finished the first level..!! Click to reload the level..!!'
5. When clicked, the player is taken back to the first level with 0 total stars.

Game incomplete scenario

1. When player collects less than 5 stars and jumps into the goal, the player is shown a message that says 'Please collect all 5 stars. Restarting.'
2. The game restarts with 0 total stars.
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Next

Return to How do I....?

Who is online

Users browsing this forum: max2612 and 23 guests