zavin Posted March 21, 2009 Share Posted March 21, 2009 Most of my site I wrote and so I know how and why ot works. Some of the stuff on my site a gathered from other sources. I have to know what every thing does so I'm hoping someone can explain in detail exactly how the following math works. If someone could use an example to explain I would appreciate it. Thanks in advance for any help provided. Quote Link to comment Share on other sites More sharing options...
shlumph Posted March 21, 2009 Share Posted March 21, 2009 Sure Quote Link to comment Share on other sites More sharing options...
zavin Posted March 21, 2009 Author Share Posted March 21, 2009 lol I guess it would help if I included the code I am referring to. Didn't notice it was missing until shlumph's post. function Get_The_Level($exp) { $a=0; $end =0; for($x=1; ($end==0 && $x<100); $x++) { $a += floor($x+1500*pow(4, ($x/7))); if ($exp >= floor($a/4)){ } else { return $x; $end=1; } } Quote Link to comment Share on other sites More sharing options...
shlumph Posted March 21, 2009 Share Posted March 21, 2009 LOL what on earth is this function used for? Quote Link to comment Share on other sites More sharing options...
zavin Posted March 21, 2009 Author Share Posted March 21, 2009 An rpg game. It returns the level of a character based on the amount of experience. The experience is a number from a DB. Quote Link to comment Share on other sites More sharing options...
corbin Posted March 21, 2009 Share Posted March 21, 2009 Well, it's already fairly straightforward, so I don't know what you want someone to explain.... Perhaps translate it to more math-ish terms? for variables a = 0, b = 0, x = 1: while end is 0 and x is less than 100: a += greatest integer value of $x+1500*4^($x/7) if(exp < greatest integer value of a/4) exit the function and return x. By the way, the PHP code is not optimized. function Get_The_Level($exp) { $a=0; for($x=1; $x < 100; ++$x) { $a += floor($x+1500*pow(4, ($x/7))); if($exp < floor($a/4)){ return $x; } } } Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted March 21, 2009 Share Posted March 21, 2009 Also it's entirely pointless doing anything with variables (or, indeed, anything at all) after returning from a function. The code is entirely unreachable - the program counter's already been returned to the caller and all the local variables of the function have been popped from the stack. So setting $end to 1 here is never ever ever executed: return $x; $end=1; Quote Link to comment 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.