Help with Score

SopandaSopanda Member Posts: 21

Hey guys. Been working with GameSalad for a week now. I figured out how to add a score counter to the game, but instead of adding a point each time, it adds 2 points instead. I've watched different videos on YouTube, it only adds one, while mine adds 2. Could you guys help me out?

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,926

    We would like to help you but we can't help you without seeing your rules. I'd be guessing to suggest that you're subtracting 6 from 8 or that you have duplicate Change Attribute behaviors that are adding one twice or that you're counting the table rows in a two row table or... you get the point.

    Either post a screenshot or a link to download your project and I'm sure we can get to the bottom of it.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SopandaSopanda Member Posts: 21

    Here's what I have. I don't know what you are saying with the 6 and 8 thing.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,926
    edited December 2014

    You're telling the actor to destroy itself and then to constrain game.score to game.score+1. Constraining an attribute to itself is generally not recommended because it introduces an endless loop (if game.score is 0, it will force itself to be one greater which is 1, and then immediately force itself to be one greater, which is 2, and then immediately 3, and ... etc.). So you've forced the score to increase constantly. It just happened that it stopped at 2 because you also are destroying the actor and it can't continue constraining the value after that.

    To fix the problem, replace the Constrain Attribute with a Change Attribute behavior. That will change the attribute's value once instead of continually. Also, it's best to place the Destroy behavior last so that you don't run the risk of destroying the actor before it's had a chance to run the other behavior(s).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,914

    Well you should be using a change attribute not a constrain.

  • SopandaSopanda Member Posts: 21

    @The_Gamesalad_Guru said:
    Well you should be using a change attribute not a constrain.

    Ohhhh, Thanks I got it. Should have read what i was typing more closely

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,914

    I could see from the beginning image you were using the wrong type. Check out my GSLogic series it will help you understand the basics for coding in GS.

Sign In or Register to comment.