So it seems that nobody is too sure how to use the Spellcheck object. It is a pro-only extension, and it never had a step-by-step tutorial, so here one is. It is based on my post on the Clickteam Forums.
Stage 1: Load a dictionary
Obviously the spell-checker doesn’t work without a dictionary. Luckily, the example pack comes with two dictionaries. We’ll just use the smaller word list for now, but there is a larger one too. The larger dictionary includes some common spelling errors itself as it is based on common search terms, and so is best avoided.
Insert the object into the frame and don’t change anything on the dialog box. Most of these settings are only required for advanced use, and you won’t need any for a while yet.
Now, create a ‘Start of frame‘ condition and add the Spellcheck action ‘Load Wordlist (Pauses MMF)‘, as shown in the screenshot below:
Choose ‘Smaller Wordlist.nswl‘ as the dictionary, which, as mentioned earlier, can an be downloaded as part of the example pack.
If you run the program, nothing happens. That is because it loads the dictionary, and then does nothing with it. If you are running on a particularly slow computer, or loading the file from a slow location, you might see a delay whilst it loads, but that is it.
We got to make it do something. Hence, stage 2.
- ‘NSWL’ stands for ‘Null separated word list‘. This means that each word in the dictionary is separated by a ‘null character’. (ASCII value 0). Words can also be separated by new lines, but as a new line in Windows is 2 characters using null characters saves a little bit of space.
- It is also OK to load one dictionary then another, and the object will then have a dictionary with both the details.
Stage 2: Checking if a word is in the dictionary
We can check if a word is in the dictionary by using the ‘Is Word correct?’ condition. So, let us make an edit box with a button which tells us what is the case.
Insert the button and edit box into the frame as you normally would. We wish to make to events: One which fires when the button is clicked and the word in the edit box has been spelled correctly, and the other when it is clicked but is not. For this, we will use the “Is Word Correct?” condition:
Add the condition “On Button Clicked” + “Is [Text of edit box] correct?” and provide some effect, like setting a string to “Is in dictionary”. Then have the same event but with the second condition negated and have it do something like set a string to “Is not in dictionary”. It should look something like this:
Run it and hopefully you will see that, for instance, “Hello” is in the dictionary but “Hellop” is not.
- For more advanced use you can load it in the background with the ‘Load Wordlist in Background‘ action and update a progress bar using ‘LoadingPercentage‘ expression, but for now we’ll just let it pause your program whilst it is loading. The frame cannot change before it has finished loading, though! Change the example so that it does it that way.
- All Spellcheck objects share the same dictionary, so if you load it on the first frame and use it again on the second, you don’t need to reload it. Test this by loading the dictionary and checking the words in different frames.
Stage 3: Getting suggestions
Now this is not very exciting. However, we can get suggestions using the object. To do this, you get the incorrectly spelt word and pass it to “List Suggestions” action. This doesn’t directly do anything, but it does cause the ‘On Correction Suggestion‘ event to get triggered once per suggestions.
So add a list box, and when an incorrect word is found you should clear the list box it and then call ‘List suggestions’, adding the suggestion to the list each time. Use the ‘Suggestions -> Get Suggestions’ (Suggestion$) expression to get the name of the current suggestion.
Download this as an example here
Tweak the settings on the first page of dialog box to change how the results are returned.
The Next Step
The next step is to spell-check sentences. This is explained in Part II.