Gamebook Advice

Joey
09 Mar 2013, 01:43
Hello!

I'm wanting to make a gamebook using Quest. I've figured out all the core-functionality (it's very easy to get to grips with) and I feel I could easily make a hyper-text work. But if I just wanted to make hypertext games, I'd be using HTML, or Twine if I was feeling fancy. What I'd like to be able to do is have choices set values which then unlock other choices at later dates. Variable text based on existing values would also be nice, but I guess not essential.

So, basically, what is the easiest way I can do this?

Cheers!

levicki
09 Mar 2013, 02:33
You can use scripts in gamebooks in Quest 5.4. There is a beta available for testing.

Joey
09 Mar 2013, 02:50
Thanks. I downloaded and investigated and I've figured out how to make variables change when you view different pages. Is there a script option for adding or removing links to pages?

levicki
09 Mar 2013, 03:12
Joey wrote:Thanks. I downloaded and investigated and I've figured out how to make variables change when you view different pages. Is there a script option for adding or removing links to pages?


Page links are stored in a "simplestringdictionary" called "options" for each page, the way to deal with adding them dynamically is as follows:

<script type="script">
dictionary add (this.options, "Page2", "My link to page 2")
dictionary add (this.options, "Page3", "My Link to page 3")
</script>


As to how to display the links afterwards, I figured that out too, the problem is -- it's a hack.

Currently I see no API that can output page links either directly or as a string to a variable which you could print.

Furthermore, if you set page type to a script you are on your own -- you would have to handle video, frame image, page links, etc manually.

Currently, the easiest (and most likely the only) way to do it is to add a function MyDoPage() which will for the most part be an exact replica of DoPage() found in GamebookCore.aslx minus the script execution part which would just create recursion if you keep it.

This is MyDoPage() function code, the easiest way to add it is to open your .aslx file using Notepad and paste the code right above the closing </asl> tag, and then reload the file from Quest:

<function name="MyDoPage" parameters="page"><![CDATA[
request (ClearScreen, "")
stop sound
if (HasString(player.parent, "sound")) {
if (LengthOf(player.parent.sound) > 0) {
play sound (player.parent.sound, false, false)
}
}
if (HasString(player.parent, "picture")) {
if (LengthOf(player.parent.picture) > 0) {
picture (player.parent.picture)
msg ("")
}
}
if (HasString(player.parent, "youtube")) {
if (LengthOf(player.parent.youtube) > 0) {
JS.AddYouTube (player.parent.youtube)
msg ("")
msg ("")
}
}
msg (player.parent.description)
msg ("")
msg ("")
if (TypeOf(player.parent, "options") = "stringdictionary") {
foreach (key, player.parent.options) {
destination = GetObject(key)
if (destination = null) {
msg (StringDictionaryItem(player.parent.options, key) + " (broken link)")
}
else {
if (DoesInherit(destination, "link")) {
msg ("<a href=\"" + destination.address + "\">" + StringDictionaryItem(player.parent.options, key) + "</a>")
}
else {
msg (CommandLink(key, StringDictionaryItem(player.parent.options, key)))
}
}
msg ("")
}
}
set (player.parent, "visited", true)
]]></function>


Once you have a function, calling MyDoPage(this) at the end of your page script will render the page:

<script type="script">
dictionary add (this.options, "Page2", "My link to page 2")
dictionary add (this.options, "Page3", "My Link to page 3")
MyDoPage (this)
</script>


Here is a demo showing this code in action:


There will probably be a better and more official way to do this in the future, assuming that someone makes a feature request.