ID:1123698
 
(See the best response by DarkCampainger.)
Code:
atom/proc/ParseMatch(Name, multi, ignorecase)
var/list/theKeywords = getKeyWords();
for(var/entry in theKeywords)
if(ignorecase)
Name = lowertext(Name)
entry = lowertext(entry)
if(multi && (Name == entry || copytext(entry,1,length(Name)+1)==Name)) return TRUE
else if(Name == entry) return TRUE
return FALSE


Problem description:

Okay so I am working on a text mud and basically there is something in AbyssDragon's parser that allows you to target mobs with just the first letter of their name but there is a bug to this if you type the command for example 'blast ' notice the space after the blast it will attack the nearest mob i am trying to make it stop doing this can anyone with some parser experience please help?
Best response
I don't see a "getKeywords()" procedure in his library, but assuming not too much is different:

If you just want to fix the immediate problem, you can change that one line to this:
if(multi && (Name == entry || (length(Name) && copytext(entry,1,length(Name)+1)==Name))) return TRUE


The problem is that you're getting a token that's an empty string. This token makes its way into ParseMatch() as Name. Then when it runs a copytext() it's copying entry from 1 to the length(Name)+1, which is just 1 because Name is empty. copytext() from 1 to 1 returns an empty string (because the end is exclusive, not inclusive) which is equal to, you guessed it, Name. So you just gotta check that name has a length before comparing it to the matching portion of entry.

Alternatively, you can change his tokenizer to not give you an empty token in the first place, but this may have side-effects depending on how you use his library:
        Tokenize(string)
var/tokens[] = list(), current, quotes = 0
while(length(string))
var/char = copytext(string, 1, 2)
if(char == "\"")
current += char
quotes = !quotes
else if(char != " " || quotes) current += char
else if(length(current) > 0) // Only add the token if it isn't empty
tokens += current
current = ""
string = copytext(string, 2)
if(length(current) > 0) tokens += current // Only include the last token if it has a length
return tokens
Thanks a lot man this helped me so much.

and yeah the getkeywords thing is something i added to npc's so they could match with a list of possible names. also items etc.