RuneWeb Forums
Welcome, Guest. Click here to Log In or here to Register.
 
Closed TopicStart new topic
> Question About The Calculators., This works too.
MaxTheDragon
post Aug 2 2005, 11:00 AM | Post #1 +Quote Post

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):

IPB Image

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
| Go to the top of the page
Chrono
post Aug 2 2005, 12:14 PM | Post #2 +Quote Post

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.
| Go to the top of the page
MaxTheDragon
post Aug 2 2005, 12:20 PM | Post #3 +Quote Post

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.
| Go to the top of the page
Chrono
post Aug 2 2005, 12:23 PM | Post #4 +Quote Post

Unregistered



both ways work who cares which we use? ;O
| Go to the top of the page
MaxTheDragon
post Aug 2 2005, 12:24 PM | Post #5 +Quote Post

Unregistered



The scripts will be smaller in filesize when using a formula.
| Go to the top of the page
Chrono
post Aug 2 2005, 12:33 PM | Post #6 +Quote Post

Unregistered



well as far as i know, BW isnt really a problem for RW atm so happy.gif
| Go to the top of the page
firenimmo
post Aug 2 2005, 12:59 PM | Post #7 +Quote Post

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.
| Go to the top of the page
MaxTheDragon
post Aug 2 2005, 01:11 PM | Post #8 +Quote Post

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
| Go to the top of the page
firenimmo
post Aug 2 2005, 01:44 PM | Post #9 +Quote Post

Unregistered



Well i'd have to be rather stupid to use an array rather than a formula really eh? joking.gif

The whole calculator, similar to the whole site, is written for efficiency and usability. Anything that slows things down too much is changed.
| Go to the top of the page
MaxTheDragon
post Aug 2 2005, 01:56 PM | Post #10 +Quote Post

Unregistered



Yup, but if you didn't know the exp formula, you would have had no choice but to use an array. happy.gif

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
| Go to the top of the page
 
« Next Oldest | RW Submit, Suggest, & Report | Next Newest »

Closed TopicStart new topic

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)

0 Members: