Reputation: 45
I created this game in AS3 that displays a word in English and 4 possible translations in French. It loads all the words from an XML file, and works without any problem (pool of about 1000 words in both languages).
What I wanted to do is to keep track of the words that generated mistakes so that I can present them again until my students get them correct, while at the same time 'marking' the words that have already been used with success so that they do not appear again.
I thought about this long and hard, googled it and did not come with anything interesting. So here is the ideas that I came up with, feel free to comment and point me in the right direction please.
My vocab XML file looks like this
<VOCAB>
<ENGLISH> The dog </ENGLISH>
<FRENCH> Le chien </FRENCH>
<VOCAB_ID> 0458 </VOCAB_ID>
<VOCAB_CATEGORY> 12 </VOCAB_CATEGORY>
</VOCAB>
IDEA1: Include an extra XML tag in my existing file that will keep track of it all. ADVANTAGE: saves me loading 2 XML objects and work on them concurrently. Smaller file size DRAWBACK: only 1 player can use the game, as score becomes tied to vocab file (but I could create duplicates vocab files for additional players)
<VOCAB>
<ENGLISH> The dog </ENGLISH>
<FRENCH> Le chien </FRENCH>
<VOCAB_ID> 0458 </VOCAB_ID>
<VOCAB_CATEGORY> 12 </VOCAB_CATEGORY>
<SCORE> -2 </SCORE> // Negative number indicates fails, zero = never used, pos number = success
</VOCAB>
IDEA2:Create a brand new XML file just for the sake of keeping the score ADVANTAGE: could have infinite number of players, each with their own score file. Keeps vocab and score two separate things. DRAWBACK: will have to do some clever programming so that the whole XML file is not parsed for every new word of vocab chosen by the game which would slow things down
<TRACKING>
<VOCAB_CATEGORY> 12 </VOCAB_CATEGORY>
<VOCAB_ID> 0458 </VOCAB_ID>
<SCORE>-2</SCORE> // Negative number indicates fails, zero = never used, pos number = success
</TRACKING>
What do you think?
Upvotes: 0
Views: 351
Reputation: 45
OK I cracked it eventually.
The vocab list loads as an XML object, and when a word is correctly guessed, its node is being deleted from the XML. This way I ensure that correct words are not asked ever again.
At the same time, a text variable keeps tab of all the answers given (correct or not or skipped), formatted as XML (but kept as a string) which the user can save when he wants.
When a new game starts, this file is loaded (if present), and the past correct answers are removed from the XML object as soon as this one is loaded.
In terms of performance, I have 1500+ nodes in the file and see no degradations as of yet.
Upvotes: 0
Reputation: 1181
Feedback:
It was smart of you to include a "vocab_id", this gives you a unique key to use as identifier in some sort of "lookup-table" or database.
In regards to which way to pursue this error, if it was me, I would definitely separate the answers from the words. This gives you the possibility to do whatever you want to do, since the "original file" containing the words will not be "cluttered" with a lot of different result data.
You have every possibility to create mapping between users responses and words thanks to your vocab_id.
How you want to store data doesn't really matter at this point. If you do it in xml you can easily sometime in the future put all that data into a database. Most important for the moment is to make sure you save data and store it somewhere safe. (Git/Svn, backups etc.)
In the future it might be smart to start using some sort of databases to store all data. But if you keep working with xml you can just create some small program that populates database with data from xml.
I think as next step you should either create a xml file for each individual user where you store what words they have answered and maybe what they answered on each word or create one xml-file containing all users and answers.
<words>
<vocab id="458" word="the dog">
<answer timestamp="..">le dog</answer>
<answer timestamp="..">la dog</answer>
<answer timestamp="..">le chien</answer>
</vocab>
<vocab id="404" word="foo">
..
</vocab>
</words>
Upvotes: 2
Reputation: 1151
I would also recommend json over xml. Json is much smaller in memory than xml. XML is good if you your implementation has no idea of the structure and needs to parse specific childs etc. If your code knows the complete structure, then JSON is way faster (with flash native json)
Upvotes: 0
Reputation: 1804
Looking at the number of words and players, I would not use XML. I would use a SQLite database. You can easily keep track of scores then per player. Next to that you can make everything relational with foreign keys.
Upvotes: 0