# Making a counter for every 5 increments.

Page 1 of 1

## 2 Replies - 405 Views - Last Post: 05 February 2013 - 03:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=311280&amp;s=bfc81480a4eb8bd3ab69953bdab8a5e5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 optix212

Reputation: 30
• Posts: 537
• Joined: 10-October 09

# Making a counter for every 5 increments.

Posted 05 February 2013 - 03:25 PM

Okay, I'm currently making a game, and the player has a level, and skills. What I want is for every 5 levels that the player gains, he gains a talent point that will effect one of his skills. Now I know that I could achieve this by doing a bunch of if statements, but I don't think that is the most efficient way to do it.

Here's an example off the top of my head:

```if(level == 5){
talentpoints++;
}
if(level == 10){
talentpoints++;
}

```

I could easily implement it this way, but it seems redundant and kind of messy to say the least, and would also mean that there would be an eventual cap to talent points. What kind of counter could I implement to resolve this issue and make it more efficient?

Is This A Good Question/Topic? 0

## Replies To: Making a counter for every 5 increments.

### #2 Ryano121

• D.I.C Lover

Reputation: 1376
• Posts: 3,015
• Joined: 30-January 11

## Re: Making a counter for every 5 increments.

Posted 05 February 2013 - 03:27 PM

The modulus operator(%) will be your friend here. It returns the remainder after the division of its two operands. In your case

```if(level % 5 == 0) { // meaning if level is a multiple of 5 as the remainder is zero after division
// go up a talent point
}
```

### #3 optix212

Reputation: 30
• Posts: 537
• Joined: 10-October 09

## Re: Making a counter for every 5 increments.

Posted 05 February 2013 - 03:28 PM

AHH! Thank you so much sir!