Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2013
    Posts
    125
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Every 10, add 1?

    Is there a loop I can step every 10 to up the level?
    For every 10 bubbles I POP in my game, it goes to the next level...
    [code]
    if(POP.score.hit === 10){
    POP.score.level = 2;
    }
    if(POP.score.hit === 20){
    POP.score.level = 3;
    }
    [\code]

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    use the modulus operator, you can even do the level this way too actually.
    Code:
    
       if (POP.score.hit % 10 === 0){
    POP.score.level = POP.score.hit / 10;
           
            }
    Last edited by DanInMa; 09-18-2013 at 02:05 AM.

  • #3
    New Coder
    Join Date
    Aug 2013
    Posts
    50
    Thanks
    0
    Thanked 11 Times in 11 Posts
    Quote Originally Posted by DanInMa View Post
    use the modulus operator, you can even do the level this way too actually.
    Code:
    
       if (POP.score.hit % 10 === 0){
    POP.score.level = POP.score.hit / 10;
           
            }
    That's what I was going to suggest. You forgot to add 1 to the level, though.

    Code:
    if (POP.score.hit % 10 === 0) {
        POP.score.level = (POP.score.hit / 10) + 1;
    }

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by joesimmons View Post
    That's what I was going to suggest. You forgot to add 1 to the level, though.

    Code:
    if (POP.score.hit % 10 === 0) {
        POP.score.level = (POP.score.hit / 10) + 1;
    }
    Oh he started with levle 1 not zero. Thanks dude, totally right. I had fun figuring this one out never really had to do this before


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •