Lone Wolf Development Forums  

Go Back   Lone Wolf Development Forums > Realm Works Forums > Realm Works Discussion
Register FAQ Community Today's Posts Search

Notices

Reply
 
Thread Tools Display Modes
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 14th, 2014, 02:00 PM
LOL ignorance duly shown. Entered the code where you said and it worked. Thank you Mirtos.
jkthomsen9 is offline   #11 Reply With Quote
Parody
Senior Member
 
Join Date: Jan 2013
Location: Rochester, MN
Posts: 1,517

Old August 14th, 2014, 02:03 PM
Quote:
Originally Posted by mirtos View Post
function rand(x) {
return Math.ceil(Math.random() * x);
}

Its the Math.ceil that makes it from 1-100 as opposed 0-99
Math.ceil makes it 0-100 instead of 0-99. Math.random() returns [0-1), so you can (extremely rarely) get 0 and (extremely slightly less rarely than desired) get 100.

You would want
Code:
Math.floor(Math.random() * x) + 1;
to get a number from 1-x.

OK, back to Gen Con for me! :)

Parody is offline   #12 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 14th, 2014, 02:04 PM
Bad code on my part. sectionIdentifier not used.

to make it more configurable on your part:

make the function definition like this:

Code:
function tableResults(argument, rollModifier) {
make the randomizer like this:

Code:
    if (!rollModifier) {
       rollModifier = 0;
    }
    var randomNum = rand(100) + rollModifier;

make your HTML like this:

Code:
<form>
<input type="button" name="Button1" value="Outer Rim" onClick="var x = tableResults('varisia', 0);this.form.name.value=x.nam e;this.form.content.value = x.content;" size="" />
<input name="name" style="font-weight:bold;"></input>
<textarea name="content" cols="50" rows="11" wrap="soft"></textarea>

</form>

<form>
<input type="button" name="Button2" value="High Ice" onClick="var x = tableResults('varisia', 25);this.form.name.value=x.nam e;this.form.content.value = x.content;" size="" />
<input name="name" style="font-weight:bold;"></input>
<textarea name="content" cols="50" rows="11" wrap="soft"></textarea>

</form>

<form>
<input type="button" name="Button3" value="Boreal Expanse" onClick="var x = tableResults('varisia', 50);this.form.name.value=x.nam e;this.form.content.value = x.content;" size="" />
<input name="name" style="font-weight:bold;"></input>
<textarea name="content" cols="50" rows="11" wrap="soft"></textarea>

</form>
mirtos is offline   #13 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 14th, 2014, 02:05 PM
Although I can only rely on the randomness. It appears to be working. Outer Rim gets results of 1-100, High Ice 26-125, and Boreal Expanse 51-150. I did not change sectionIdentifier to regionNumber.
jkthomsen9 is offline   #14 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 14th, 2014, 02:06 PM
fair enough. my previous post right before yours will make it so you can control the number a little bit more as well. up to you what you prefer.
mirtos is offline   #15 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 14th, 2014, 02:08 PM
Quote:
Originally Posted by Parody View Post
Math.ceil makes it 0-100 instead of 0-99. Math.random() returns [0-1), so you can (extremely rarely) get 0 and (extremely slightly less rarely than desired) get 100.

You would want
Code:
Math.floor(Math.random() * x) + 1;
to get a number from 1-x.

OK, back to Gen Con for me! :)
parody is absolutely correct.

my bad.

so the function should be:
Code:
function rand(x) {
   return Math.floor(Math.random() * x) + 1;
}

Last edited by mirtos; August 14th, 2014 at 02:11 PM.
mirtos is offline   #16 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 14th, 2014, 02:09 PM
Would I replace all of this

var randomNum = rand(100) + ((sectionIdentifier -1) * 25)
var arrayOfChoices = allArrays[argument];
var error = "";
if (!arrayOfChoices) {
error = "no such set: " + argument;
}


with

if (!rollModifier) {
rollModifier = 0;
}
var randomNum = rand(100) + rollModifier;
jkthomsen9 is offline   #17 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 14th, 2014, 02:19 PM
no. You would replace:

var randomNum = rand(100) + ((sectionIdentifier -1) * 25)


with

if (!rollModifier) {
rollModifier = 0;
}
var randomNum = rand(100) + rollModifier;


-----------------------------------------------------------------

leave the arrayOfChoices section alone.
mirtos is offline   #18 Reply With Quote
jkthomsen9
Senior Member
 
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267

Old August 14th, 2014, 02:26 PM
Crap I seem to have broke it. This is what I currently have.


Quote:

<HTML>
<HEAD>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Crown of the World Caravan Encounters</TITLE>
</HEAD>
<BODY>

<script language="JavaScript">

// Some Arrays


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 tableResults(argument, rollModifier) {

var varisiaArray = [];

varisiaArray.push({"max": 5, "name": "Rough Terrain", "content": "a" });
varisiaArray.push({"max": 10, "name": "Cabin", "content": "b" });
varisiaArray.push({"max": 15, "name": "Erutaki Encampment", "content": "c" });
varisiaArray.push({"max": 20, "name": "Hungry Predators", "content": "d" });
varisiaArray.push({"max": 25, "name": "Horned Herd", "content": "e" });
varisiaArray.push({"max": 30, "name": "Wanderers", "content": "f" });
varisiaArray.push({"max": 35, "name": "Wrecked Caravan", "content": "g" });
varisiaArray.push({"max": 40, "name": "Dragon Sighting", "content": "h" });
varisiaArray.push({"max": 50, "name": "Blizzard", "content": "A bitter storm of driving wind and snow engulfs the caravan for 1d4 days. During this time, the caravan takes a –2 penalty to AC and on Attack and Security checks because of poor visibility and hostile weather. The caravan can make a DC 22 Security check each day to move at half speed during the blizzard. If the caravan fails the check by 4 or less, the caravan moves at one-quarter speed. If the caravan fails the check by 5 or more, it makes no progress. Casting control winds grants a +2 bonus on this check, while control weather grants a +4 bonus. When the blizzard ends, the deep drifts of snow it leaves behind are considered a Rough Terrain encounter (see page 17) for 1d4 days. XP Award: Award the PCs 3,200 XP for a blizzard encounter." });
varisiaArray.push({"max": 55, "name": "Aurora", "content": "The wondrous polar aurora ripples overhead at night for 1 week. This good omen grants the caravan a +2 bonus on Resolve checks for the duration of the aurora, and the caravan’s fortune-teller can use her reroll ability one additional time that week." });
varisiaArray.push({"max": 60, "name": "Wings of Hope", "content": "k" });
varisiaArray.push({"max": 65, "name": "Death from Below", "content": "l" });
varisiaArray.push({"max": 70, "name": "Creeping Rot", "content": "m" });
varisiaArray.push({"max": 76, "name": "Wagon Damage", "content": "n" });
varisiaArray.push({"max": 80, "name": "Ice Hunters", "content": "o" });
varisiaArray.push({"max": 85, "name": "Pleasant Weather", "content": "p" });
varisiaArray.push({"max": 90, "name": "Polar Pudding", "content": "q" });
varisiaArray.push({"max": 100, "name": "Frozen Dead", "content": "r" });
varisiaArray.push({"max": 105, "name": "Black Monolith", "content": "The caravan approaches a monolith of black stone that rises out of the ice to a height of 20 feet. This is one of the monoliths Katiyana has been placing across the Crown of the World to cement her control over the morozkos. Creatures: A Frozen Dead encounter always accompanies the discovery of a black monolith. In addition, there is a 50% chance that it is accompanied by a Blizzard encounter (see the next column)." });
varisiaArray.push({"max": 110, "name": "The Lonely Maiden", "content": "t" });
varisiaArray.push({"max": 115, "name": "Northern Lights", "content": "u" });
varisiaArray.push({"max": 120, "name": "Rough Terrain", "content": "v" });
varisiaArray.push({"max": 125, "name": "Crevasse", "content": "w" });
varisiaArray.push({"max": 130, "name": "Polar Mirage", "content": "x" });
varisiaArray.push({"max": 135, "name": "Black Slush", "content": "The caravan encounters a wide area of tainted snow and polluted eff luent. This acts as an open Crevasse encounter (see page 12), though casting water walk grants a +2 bonus on Security checks to cross the area. In addition, the caravan must make a DC 23 Security check once per hour while crossing or become poisoned by the toxic slurry, taking a cumulative –1 penalty to AC and on Attack checks for each failed check. These penalties can be removed with a successful DC 23 Security check when the caravan rests. Each healer in the caravan grants a cumulative +1 bonus on this check, and each casting of neutralize poison grants a +2 bonus on the check. Creatures: In addition, there is a 50% chance that an area of black slush is the hunting ground of a mated pair of chardas, xenophobic monstrous humanoids from the depths of the earth, who attack the caravan (AC 23; hp 115; Attack +18; Damage 8d8+4). The chardas can be avoided with two successful DC 19 Security checks. The chardas fight to the death. Treasure: The chardas maintain a lair in an ice cave below the black slush, which can be found with a DC 25 Survival check. Inside the lair are 34 uncut diamonds (worth 100 gp each), one of which is actually an air elemental gem. XP Award: Award the PCs 3,200 XP for a black slush encounter, and an additional 6,400 XP if they defeat the mated pair of chardas." });
varisiaArray.push({"max": 140, "name": "Auroral Flight", "content": "Creature: The caravan sees a strange, blue-green light on the northern horizon, sometimes streaking at high speed in straight lines, and at other times soaring in broad circles. This is a boreal yrthak, a f lying reptile that has adapted to life in the cold skies above the frozen wastes of the Crown of the World. The caravan can make a DC 24 Security check to avoid the boreal yrthak; otherwise, the creature notices the caravan and swoops in to attack, targeting individual creatures rather than the caravan itself." });
varisiaArray.push({"max": 145, "name": "Cold Gate", "content": "aa" });
varisiaArray.push({"max": 150, "name": "Hunting Party", "content": "ab" });



var allArrays = {
"varisia": varisiaArray,
};

if (!rollModifier) {
rollModifier = 0;
}
var randomNum = rand(100) + rollModifier;
var arrayOfChoices = allArrays[argument];
var error = "";
if (!arrayOfChoices) {
error = "no such set: " + argument;
}

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

var results = [];
if (error) {
results.name = "";
results.content = error;
} else {
results.name = name;
results.content = content;
}
return results;

}

</script>

<div id="error"></div>
<form>
<input type="button" name="Button1" value="Outer Rim" onClick="var x = tableResults('varisia', 0);this.form.name.value=x.nam e;this.form.content.value = x.content;" size="" />
<input name="name" style="font-weight:bold;"></input>
<textarea name="content" cols="50" rows="11" wrap="soft"></textarea>

</form>

<form>
<input type="button" name="Button2" value="High Ice" onClick="var x = tableResults('varisia', 25);this.form.name.value=x.nam e;this.form.content.value = x.content;" size="" />
<input name="name" style="font-weight:bold;"></input>
<textarea name="content" cols="50" rows="11" wrap="soft"></textarea>

</form>

<form>
<input type="button" name="Button3" value="Boreal Expanse" onClick="var x = tableResults('varisia', 50);this.form.name.value=x.nam e;this.form.content.value = x.content;" size="" />
<input name="name" style="font-weight:bold;"></input>
<textarea name="content" cols="50" rows="11" wrap="soft"></textarea>

</form>
jkthomsen9 is offline   #19 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 14th, 2014, 03:14 PM
I look at it in like 45 minutes.

Edit: off the bat, looks like you have a typo. You have a this.form.name.value = x.nam e

It should be x.name

(You have a space misspelling the word name)

Just a guess, as I'm currently on a bus.

Last edited by mirtos; August 14th, 2014 at 03:18 PM.
mirtos is offline   #20 Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 11:16 AM.


Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.