`Karl Posted November 7, 2009 Share Posted November 7, 2009 I've managed to make a skill calculator for a game I play. However, I want each of the iterations to be highlighted in green in a player can do it, and red if not. Then Yellow if they will be able to do it by the time they reach their goal. However, everyones experiences differs. Level 1 - 0 Exp Level 2 - 83 Exp Level 3 - 174 Exp Level 4 - 276 Exp and so on. A player can have any experience between these levels. such as 182, this would be level 3. So if an iteration required Level 4, they couldn't do it so I would like Level 4 to be highlighted red. So I need the code to figure out which level they are from the experience they give, then highlight the iterations accordingly. I will show you the calculator I've coded, however, I don't want to publicly post it. Thanks ~Karl Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/ Share on other sites More sharing options...
ngreenwood6 Posted November 7, 2009 Share Posted November 7, 2009 im not sure if i just read your post wrong but this should be very simple. you can use a simple if block: if($user_xp < 83){ level one } elseif($user_xp >= 83 && $user_xp < 174){ level two } elseif($user_xp >= 174 && $user_xp < 276){ level 3 } You would just do what you needed to do inside of each block Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953056 Share on other sites More sharing options...
`Karl Posted November 7, 2009 Author Share Posted November 7, 2009 Not quite sure that would work, I'll have a mess around though. Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953060 Share on other sites More sharing options...
ngreenwood6 Posted November 7, 2009 Share Posted November 7, 2009 why dont you think that would work? am i missing something in your original post or not understanding it? Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953066 Share on other sites More sharing options...
`Karl Posted November 7, 2009 Author Share Posted November 7, 2009 Following on from what you put, I want each thing to highlight according to whether or not a player can do the iteration or not. In theory, this should work: if($arr['level'] <= $level) { $colour = "24ff00"; } elseif ($arr['level'] > $level){ $colour = "ff0000"; } $arr['level'] is the level required, which is taken from a database. However, it highlights it all green at the moment, even if a player cannot do the task. Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953075 Share on other sites More sharing options...
sasa Posted November 7, 2009 Share Posted November 7, 2009 try <?php function my_level($exp){ $levels = array(1 => 0, 83, 174, 276); $l = count($levels); while ($levels[$l] > $exp) $l--; return $l; } echo my_level(180); ?> Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953079 Share on other sites More sharing options...
`Karl Posted November 7, 2009 Author Share Posted November 7, 2009 Nevermind Sasa, that works perfectly. However, the highlighting still doesn't. if($arr['level'] <= my_level($current)) { $colour = "30ff00"; } elseif ($arr['level'] > my_level($current)){ $colour = "ff0000"; } What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953080 Share on other sites More sharing options...
ngreenwood6 Posted November 7, 2009 Share Posted November 7, 2009 what is the value of $arr['level']? Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953086 Share on other sites More sharing options...
`Karl Posted November 7, 2009 Author Share Posted November 7, 2009 what is the value of $arr['level']? It's the level required to do the iteration, the information is taken from a database. Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953087 Share on other sites More sharing options...
`Karl Posted November 7, 2009 Author Share Posted November 7, 2009 Figured it out myself, thanks for all the help guys. Quote Link to comment https://forums.phpfreaks.com/topic/180648-solved-skill-calculators/#findComment-953094 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.