View Single Post
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 9th, 2014, 10:34 AM
Thank You Mirtos. There seems to be something wrong with the code. Nothing displays when to click the button. I have started to modify the code to become the Crown of the World Random Encounter table. This is what I have so far. Not sure what values to change to make a different array for each button. Again thank you mirtos for your help.

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Crown of the World Random Encounters</TITLE>
</HEAD>
<BODY>

<script language="JavaScript">
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
}

function rand(number) {
return Math.ceil(rnd()*number);
}

function BitchRule() {
var randomNum = rand(100) + 1;
console.log(randomNum);
var arrayOfChoices = [];
arrayOfChoices.push( {"max": 18, "content": "1 draugr; CR 2; Bestiary 2 110" });
arrayOfChoices.push({"max": 31, "content": "1 bunyip; CR 3; Bestiary 2 50"});
arrayOfChoices.push({"max": 59, "content": "1 orca; CR 5; Bestiary 88"});
arrayOfChoices.push({"max": 72, "content": "1 selkie; CR 5; Pathfinder #50 pg 88"});
arrayOfChoices.push({"max": 84, "content": "1 glacier toad; CR 6; Bestiary 2 268"});
arrayOfChoices.push({"max": 100,"content": "1 qallupilluk; CR 7; Pathfinder #51 pg 88"});

var chosenString = "";
for (var itemIndex in arrayOfChoices) {
var item = arrayOfChoices[itemIndex];
if (randomNum <= item.max) {
chosenString = item.content;
break;
}
}
return chosenString;

}

</script>

<form>
<input type="button" name="Button1" value="Aquatic" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button2" value="Forest" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button3" value="Hills" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button4" value="Mountains" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

<form>
<input type="button" name="Button5" value="Tundra" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>

Last edited by jkthomsen9; August 9th, 2014 at 10:38 AM. Reason: mistake in code
jkthomsen9 is offline   #10 Reply With Quote