ID:273624
 
mob
verb
Test()
usr<<browse({"<script type="text/javascript">
<!--
document.close();
document.open();
document.writeln('Begin JavaScript output:');
document.writeln('<pre>');

points = 0;
output = 0;
minlevel = 2; // first level to display
maxlevel = 200; // last level to display

for (lvl = 1; lvl <= maxlevel; lvl++)
{
points += Math.floor(lvl + 300 * Math.pow(2, lvl / 7.));
if (lvl >= minlevel)
document.writeln('Level ' + (lvl) + ' - ' + output + ' xp');
output = Math.floor(points / 4);
}

document.writeln('</PRE>');
document.close();
// -->
</SCRIPT>"}
)


When i convert the JavaScript algorithm to BYOND Code the values i get are different from the JavaScript outputs. Is there a way i can use the JavaScript values? or can anyone see where the algorithm is different?

The BYOND algorithm i got was:
mob
verb
Test()
var/points = 0
var/output = 0
var/minlevel = 1 // first level to display
var/maxlevel = 200 // last level to display
var/lvl = 1
for (lvl = 1; lvl <= maxlevel; lvl++)
points += (lvl + (300 * (2^(lvl/7))))
if (lvl >= minlevel)
usr << "Level [lvl] - [output] xp"
output = (points/4)

JavaScript Math.pow(2, lvl / 7.) does not equal DM (2^(lvl/7)

^ is binary XOR, not power of in DM. What you are looking for is the ** operator.

As for your question, yes, you could use the result of your JavaScript simply by having it pass the value (GET/POST) back and taking it in BYOND's Topic procedure.
In response to Schnitzelnagler
Ah, thanks. I used the ** rather than Topic, since it doesnt need to be displayed. Thanks alot for your help :)
You're probably better off correcting the DM version of the algorithm. But, if you do need to pass values from JavaScript to DM my interface library contains functions to do that. It comes with a few examples.

A simple example would look something like this:

// JavaScript code
points = 0;
output = 0;
minlevel = 2; // first level to display
maxlevel = 200; // last level to display

for(lvl = 1; lvl <= maxlevel; lvl++)
{
points += Math.floor(lvl + 300 * Math.pow(2, lvl / 7.));
if(lvl >= minlevel)
world.level_exp(lvl, output);
output = Math.floor(points / 4);
}

// DM code
proc
level_exp(lvl, output)
world << "Level [lvl] - [output] xp"