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)
^ 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.