Question About The Calculators., This works too. |
|
|
| MaxTheDragon |
Unregistered

|
[EDIT] I've editted the post, so that it now displays what I'm trying to say, in a better way. Also, it's a bit shorter now.
I was wondering whether RW uses a look-up array or a formula to retrieve exp values from levels. Also, I made this thread to inform people about the existence of the experience formula.
A look-up array works like this:
CODE <?php $exp[2] = 83; $exp[3] = 174; $exp[4] = 276; $exp[5] = 388;
etc.. etc..
$exp[99] = 13034431; ?> This results in a pretty long script. Using this array, you can call the exp value with:
CODE $exp[$level]; Now, this may seem as the best way to look up exp values, but there is an easier way:
The Experience Formula ("L" is the level you want to calc the exp value for):

I converted it to PHP (exact translation):
CODE <?php // This function calculates the corresponding exp from a certain level, // using the experience formula.
function experience($level){ $temp = 0; for($loop = 1; $loop < $level; $loop++) { $temp += floor($loop + 300 * pow(2, $loop / 7));} return floor($temp / 4);} ?> This piece of code generates EXACTLY the same as the array shown above. The only difference is that this function consists of no more than 5 lines. That's a whole lot better than 98 if you ask me.
Using this function, you can call the exp value with:
CODE experience($level);
This piece of code would be suitable for something that requires a list of all exp values, rather than just one random value.
CODE <?php // This script generates an array, using the experience formula. for($level = 2; $level <= 99; $level++){ $temp = 0; for($loop = 1; $loop < $level; $loop++) { $temp += floor($loop + 300 * pow(2, $loop / 7));} $experience[$level] = floor($temp / 4);} ?>
You could use this formula to generate the captions of each option in the drop-down box, and in the php-script that is used for the calculator. That way you could save some space and time.
Try running the script above including a loop with something like "echo experience($loop);". Examine the output, and you'll see that this formula works for all levels.
This post has been edited by MaxTheDragon: Aug 2 2005, 02:03 PM
|
|
|
| | |
 |
|
| Chrono |
Unregistered

|
i think those who made the calculator did whatever needed to do it. i didnt read what ur post since u was to lazy to read all.
but i assume firenimmo or who ever did it have done it well.
|
|
|
| | |
 |
|
| MaxTheDragon |
Unregistered

|
Yeah the calcs work fine. Those who use the calcs, will not notice any difference, whether they have used an array or a formula. The calcs will work the same in both occasions. I just wanted to point out that there is a formula for calc'ing experience. It worked perfectly for my Flash calc.
|
|
|
| | |
 |
|
| Chrono |
Unregistered

|
both ways work who cares which we use? ;O
|
|
|
| | |
 |
|
| MaxTheDragon |
Unregistered

|
The scripts will be smaller in filesize when using a formula.
|
|
|
| | |
 |
|
| Chrono |
Unregistered

|
well as far as i know, BW isnt really a problem for RW atm so
|
|
|
| | |
 |
|
| firenimmo |
Unregistered

|
QUOTE(MaxTheDragon @ Aug 2 2005, 11:00 AM) I find it incredibly stupid, that the people from these other fansites...
I see. Do you find me incredibly stupid? Didn't think that i'd possibly have used an efficient method to create the dropdown menu?
Your method of creating the dropdown menu would use one loop to create the options and call the function repeatedly, which would effectively mean you were using 99 loops, since the function uses a for loop.
I'd rather use 2 while loops (although using for would be acceptable in either or both cases, too).
One:
CODE $i = 1; $pts = 0; while($i < 100) { $pts = $pts + floor($i + (300 * pow(2, ($i / 7)))) / 4; $level[$i + 1] = floor($pts); $i++; }
Two:
CODE while ($i < 100) { echo "<option value=\"".$i."\" class=\"FormFields\">Level ".$i." (".number_format($level[$i])." EXP)</option>"; $i++; }
So thanks for thinking before you post.
|
|
|
| | |
 |
|
| MaxTheDragon |
Unregistered

|
I don't think you're incredibly stupid. I was referring to other fansites I know (not RW) that used pre-set arrays rather than a formula. Also, I was not really talking about what kind of loops or functions you used to create the drop-down box. I'm sure that you did use an efficient way. I was talking about using a formula rather than an array, to retrieve exp values.
I can't tell by the HTML source what the actual PHP looks like. I just thought that you might have used an array with exp values, while the same thing can be done with a formula.
Also, the function I posted was to show that it works the same as an array with exp values. It wasn't meant to be suitable for a script to generate options for a drop-down box. It is basically an exact translation of the formula. Of course, two while/for loops work better when generating the whole list of exp values. The function is more for calculating one value from a random level.
This post has been edited by MaxTheDragon: Aug 2 2005, 01:30 PM
|
|
|
| | |
 |
|
| firenimmo |
Unregistered

|
Well i'd have to be rather stupid to use an array rather than a formula really eh? 
The whole calculator, similar to the whole site, is written for efficiency and usability. Anything that slows things down too much is changed.
|
|
|
| | |
 |
|
| MaxTheDragon |
Unregistered

|
Yup, but if you didn't know the exp formula, you would have had no choice but to use an array. 
Anyway, this thread is also for people who would like to know what the exp. formula is. There is a whole lot of people on the official RS-forum, trying to figure it out. I can't post it there, because the censor filter eats such a complex formula and I can't advertise other sites either.
This post has been edited by MaxTheDragon: Aug 2 2005, 02:05 PM
|
|
|
| | |
 |
|
|
|