Need help with adding all collected stars together!

0 favourites
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • 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!

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

  • Do you have an example capx by any chance? 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.

  • Do you have an example capx by any chance? <img src="{SMILIES_PATH}/icon_eek.gif" alt=":shock:" title="Shocked"> 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

    After

    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.

  • 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

    After

    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.

  • Did you clear the level once you got all the stars?

  • From my example or from the 'after' version?

    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.

  • From my example or from the 'after' version?

    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.

  • You mean like this one? <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

    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.

  • Ops, my apologies, Aquanex2.

    I missed your reply that said you couldn't open my files because they were version 234, because I've only read the latest reply. (Sorry..!!) <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    I have modified the files so that it can be opened in version 233 of Construct 2.

    GMoney - star counter - v233.capx is the file from earlier today.

    GMoney - star counter v2 - v233.capx is the file from my last reply.

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

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

    Please download the latest version of Construct 2 from the following page. <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

    https://www.scirra.com/construct2/releases

  • You mean like this one? <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

    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.

    I see what you did, but The object of my game is not to get the stars. It's just a simple platformer, and the stars are just extra. If you missed a star I wanted you to be able to replay the levels until you get them all, while showing you your total amount of stars on the level select.

  • I have added the following features.

    1. Added a 'Level Select' button.

    - When pressed, a Level Select screen will pop up to show how many stars are remaining.

    - When discarded, the game will continue just the way you left it, right before entering the Level Select screen.

    2. Added a feature to allow the Player who hasn't finished the level to restart without having to reset the number of stars remaining in game.

    - Previously, when the Player reached the goal without collecting all the stars required to finish the level, the number status of the stars had automatically reset.

    - What happens now is this. If the Player hasn't collected all the required stars, the Player will restart from the beginning of the level. The Player will notice only the remaining number of stars are in game and the ones s/he collected have disappeared.

    By the way, I have downgraded my Construct 2 version to 233, because other people who I helped on the forum advised they were also using 233..

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

  • I have added the following features.

    1. Added a 'Level Select' button.

    - When pressed, a Level Select screen will pop up to show how many stars are remaining.

    - When discarded, the game will continue just the way you left it, right before entering the Level Select screen.

    2. Added a feature to allow the Player who hasn't finished the level to restart without having to reset the number of stars remaining in game.

    - Previously, when the Player reached the goal without collecting all the stars required to finish the level, the number status of the stars had automatically reset.

    - What happens now is this. If the Player hasn't collected all the required stars, the Player will restart from the beginning of the level. The Player will notice only the remaining number of stars are in game and the ones s/he collected have disappeared.

    By the way, I have downgraded my Construct 2 version to 233, because other people who I helped on the forum advised they were also using 233..

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

    I want the Totalstars variable to add together all of the stars from all the levels. How would I do that while keeping the same code?

  • 1. Make a global variable Totalstarscollected = 0.

    2. When Level 1 ends, add a system Event to add TotalStars variable's number to Totalstarscollected.

    3. When Level 2 starts, reset TotalStars variable.

    4. When Level 2 ends, add a system Event to add TotalStars variable's number to Totalstarscollected.

    5. When level 3 starts, reset TotalStars variable and so on.

    6. After all the levels are cleared, Player will be able to see how many stars were collected in total, by observing the Totalstarscollected variable.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)