Okay ... I found the problem. It was actually pretty simple ... in the script you have a variable called 'maxstrength' which you set to 0 ....
Then you have a function GetKeywordsMatchStrength that compares the keywords and the user input and generates a strength ... as long as the GetKeywordsMatchStrength is greater than the maxstrength ... then it 'matches' ... unfortunately, you are never modifying the maxstrength variable ... it always stays as 0 .... so ANY match regardless of how good it is, will overwrite a previous match.
Here is my modified function:
<function name="DoAskTell" parameters="object, text, property, defaultscript, defaulttemplate"><![CDATA[
handled = false
maxstrength = 0
match = null
text = LCase(text)
if (typeof(object, property) = "scriptdictionary") {
dictionary = GetAttribute(object, property)
foreach (keywords, dictionary) {
if (GetKeywordsMatchStrength(LCase(keywords), text) >= maxstrength) {
match = ScriptDictionaryItem(dictionary, keywords)
maxstrength = GetKeywordsMatchStrength(LCase(keywords), text)
}
}
if (match <> null) {
invoke (match)
handled = true
}
}
if (not handled) {
if (HasScript(object, defaultscript)) {
do (object, defaultscript)
}
else {
msg (DynamicTemplate(defaulttemplate, object))
}
}
]]></function>
This solves the main problem I brought up ... although pertex made me think of a different problem. General versus specific matching ... (keycard versus red keycard)
Since I used a >= ... if two items have the same strength, it will keep replacing the match until it gets to the last one in the series.
I.e.
Item One - Keys : Red Keycard
Item Two - Keys : Blue Keycard
Item Three - Keys : Keycard
if I just use the > operator, then if the users input is "ask about keycard" ... the output will match the first item in the list (so in this case : red keycard), and then ignore any other match ... but thats not really what we want.
We want it to match the generic 'keycard' item ... so by using >=, and putting Keycard as the last item, then if the user just inputs ask about keycard ... the system will run the 'keycard' script.
Its really half a dozen of one/six of the other ... either way it forces you to modify the position of what you want to match 'in general' versus 'in specific'.
This is not really ideal, but it will do for now. I will continue to tinker with this and if I get a better solution together, I'll post it.