Senior Member
Join Date: Jun 2010
Location: Beaverton, OR
Posts: 267
|
This particular encounter table has twenty different outcomes based on five different terrains. Some have five or six outcomes others have all but three.
|
#11 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
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... |
#12 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
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> |
#13 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
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. |
#14 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
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. |
#15 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
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 |
#16 |
Senior Member
Join Date: Mar 2013
Location: Denver, CO
Posts: 437
|
Mirtos, I tested the last two code pieces you put up, but neither one works in RW, only in a browser.
|
#17 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
i guess i should test in realms work before i put up. looks like it might be using a different javascript engine.
|
#18 |
Senior Member
Join Date: Oct 2011
Posts: 865
|
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. |
#19 |
Senior Member
Join Date: Jan 2013
Location: Rochester, MN
Posts: 1,516
|
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:
Last edited by Parody; August 9th, 2014 at 06:32 PM. |
|
#20 |
|
|