DictionaryContains error

Greetings fellow Quest coders.

I'm currently working on a small gamebook project which is non-linear and allows the player to acces previous pages. To do this, i'm using a rather simple script executed at the start of each page:

player.LastPage = player.Now
player.Now = player.parent
AddPageLink (player.parent, player.LastPage, "Previous Page")
AddPageLink (player.parent, MainHub, "Main Menu")

(I've seen people here using NewStringDictionary instead, but that's too messy for my taste for what is supposed to be a simple feature.)

The good news is that this works smoothly, and in case in which the last page is the Main Menu, you only get one link instead of two doing exactly the same.

The bad thing: whenever the game is started, it throws up two ugly errors:

Error running script: Error compiling expression 'DictionaryContains(source.options, destination.name)': Variable does not refer to an object: 'destination'
Error running script: Error compiling expression 'destination.name': Variable does not refer to an object: 'destination'

At first i thought this is because the game tries to reference a last page when there is none, but further scrutinity reveales this must be somehow connected to the HandleCommand function in GamebookCore.aslx . I'm defenitly not experienced enough to fiddle with the GamebookCore.aslx, and i have no idea what causes these errors.

So could anyone help me and explain what's going wrong, and how to do better? Help is highly appreciated, and thanks in advance.


Okay, i found a workaround on my own, but it's not exactly elegant.

if (player.parent = Intro) {
  player.Now = MainHub
}

(This is included before the script i described above)

This works around the error by making the game refer to an non-null value. It's not what i hoped for, but it gets the job done. And, let's be honest, this won't impact performance to a measurable degree.


That does not make sense as you describe it. Your new code is:

if (player.parent = Intro) {
  player.Now = MainHub
}
player.LastPage = player.Now
player.Now = player.parent
AddPageLink (player.parent, player.LastPage, "Previous Page")
AddPageLink (player.parent, MainHub, "Main Menu")

If the player is in the intro, player.Now gets set to Mainhub, but then gets set to Intro before you do anything with it, so the end result is exactly the same as you had originally. Or is there some intervening code?


If the player is in the intro, player.Now gets set to Mainhub, but then gets set to Intro before you do anything with it,

No, it's for the player.LastPage = player.Now. Otherwise, the first time it's run LastPage would be set to null, which generates the error quoted in the first post.


Thanks, had not spotted that!


Exactly what mrangel said. Seems like the errors came from the game trying to set a value to a value that wasn't defined then. (Still don't get what the second error means though.)

By setting the previous page to be the Main Menu, i'm abusing the fact that using AddPageLink will not generate a link to the same object/page twice, and instead modifies the existing entry. In this case, changes it to read "Main Menu" instead of "Previous Page". I honestly don't know if that is a feature or a bug, but since i discovered this a while ago i'm making use of it to put flavour into my games.


Log in to post a reply.

Support

Forums