Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Is CreateMemblockFromFile The Best Method To Load Word Dictionary?

Author
Message
JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 30th Aug 2019 23:24
Hi,

We are working on our educational word spelling game now.

We use:
CreateMemblockFromFile
to read in a word dictionary(26 files, one for each letter)

Is above function the best method to use for above application?
Seems to work fine on HTML5 and Windows build
but on Android there is issue sometimes where the word files are not loaded?

Is there something else we need to do?
Let us know, thanks!

Jesse

JeZxLee
Fallen Angel Software
Video Game Design Studio
http://www.FallenAngelSoftware.com
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 31st Aug 2019 01:48
Android is filename case sensitive, where Windows isn't. Make sure you check you have an exact match with your filename spellings (i.e. if the file is called "LetterA.txt", then "lettera.txt" will work in Windows, but not Android. It MUST be "LetterA.txt").

Also, my personal preference for quickly loading and saving data is to use the json my_array.load("filename.json") and my_array.save("filename.json") commands (these can be found in the docs under "Guides>Arrays in version 2" I think). You just create an array of your user-defined type that fits your data, and it will get automatically populated for you with those commands. No memblocks required, or iterating through files one line at a time etc. It is a really useful feature that saves a lot of pain.
JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 31st Aug 2019 03:45
Hi,

Thanks for the reply...

Please look at attached A word file.
How would we use file with the JSON you recommended?

Thanks!

Jesse
JeZxLee
Fallen Angel Software
Video Game Design Studio
http://www.FallenAngelSoftware.com

Attachments

Login to view attachments
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 31st Aug 2019 10:05
First, replace the surrounding apostrophes ' with double quotes ". Otherwise, JSON won't work with the file.

Next, you need to modify the file so that it begins with an open bracket [, ends with a closing bracket ], and all the words are separated by a comma.
So the first few words of your file would look like this

Now all you need to do to load your dictionary in is to call the load method on the array.
MyArray.Load("Dictionary.json")

With multiple letters like you have, something like this would do.
(just typing this in, haven't actually tested it yet.



JeZxLee
7
Years of Service
User Offline
Joined: 15th Mar 2017
Location: Long Island, New York, United States, Earth
Posted: 31st Aug 2019 15:27
Hi,

I implement above.
Stuck on the word compare function below:
Get an error...

Jesse

JeZxLee
Fallen Angel Software
Video Game Design Studio
http://www.FallenAngelSoftware.com
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 1st Sep 2019 10:52 Edited at: 1st Sep 2019 10:55
FindString searches within a string, not an array. To search an array, use the find() method of the array. find() only works on sorted arrays, so after loading the array in LoadDictionaryLetterFIle function, just do a DictionaryString[DictionaryLetterLoading].sort() to make sure everything is in order. I would also suggest that you get rid of the '1' at the end of the file. You can always find the end with the length property. DictionaryString[Letter].length will always point to the last item in the array. Otherwise, the '1' will mess with the sorting and searching algorithms. So to see if a word is in the list, just do if DictionaryString[letterToCheck].find( Upper(currentWordSelected)) >= 0. Note the >= instead of just > as arrays start with index 0.

Login to post a reply

Server time is: 2024-10-01 10:22:08
Your offset time is: 2024-10-01 10:22:08