Skip to content

Instantly share code, notes, and snippets.

@triptych
Created November 16, 2010 21:51
Show Gist options
  • Select an option

  • Save triptych/702589 to your computer and use it in GitHub Desktop.

Select an option

Save triptych/702589 to your computer and use it in GitHub Desktop.
a YQL open table for calculating the XP requirements of a given Character Level
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<sampleQuery>select * from xpl where basexp="100" and numlevels="5" and startlevel="2"</sampleQuery>
<author>Andrew Wooldridge</author>
<description>Returns a list of levels and their required experience points. Suitable for RPGs or other games.</description>
</meta>
<bindings>
<select itemPath="" produces="XML">
<inputs>
<key id="basexp" type="xs:string" paramType="variable" required="true" />
<key id="numlevels" type="xs:string" paramType="variable" required="true"/>
<key id="startlevel" type="xs:string" paramType="variable" required="false"/>
</inputs>
<execute><![CDATA[
var retobj;
var tempXP;
var levels = <levels></levels>;
basexp = parseInt(basexp);
numlevels = parseInt(numlevels);
startlevel = parseInt(startlevel);
if(!startlevel){
startlevel = 1;
}
iterationIndex = (numlevels -1) + startlevel; //where to start
y.log("numlevels = "+ numlevels);
y.log("startlevel = "+ startlevel);
y.log("iterationIndex = " + iterationIndex);
for(var level = startlevel; level <= iterationIndex; level++){
tempXP = basexp*(level*(level - 1)/2);
levels.level += <level><value>{level}</value><experience>{tempXP}</experience></level>
}
//levels.level += <level>3</level>;
response.object = levels;
]]></execute>
</select>
</bindings>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment