Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Found a new issue regarding spaces in the parser :)

As an example, in English the insertInto pattern is `(put|insert|stick) (.+) (?:in) (.+)`. If given an input like "insert bone into hole", Parser correctly generates an action object even though the pattern matches the input exactly. This is because the initial match is skipped:

if(
    sorgente != this.commands &&
    override != this.override.commands &&
    input.indexOf(" ") == -1 &&
    (obj.singolo === undefined || obj.singolo == false)
){
    let matches = input.match(new RegExp("^"+pattern+"$", 'i'));
    if( matches != null)
        return input;
}

The input contains spaces, so the above logic is skipped due to `input.indexOf(" ") != -1`. Otherwise, there would be a match and the raw input would be returned directly.

It appears the presence of the space is used to indicate whether this is an action and/or potentially has subjects. Unfortunately, since there are no spaces in Chinese, any inputs that match the pattern enter the above logic and return a string, not an action object. As an example, we would enter the Chinese equivalent of "insertboneintohole" and Parser.parse will return the string instead of the action.

How would you recommend adjusting the logic to handle this? I'm not sure if it is safe to remove the `input.IndexOf(" ") == -1` condition.

My fix right now is to remove the initial check (that was copied in the previous post). This avoids looking for spaces to detect the presence of a subject when `sorgente` is the set of verbs.

Then, right before the following return statement

// Rirotno un oggetto contenente l'azione e i soggetti
return {
    verb: chiave,
    actionObject: obj,
    command: sorgente == this.commands, //patternEsatto == true,
    subjects: subjects
}

I added the subject check:

if(
    sorgente != this.commands &&
    override != this.override.commands &&
    (obj.singolo === undefined || obj.singolo == false)
) {
    if( subjects.length == 0)
        return input;
}
// Rirotno un oggetto contenente l'azione e i soggetti

Ok I think your solution can work... just test it :)

Thanks for validating!

I did a play-through with no issues, this solution should be good to go for any other languages that have the same problem 😊

perfect :D