Adding +1 to Score Only Once

HolyHippoHolyHippo Member Posts: 12
edited November -1 in Working with GS (Mac)
I'm working on a game where you tap a particular object to score a point. After its tapped I want it to continue across the screen. Right now I have it set to...when pressed game.score+1. That however allows the player to continuously tap the object to increase the score.

How do make it so tapping each object only increases the score by 1?

Thanks!

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    make a self attribute called tap in the object and set it to 0

    then have a rule in the object when attribute tap=0 and touch is pressed
    -change score to score+1
    -change attribute tap to 1
  • HolyHippoHolyHippo Member Posts: 12
    I think I understand that. I'm trying it and I'm obviously doing something wrong.

    Here's what I did...

    1. Rule...when pressed change score to score+1
    2. A Rule under that ...when tap=0 change tap to 1
  • DrGlickertDrGlickert Member Posts: 1,135
    On the actor that is tapped to add +1 to the score, create a self.attribute that's an integer and call it self.score.

    In that same actor, create a rule that says this;

    When self.score = 0
    AND
    touch is pressed

    Change attribute self.score to 1
    Change attribute game.score to game.score + 1

    That will only allow the player to add +1 to the score ONLY one time.

    (Only need one rule. You don't need a rule imbedded in the first rule).
  • HolyHippoHolyHippo Member Posts: 12
    You guys rock. Got it to work.

    One thing I forgot to mention. I'm having the same 4 objects repeatedly spawn on one side and scroll to the other. So having this set up now I tap the one object and the score increases by 1 but when I tap on the next spawn of the object nothing happens because of the constraint I've put on it.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi HolyHippo, one way around your problem is to make duplicate actors in the inspector, so that you can use different attributes for each: make 4 attributes, game.scoreA, game.scoreB, game.score.C and game.scoreD. So replacing these in DrGlicket's Rules you'll have control of each one.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • calvin9403calvin9403 Member Posts: 3,186
    Also guys why not use Boolean? I remember that I post a thread about that

    Bool is faster then int
  • HolyHippoHolyHippo Member Posts: 12
    Ok...I think I got that. I'll try it out.

    Thanks!
  • HolyHippoHolyHippo Member Posts: 12
    Ok...I tried that and I'm doing something wrong. Any other ideas? Or should I keep trying?

    Appreciate the help!
  • OctappusOctappus Member Posts: 68
    calvin9403 said:
    Also guys why not use Boolean? I remember that I post a thread about that

    Bool is faster then int

    I'm a big fan of Boolean - I find it makes things easier to understand and remember, which then leads to fewer mistakes.

    I didn't know that it's faster than using integers - that's an added bonus!
  • OctappusOctappus Member Posts: 68
    DrGlickert said:
    On the actor that is tapped to add +1 to the score, create a self.attribute that's an integer and call it self.score.

    In that same actor, create a rule that says this;

    When self.score = 0
    AND
    touch is pressed

    Change attribute self.score to 1
    Change attribute game.score to game.score + 1

    That will only allow the player to add +1 to the score ONLY one time.

    (Only need one rule. You don't need a rule imbedded in the first rule).

    This is how I would have done it - the key is using SELF attributes and not GLOBAL ones. This way, changes should affect only one instance of an actor rather than all of them.

    Can you confirm you are using self attributes?
  • HolyHippoHolyHippo Member Posts: 12
    That was the problem. Thanks DrGlickert and Octappus!

    Now I have a wall set up at the end that if the actor touches it it subtracts a life. How do I make the wall only subtract a life if the actor hasn't been tapped? In other words whether or not the actor has been tapped a life is subtracted when it hits the wall.
  • OctappusOctappus Member Posts: 68
    Use a rule, for example:

    When ... actor receives event ... overlaps or collides ... with ... actor of type ... wall

    If you don't refer to the self.score attribute, then it won't matter if the actor has been tapped or not.
Sign In or Register to comment.