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 9th, 2014, 10:43 AM
This particular encounter table has twenty different outcomes based on five different terrains. Some have five or six outcomes others have all but three.
jkthomsen9 is offline   #11 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 10:53 AM
im confused... is it working, or not working for you? It works for me in a browser, but havent tried it directly in RealmWorks

This is starting to get complicated, but i'd suggest modifying the function to determine which set of tables to use...
mirtos is offline   #12 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 11:05 AM
ok, here is the latest. Ive done forest and aquatic for you. You will need to do the rest. Tested in a browser, but not Realm Works:

Code:
<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">

// Some Arrays


var forestArray = [];
var aquaticArray = [];

forestArray.push( {"max": 18, "content": "1 draugr; CR 2; Bestiary 2 110" });
forestArray.push({"max": 31, "content": "1 bunyip; CR 3; Bestiary 2 50"});
forestArray.push({"max": 59, "content": "1 orca; CR 5; Bestiary 88"});
forestArray.push({"max": 72, "content": "1 selkie; CR 5; Pathfinder #50 pg 88"});
forestArray.push({"max": 84, "content": "1 glacier toad; CR 6; Bestiary 2 268"});
forestArray.push({"max": 100,"content": "1 qallupilluk; CR 7; Pathfinder #51 pg 88"});


aquaticArray.push({"max": 70, "content": "another shark"});
aquaticArray.push({"max": 100, "content": "a nice dolphin"});


var allArrays = {
	"forest": forestArray,
	"aquatic": aquaticArray
};

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) {
 	var randomNum = rand(100) + 1;
	console.log(randomNum);
	var arrayOfChoices = allArrays[argument];
	if (!arrayOfChoices) {
		return "no such set: " + argument;
	}

	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 = tableResults('aquatic')" 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 = tableResults('forest')" 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 = tableResults()" 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 = tableResults()" 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 = tableResults()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>
mirtos is offline   #13 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 11:07 AM
i put it in a code block to keep the formatting (easy to follow when you have multiple blocks).

I changed a method name, and now the method requires an argument, for your code.
mirtos is offline   #14 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 11:09 AM
by the way, we're starting to get complicated. something like jquery would start to be better. but i dont know if realms works can handle external javascript libraries or not.

Last edited by mirtos; August 9th, 2014 at 11:18 AM.
mirtos is offline   #15 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 11:47 AM
Here is a slightly nicer, cleaner version. not much, but a little.

I dont think you need the input box. You could style the result tag a little nicer.

Slightly better formatted to (even though i hate using table formatting, i just dont know what html engine Realm Works is using)

<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">

// Some Arrays


var forestArray = [];
var aquaticArray = [];

forestArray.push( {"max": 18, "content": "1 draugr; CR 2; Bestiary 2 110" });
forestArray.push({"max": 31, "content": "1 bunyip; CR 3; Bestiary 2 50"});
forestArray.push({"max": 59, "content": "1 orca; CR 5; Bestiary 88"});
forestArray.push({"max": 72, "content": "1 selkie; CR 5; Pathfinder #50 pg 88"});
forestArray.push({"max": 84, "content": "1 glacier toad; CR 6; Bestiary 2 268"});
forestArray.push({"max": 100,"content": "1 qallupilluk; CR 7; Pathfinder #51 pg 88"});


aquaticArray.push({"max": 70, "content": "another shark"});
aquaticArray.push({"max": 100, "content": "a nice dolphin"});


var allArrays = {
"forest": forestArray,
"aquatic": aquaticArray
};

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(el, argument) {
var randomNum = rand(100) + 1;

var arrayOfChoices = allArrays[argument];
var chosenString = "";
if (!arrayOfChoices) {
chosenString = "no such set: " + argument;
} else {
for (var itemIndex in arrayOfChoices) {
var item = arrayOfChoices[itemIndex];
if (randomNum <= item.max) {
chosenString = item.content;
break;
}
}
}

var resultSection = el.parentNode.parentNode.getElementsByClassName('r esults')[0];
resultSection.innerHTML = chosenString;
}

</script>

<table>
<tr>
<td><input type="button" value="Aquatic" onClick="tableResults(this, 'aquatic')" size=""/></td>
<td><span class="results"></span>
</tr>
<tr>
<td><input type="button" value="Forest" onClick="tableResults(this, 'forest')" size=""/></td>
<td><span class="results"></span>
</tr>
<tr>
<td><input type="button" value="Hills" onClick="tableResults(this, 'hills')" size=""/></td>
<td><span class="results"></span>
</tr>
</table>
</form>

</BODY>
</HTML>

Last edited by mirtos; August 9th, 2014 at 11:49 AM. Reason: code cleanup
mirtos is offline   #16 Reply With Quote
gloranphile
Senior Member
 
Join Date: Mar 2013
Location: Denver, CO
Posts: 437

Old August 9th, 2014, 12:02 PM
Mirtos, I tested the last two code pieces you put up, but neither one works in RW, only in a browser.
gloranphile is offline   #17 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 12:53 PM
i guess i should test in realms work before i put up. looks like it might be using a different javascript engine.
mirtos is offline   #18 Reply With Quote
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 9th, 2014, 01:17 PM
I just tried the first one. got it to work while rmeoving the console.log statement... (debugging statement).

Couldnt get the second one to work... looks like whatever JS engine is being used it doesnt know the parentdom stuff.

When i was doing it all earlier i wasnt by realms works... tested, now it works (well one of them does) It would be interesting to know what JS engine is being used.


You could do a table with ids or something, but you can use the first one:


<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">

// 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) {

var forestArray = [];
var aquaticArray = [];

forestArray.push( {"max": 18, "content": "1 draugr; CR 2; Bestiary 2 110" });
forestArray.push({"max": 31, "content": "1 bunyip; CR 3; Bestiary 2 50"});
forestArray.push({"max": 59, "content": "1 orca; CR 5; Bestiary 88"});
forestArray.push({"max": 72, "content": "1 selkie; CR 5; Pathfinder #50 pg 88"});
forestArray.push({"max": 84, "content": "1 glacier toad; CR 6; Bestiary 2 268"});
forestArray.push({"max": 100,"content": "1 qallupilluk; CR 7; Pathfinder #51 pg 88"});


aquaticArray.push({"max": 70, "content": "another shark"});
aquaticArray.push({"max": 100, "content": "a nice dolphin"});


var allArrays = {
"forest": forestArray,
"aquatic": aquaticArray
};

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

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 = tableResults('aquatic')" 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 = tableResults('forest')" 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 = tableResults()" 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 = tableResults()" 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 = tableResults()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>

Last edited by mirtos; August 9th, 2014 at 01:19 PM.
mirtos is offline   #19 Reply With Quote
Parody
Senior Member
 
Join Date: Jan 2013
Location: Rochester, MN
Posts: 1,516

Old August 9th, 2014, 06:12 PM
Realm Works (likely via the .NET WebBrowser control) uses the engine from the main version of IE installed on your machine. I have IE11 and the User Agent for Realm Works is:
Quote:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
It'll navigate to other websites and run plugins if you want. I wouldn't recommend using external resources but you likely can. At that point, though, why not just link to a page on the Internet? The "local" page won't work without Internet access anyway.


Last edited by Parody; August 9th, 2014 at 06:32 PM.
Parody 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 05:58 PM.


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