Corrupt aslx file
Mosh
24 Feb 2016, 13:18One of our pupils is close to finishing a small adventure she is working on for a class assignment, but during the last lesson found that she couldn't open the file any more. The error message below appears as soon as she tries to load it. Is there anything I can do to get rid of this as she has no earlier-stage backup versions?
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at TextAdventures.Quest.EditorController.GetElementTreeParent(Element o)
at TextAdventures.Quest.EditorController.AddElementToTree(Element o, Nullable`1 position, String name)
at TextAdventures.Quest.EditorController.AddElementAndChildrenToTree(Element o)
at TextAdventures.Quest.EditorController.UpdateTree()
at TextAdventures.Quest.Editor._Closure$__1._Lambda$__4()
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at TextAdventures.Quest.EditorController.GetElementTreeParent(Element o)
at TextAdventures.Quest.EditorController.AddElementToTree(Element o, Nullable`1 position, String name)
at TextAdventures.Quest.EditorController.AddElementAndChildrenToTree(Element o)
at TextAdventures.Quest.EditorController.UpdateTree()
at TextAdventures.Quest.Editor._Closure$__1._Lambda$__4()

XanMag
24 Feb 2016, 15:35I'm sure someone will be along to help with this, but unfortunately, I am not wise enough with Quest code. I did PM you however in an unrelated matter. Please check that out. Thanks and good luck!
HegemonKhan
24 Feb 2016, 15:59this sounds like an error with one of her 'list' or 'dictionary' Attributes, which throws all of the quest underlying code errors (that you're seeing) dealing with the handling of 'lists' or 'dictionary' Attributes. It looks like one of her 'key' fields in one of her 'list' or 'dictionary' Attributes has the error (maybe a typo/mispelled name of her Object/text that she is trying to refer to within the 'key' field of one of her 'list' or 'dictionary' Attributes, which would be a does-not-exist/can't-be-found type of error)
She just needs to open up the *.aslx quest file (hopefully, she has the file offline/on-desktop, if she's doing this online/web, you may need to pm Alex to get at the file/code of her uploaded game), any text software will open up (notepad, wordpad, notepad++, apple: text editor, etc) the *.aslx quest file, and trouble-shoot where her coding error is, and correct/fix it.
---------
This happens lots of times, especially when writing directly code in with quest, as you can easily make a mistake, creating an error at compile time, which keeps you from starting/playing your game or opening into the GUI~Editor, instead of a run-time error during game play. It's just a matter of opening up the quest file and finding/fixing your code error... not always easy (especially when it's a small typo), lol
-----------------------
from this error code:
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
in particular, the:
get_Item(TKey key)
does she have a:
TKey key
Object in her game (or a similar spelled/typed in Object)?
as this is where her error is at or in relation to, I think.
She just needs to open up the *.aslx quest file (hopefully, she has the file offline/on-desktop, if she's doing this online/web, you may need to pm Alex to get at the file/code of her uploaded game), any text software will open up (notepad, wordpad, notepad++, apple: text editor, etc) the *.aslx quest file, and trouble-shoot where her coding error is, and correct/fix it.
---------
This happens lots of times, especially when writing directly code in with quest, as you can easily make a mistake, creating an error at compile time, which keeps you from starting/playing your game or opening into the GUI~Editor, instead of a run-time error during game play. It's just a matter of opening up the quest file and finding/fixing your code error... not always easy (especially when it's a small typo), lol
-----------------------
from this error code:
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
in particular, the:
get_Item(TKey key)
does she have a:
TKey key
Object in her game (or a similar spelled/typed in Object)?
as this is where her error is at or in relation to, I think.
Mosh
24 Feb 2016, 16:04Just checking now. I've got her file to hand. We're using the offline version of Quest as it's one less login for them to forget the password for!
HegemonKhan
24 Feb 2016, 16:14err, my mistake, 'list' Attributes don't use a 'key' field, so you only need to look for your 'dictionary' Attributes
-----------------
here's the (syntax) documentation for 'dictionary' Attributes:
http://docs.textadventures.co.uk/quest/ ... aries.html
and specifically for your troubleshooting needs (if the code error exists within the 'dictionary' Attribute itself):
http://docs.textadventures.co.uk/quest/ ... onary.html (String Dictionary Attribute)
http://docs.textadventures.co.uk/quest/ ... onary.html (Object Dictionary Attribute)
http://docs.textadventures.co.uk/quest/ ... onary.html (Script Dictionary Attribute)
-------------
for example of a possible cause of the error:
(quest is case sensitive)
say she has an Object named (ID'ed) as:
Key1
in code:
but in her Object Dictionary Attribute, named 'key_dict', she accidentally names her 'key' Object as:
key1 // which is NOT the same as: Key1
in code:
so quest tries to find an Object named 'key1', but no such Object exists for it to use with the Object Dictionary operations she using/doing, so you get the errors seen, quest is throwing all the underlying code errors in trying to handle an Object Dictionary, with an incorrect 'key' field input, as that 'key1' Object input doesn't exist, so quest can't handle an unexisting Object with its Object Dictionary and thus any operations that use that item in the Object Dictionary.
-----------------
here's the (syntax) documentation for 'dictionary' Attributes:
http://docs.textadventures.co.uk/quest/ ... aries.html
and specifically for your troubleshooting needs (if the code error exists within the 'dictionary' Attribute itself):
http://docs.textadventures.co.uk/quest/ ... onary.html (String Dictionary Attribute)
http://docs.textadventures.co.uk/quest/ ... onary.html (Object Dictionary Attribute)
http://docs.textadventures.co.uk/quest/ ... onary.html (Script Dictionary Attribute)
-------------
for example of a possible cause of the error:
(quest is case sensitive)
say she has an Object named (ID'ed) as:
Key1
in code:
<object name="Key1">
// blah Attributes
</object>
but in her Object Dictionary Attribute, named 'key_dict', she accidentally names her 'key' Object as:
key1 // which is NOT the same as: Key1
in code:
<object name="Key1">
// blah Attributes
</object>
<object name="Key2">
// blah Attributes
</object>
<object name="Key3">
// blah Attributes
</object>
<attr name="key_dict" type="stringdictionary">
<item>
<key>key1</key>
<value>1</value>
</item>
<item>
<key>Key2</key>
<value>2</value>
</item>
<item>
<key>Key3</key>
<value>3</value>
</item>
</attr>
so quest tries to find an Object named 'key1', but no such Object exists for it to use with the Object Dictionary operations she using/doing, so you get the errors seen, quest is throwing all the underlying code errors in trying to handle an Object Dictionary, with an incorrect 'key' field input, as that 'key1' Object input doesn't exist, so quest can't handle an unexisting Object with its Object Dictionary and thus any operations that use that item in the Object Dictionary.
Mosh
24 Feb 2016, 16:17I've had a search and there's no "Tkey key". Shame, that would have been an easy fix!
I'll have a dig through the links you posted when I get home. I've got until Friday morning to fix it for her
I'll have a dig through the links you posted when I get home. I've got until Friday morning to fix it for her

HegemonKhan
24 Feb 2016, 16:31I could be wrong as to the cause/error codes, I still don't know quest and all of its error codes that well... I tried to help...
(if you/she don't mind and/or depending on school policy on a student's/school's/teacher's Intellectual Property), you can copy and paste her entire code in a post for us to troubleshoot it for her, trying to find the issue/cause of her error(s), or you can pm it to one of the mods (I don't have the time, being a student myself, I got school work to do, programming classes, lol) and they'll privately try to find/fix it up the error(s) for you.
to put it into the post's code box (which keeps the formatting of your game code, and keeps your post from being massive wall), here's the syntax:
[code.]your pasted entire game code here[/code.]
but without the dots/periods in the brackets, which will/should produce or look like this:
don't worry, someone (such as Pixie, or any the moderators) who know coding and quest better will be able to help you get this fixed up (hopefully before friday, lol)
(if you/she don't mind and/or depending on school policy on a student's/school's/teacher's Intellectual Property), you can copy and paste her entire code in a post for us to troubleshoot it for her, trying to find the issue/cause of her error(s), or you can pm it to one of the mods (I don't have the time, being a student myself, I got school work to do, programming classes, lol) and they'll privately try to find/fix it up the error(s) for you.
to put it into the post's code box (which keeps the formatting of your game code, and keeps your post from being massive wall), here's the syntax:
[code.]your pasted entire game code here[/code.]
but without the dots/periods in the brackets, which will/should produce or look like this:
your pasted entire game code here
don't worry, someone (such as Pixie, or any the moderators) who know coding and quest better will be able to help you get this fixed up (hopefully before friday, lol)
HegemonKhan
24 Feb 2016, 16:44maybe this might be the issue:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
she needs to add her 'TKey key' to the dictionary... for example:
(also, using spaces in the 'names' (IDs) can cause issues with quest trying to parse them correctly)
though your search didn't find any ' TKey key ' ... hmm, try different variations of spelling... Tkey key, tKey key, etc..
or maybe just try searching for 'key' and see if you come across something resembling 'TKey key'...
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
she needs to add her 'TKey key' to the dictionary... for example:
<object name="Key1">
// blah Attributes
</object>
<object name="Key2">
// blah Attributes
</object>
<object name="Key3">
// blah Attributes
</object>
<attr name="key_dict" type="stringdictionary">
// missing item input for the 'Key1' Object, which some part of her game code operations needs to use; didn't add her Key1 to the dictionary
<item>
<key>Key2</key>
<value>2</value>
</item>
<item>
<key>Key3</key>
<value>3</value>
</item>
</attr>
(also, using spaces in the 'names' (IDs) can cause issues with quest trying to parse them correctly)
though your search didn't find any ' TKey key ' ... hmm, try different variations of spelling... Tkey key, tKey key, etc..
or maybe just try searching for 'key' and see if you come across something resembling 'TKey key'...
Mosh
24 Feb 2016, 20:01I did a search just for "tkey" using Wordpad and it only came across two instances, both in the middle of a function name (GetKeywordsMatchStrength). I made sure the search wasn't case sensitive so those are definitely the only ones.
I'll check for object names/IDs with spaces in and see if I can spot anything else. I'm not used to looking at code view, but I guess this is a chance to learn! Fortunately, the program's not too large. Large enough, though, that I can't paste or attach it to a forum post. Boo.
I'll check for object names/IDs with spaces in and see if I can spot anything else. I'm not used to looking at code view, but I guess this is a chance to learn! Fortunately, the program's not too large. Large enough, though, that I can't paste or attach it to a forum post. Boo.
Mosh
24 Feb 2016, 20:02Wasn't sure if the forum would take ZIP files. It seems that it does...

jaynabonne
24 Feb 2016, 20:31I've seen this before. Unfortunately, it seems all too easy to make happen...
The basic problem is that a runtime game save has been saved over the original source. This usually happens due to a confusion (in my opinion) in the desktop interface - if you're in the editor and hit Save, it saves your game that you're writing. If you do File/Save while running the same game, it wants to save the game in progress instead, and if you happen to point it back to your original source, you overwrite that by mistake with something that isn't loadable by the editor. (At least, that's what I think happens.) If you open the game in a text editor, you'll see Quest actually knew the original game's name. It would be nice if it asked if you were really sure you wanted to overwrite the original with the saved game if it detects it's the same file.
It might be possible to extract the original game from the saved game (I hope). I'll take a stab at it. Unless anyone else has any other ideas...
The basic problem is that a runtime game save has been saved over the original source. This usually happens due to a confusion (in my opinion) in the desktop interface - if you're in the editor and hit Save, it saves your game that you're writing. If you do File/Save while running the same game, it wants to save the game in progress instead, and if you happen to point it back to your original source, you overwrite that by mistake with something that isn't loadable by the editor. (At least, that's what I think happens.) If you open the game in a text editor, you'll see Quest actually knew the original game's name. It would be nice if it asked if you were really sure you wanted to overwrite the original with the saved game if it detects it's the same file.
It might be possible to extract the original game from the saved game (I hope). I'll take a stab at it. Unless anyone else has any other ideas...

The Pixie
24 Feb 2016, 20:38What you have uploaded is a save game file (as I see Jay noted), not the actual game file. It may be the the error is just because you are trying to open that up in Quest. Nevertheless, I have extracted the original game from the file, apart from a command called K4, which seemed to be giving problems.
This file will open and you can play the game.
This file will open and you can play the game.
Mosh
24 Feb 2016, 20:45Would be hugely appreciated!
I did have one boy in the class who'd done exactly that, or at least saved the game while testing and then erased his "program" file. In that case it gave a very different error, if I recall correctly, though I can't remember what it was. Mind you, I'm pretty certain that the file suffix was different in that case. Ah, memory fails me. Dealing with almost 80 kids doing this assignment so apologies if I get a little muddled!
Pixie: thank you so much. I'll give this a whiz now. I was looking through the code and spotted this "k4" thing which seems to be an alias/renaming for the "give to" command, for some reason. If her "give" puzzle doesn't work, we know why. If the method of fixing this issue is easily documented, I'd be happy to learn how so that I don't need to call on you again in future!
I think there's a learning point here for myself - ensure the pupils recognise that saving in design and test mode produces different files! Strange, this is the third year we've run the course and they've never done this before... and then I get two children in one class doing the same/similar thing.
I did have one boy in the class who'd done exactly that, or at least saved the game while testing and then erased his "program" file. In that case it gave a very different error, if I recall correctly, though I can't remember what it was. Mind you, I'm pretty certain that the file suffix was different in that case. Ah, memory fails me. Dealing with almost 80 kids doing this assignment so apologies if I get a little muddled!
Pixie: thank you so much. I'll give this a whiz now. I was looking through the code and spotted this "k4" thing which seems to be an alias/renaming for the "give to" command, for some reason. If her "give" puzzle doesn't work, we know why. If the method of fixing this issue is easily documented, I'd be happy to learn how so that I don't need to call on you again in future!
I think there's a learning point here for myself - ensure the pupils recognise that saving in design and test mode produces different files! Strange, this is the third year we've run the course and they've never done this before... and then I get two children in one class doing the same/similar thing.

jaynabonne
24 Feb 2016, 21:00Pixie, I ended up with the same mysterious k4 verb. (I have a game that loads as well, but you beat me to it.
)
But I found something else strange about that k4. I tried to recreate it in an empty game to see if I could get a syntax it liked, but whenever I tried to name a new verb "k4", it said an element with that name already existed. The same for k1, k2, k3, etc. (k0 was fine.) I did a search in the Quest core, and I didn't find it anywhere. A bit of a mystery there.

But I found something else strange about that k4. I tried to recreate it in an empty game to see if I could get a syntax it liked, but whenever I tried to name a new verb "k4", it said an element with that name already existed. The same for k1, k2, k3, etc. (k0 was fine.) I did a search in the Quest core, and I didn't find it anywhere. A bit of a mystery there.

XanMag
24 Feb 2016, 21:17As a teacher myself, I'm always amazed at how creative kids are at finding new ways to screw stuff up! 

Mosh
24 Feb 2016, 21:30Tell me about it. Test, re-test, document, tweak, test... and they still find something you've not thought of. Shouldn't we be stifling this creativity somehow?

jaynabonne
24 Feb 2016, 21:31For anyone interested, I think this code in the Quest source points to it:
It's generating unique internal IDs for (I think) editor-related items. Which probably means it's not a good idea to name something "k" + a number, as who knows what grief that might cause!
(Sorry, I went off on a tangent.)
private string GetUniqueId()
{
m_nextId++;
return "k" + m_nextId.ToString();
}
It's generating unique internal IDs for (I think) editor-related items. Which probably means it's not a good idea to name something "k" + a number, as who knows what grief that might cause!
(Sorry, I went off on a tangent.)
HegemonKhan
25 Feb 2016, 09:04mischief, is the engine of innovation 
(if males didn't fool around, we wouldn't have our modern technological world)

(if males didn't fool around, we wouldn't have our modern technological world)