0

I was busy making a level system for my site, I already have a if/else system that does it for a x amount of clicks.

So if you have clicked 44 times, you're level 1. The only problem is that people already clicked over 10.000 times(it's cool actually) but now I have to make a lot of ifs to create a level for it. This is what I already have:

  if($score['clicks'] >= 0 && $score['clicks'] <= 49)
  {
      $level = 'Level 2';
  }
  elseif($score['clicks'] >= 50 && $score['clicks'] <= 199)
  {
      $level = 'Level 3';
  }
  elseif($score['clicks'] >= 200 && $score['clicks'] <= 349)
  {
      $level = 'Level 4';
  }
  elseif($score['clicks'] >= 350 && $score['clicks'] <= 499)
  {
      $level = 'Level 5';
  }
  elseif($score['clicks'] >= 500 && $score['clicks'] <= 749)
  {
      $level = 'Level 6';
  }
  elseif($score['clicks'] >= 750 && $score['clicks'] <= 999)
  {
      $level = 'Level 7';
  }
  elseif($score['clicks'] >= 1000 && $score['clicks'] <= 1499)
  {
      $level = 'Level 8';
  }
  elseif($score['clicks'] >= 1500 && $score['clicks'] <= 1999)
  {
      $level = 'Level 9';
  }
  elseif($score['clicks'] >= 2000 && $score['clicks'] <= 2999)
  {
      $level = 'Level 10';
  }

I don't know how to make a if that can do it this way:

If $score['clicks'] is greater than 3000 then level is 11. And if $score['cliks'] is greater than 4000 then level is 12 etc...

Can you guys help me with this? Thank you and sorry for my bad English, it isn't my mother tongue.

1
  • So you basically want to have an unlimited number of levels? And for 1000 clicks you move up one level (for clicks > 3000)? Commented Mar 29, 2014 at 15:15

2 Answers 2

4

Create a mathematical model instead of dozens of if statements. For example you could use: round(clicks^0.3) = level. That is a exponential function so users will level up fast in the beginning but then it get harder and harder to level up. You probably recognize this pattern from a lot of games.

In PHP code:

$level = round(pow($score['clicks'], 0.3));

A table of the result:

clicks^0.3  = level
-------------------
1^0.3       = 1
10^0.3      = 2
100^0.3     = 4
1000^0.3    = 8
10000^0.3   = 16
Sign up to request clarification or add additional context in comments.

2 Comments

yeah, was baffled with OP's solution. Your's one is better, simple and for unlimited clicks.
The level limits won't be longer so nice numbers. But this can be fine.
2

You can do something similar:

}elseif($score['clicks']>=3000){
  $level= 'Level ' . (floor(($score['clicks']-3000)/1000)+11);
}

3 Comments

Can be simplified. Use floor(($score['clicks']/1000)+8);
Yes. But I think it is less understandable.
Thnx, I'm bad at PHP with floor() and math etc. Thank you it worked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.