Added code in Gamebook
Cyrano
26 Dec 2012, 20:57I'm probably missing something here,but I cannot see how or where to add javascript to the coded pages. I want to add a few lines to create a random number function which can be called form other pages. I have the javascript working but where to put it?
sgreig
27 Dec 2012, 17:26You can't add code through the gui to a gamebook. You have to add it through the code editor. Also, Quest's gamebook mode doesn't support all the scripting and coding features of the text adventure mode either, just a heads up.
Cyrano
27 Dec 2012, 20:13I've been looking at the gamebook code via the view code option but if the mode will not support all features of JS then I might have to think of a simplified text adventure instead. Thanks for info.
Alex
28 Dec 2012, 12:52You should still be able to use JS in gamebook mode - the Editor probably won't show it though.
Cyrano
28 Dec 2012, 19:33Thanks for input but...I still cannot see how to implement JS in the viewed code. I can get the JS file to appear via add javascript but have no idea how to get it running at the game points I select. I have tried adding the JS code embedded within a HTML file but while the "insert" shows the required filename in the object code segment nothing happens when the game event occurs.
As the random number generator is probably a basic function to deal with events might it be possible to add one the list of available scripts.
As the random number generator is probably a basic function to deal with events might it be possible to add one the list of available scripts.
Alex
29 Dec 2012, 12:43Not exactly sure how you've got things set up - could you attach a zip file of your game aslx and JS?
Cyrano
01 Jan 2013, 16:09Alex,
Thanks for reply. Attached a zip containing a short demo game and JS and HTML files for the random number code. All I need to know is how to insert the code into the aslx file within any selected room object. I am a novice at both Quest and JS but can polish up the appearances once I get it running.
Any guidance will be most welcome.
David
Thanks for reply. Attached a zip containing a short demo game and JS and HTML files for the random number code. All I need to know is how to insert the code into the aslx file within any selected room object. I am a novice at both Quest and JS but can polish up the appearances once I get it running.
Any guidance will be most welcome.
David
Alex
01 Jan 2013, 16:43Here you go. I've manually added the javascript tag to the .aslx so it loads randomjs.js, and I've fixed randomjs.js so it's a proper JS file.
As an example, I added a "changedparent" script to the player object so it triggers the singledice function every time the player moves.
As you can see, gamebook mode is not really set up for this kind of thing so there are some manual hacks to make - but it shows that in principle you can get JS running from gamebook mode (as there's not really anything special about gamebooks - they just use a more limited standard library)
As an example, I added a "changedparent" script to the player object so it triggers the singledice function every time the player moves.
As you can see, gamebook mode is not really set up for this kind of thing so there are some manual hacks to make - but it shows that in principle you can get JS running from gamebook mode (as there's not really anything special about gamebooks - they just use a more limited standard library)
Cyrano
04 Jan 2013, 20:06Thanks a lot for the files etc. I think I can see that all you have added are the Changedparent lines, request line and javascript scr line.
If that is so then why wont these lines work when I add them to another block within another program?
<object name="para156">
<description><![CDATA[You charge the door with your shoulder. <br/><br/>Roll the dice...<br/><br/><br/><br/>]]></description>
<options type="stringdictionary">para343 = Even number;para92 = Odd number</options>
<changedparent type="script">
request (RunScript, "singledice; 6")
</changedparent>
</object>
<object name="para343">
<description><![CDATA[<br/><br/>The door bursts and you fall headlong into a room., <br/><br/>]]></description>
<options type="stringdictionary">para92 = Leave through the door</options>
</object>
<javascript src="randomjs.js" />
Thanks
If that is so then why wont these lines work when I add them to another block within another program?
<object name="para156">
<description><![CDATA[You charge the door with your shoulder. <br/><br/>Roll the dice...<br/><br/><br/><br/>]]></description>
<options type="stringdictionary">para343 = Even number;para92 = Odd number</options>
<changedparent type="script">
request (RunScript, "singledice; 6")
</changedparent>
</object>
<object name="para343">
<description><![CDATA[<br/><br/>The door bursts and you fall headlong into a room., <br/><br/>]]></description>
<options type="stringdictionary">para92 = Leave through the door</options>
</object>
<javascript src="randomjs.js" />
Thanks