Work on Multimedia Fusion extensions

A few of my extensions have known problems with it. I don’t particularly enjoy working on these projects; actually, I pretty much hate it. I have much better things I could be doing. However,  I will try to make the changes when I can.

The known problems are:

Chart Object
  • No support for HWA, which means it doesn’t work in the latest version of MMF
  • No support for Unicode titles, etc.
Ini++
  • Crash to do with encryption
String Replacer
  • Suspected crash turned out to be due to a different object
Spell check Object
  • Lack of support for additional characters (such as accented characters)
String Replacer
  • Lack of support for additional characters (such as accented characters)

None of these will be much fun at all to work on, or particularly rewarding, so don’t expect progress to be quick. However, hopefully it will happen someday.

Spell checking a Sentence

From my previous post on the spell check object, you should now be able to list suggestions for a single word. How can we do this for a whole sentence?

If we have a string like “Hello, my name is Jack” we need to split it into separate words, remove the punctuation and then check each word in turn. We can then hi-light each incorrect word.

The problem is, that is boring and too much work. Surely an object whose sole purpose in life is to check spellings can handle a sentence? And the answer is yes! =)

The spell check object has ‘Auto-parse’ features, which are actually quite powerful. First, open MMF2 and insert a spell check object without changing any properties on the dialog box. Also, add an edit box, a button, and a list box. We wish to have the list box show all the incorrectly spelt words in the edit box when the button is clicked.

First, add an action to load a word-list at the start of frame. Now, we add the extra stuff.

When the button is clicked, first of all we want to clear the list. Next, call the “Autoparse -> Start” action, and put the text of the edit box as the text to parse.

What does this do then? Autoparse will take the text you put in, split it into individual words and then spell-check each word. If it comes across a word which is incorrect, it calls the event “On Incorrect Word” and pauses it so that you can do what you want. This might be showing a dialog with a list of spelling suggestions, or it might just be hi-lighting the text.

It is important to remember that the auto-parse is now paused, so it won’t continue until you call the “Resume Parse” action.

(Also note that you cannot run two auto-parses at the same time. Why? Because this would almost certainly cause bugs with your code so it was thought better to disallow it altogether.)

So for now we will just add the word to a list box. Add the “On Incorrect Word” event and add a line to the list box with the text from the expression “Autoparse -> Get Incorrect Word” (IncorrectWord$). Now also add the action “Resume Parse”. If you don’t do that, it won’t progress past the first spelling mistake!

You should get something that looks like this:

Now, you will notice that if you click the button twice in quick succession, an alert box will come up reminding you that you cannot start an autoparse when another one is already happening. To stop this happening, you can add the condition “Is Autoparse in progress?” and negate it:

Now, let’s try hi-lighting misspelt words instead. Remove the edit box and list box and insert a Rich Text box. We’ll still have it start an auto-parse when the button is clicked, this time with the text of the RTF object as the parameter.

Now on “On Incorrect Word”, it should do the following to the RTF object:

  1. Select the range of text that starts at “Get incorrect word start index” (IncorrectIndex) and carries on “Get incorrect word length” (IncorrectLen).
  2. Set the current range as bold

It should then resume the parse. You could make “On parse complete” make it unselect all the text.

This works but isn’t automatic. It is hard to get this working well in real-time because the RTF object is so slow. However, alternative objects like the Scintilla object offer hope. Anyway, that is something for you to do!

Now there are two other features I’d like to quickly mention.

The first is that if you change an incorrectly spelt word with the “Change last incorrect word” action, the object will keep track of it and you can use “Get corrected string” to return the whole string with the changes made in it. This helps you actually correct a string once you have spell checked it.

The next is that you can make autoparse automatically ignore incorrectly spelt words that don’t match certain conditions. For instance, if you didn’t want anything within quotes to be spell checked, to go the dialog box and on the “Auto-parse” tab make sure that “Ignore Keys” is selected. Then click “Add” and put a single quote in each box. Then try and spellcheck the string “xd xd ‘sd sd’ xd”. Notice that the the sd won’t turn bold – they have been ignored.

Likewise, you can make it only spell check certain things. For instance, if you only wanted things in brackets to be spell checked, then unselected “Spellcheck when neutral”, select “Spellcheck keys” and put a left bracket in the first box and a right bracket in the second box. Now if you try and spell check something, it will only be considered as possibly wrong if it is in brackets.

In fact, auto-parse is even more powerful than that and can be set up to spell check most programming languages. The reason for this is that when Spell check was developed, making HTML and other editors in MMF was very popular. That doesn’t seem to be the case any more, however.

Spellcheck Object Guide

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.

  1. ‘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.
  2. 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.

  1. 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.
  2. 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.