[Adv3] parsing string to game object

Looking at the code, I can’t figure out how or where exactly the parser does this itself. Is it possible for me to start with a string, say ‘red ball’, and end up with the red ball game object?

If I tokenize that string is there a parser function or two that I could call that would get me the results I am after? I need this for a few command structures where a game object appears in gLiteral but I need to know what that item is to fully parse the command.

Trying to parse what the parser is doing is just giving me a headache.

1 Like

I’ve hacked together something using cmdDict.findWord. It basically checks each word of the string as either an adjective or a noun depending on its placement in the string. This will get me either the object in question or a list of objects that I can try to narrow down or disambiguate against. This might be the only way to do this.

If there is a more direct way to do this, I still would like to hear it.

modify String
toObject() {
    local temp,lst = new Vector,prev = [],str = Tokenizer.tokenize(self);
    for (local i = 1, local cnt = str.length() ; i <= cnt ; ++i) {
        if (i < cnt) temp = cmdDict.findWord(getTokVal(str[i]),&adjective);
        else temp = cmdDict.findWord(getTokVal(str[i]),&noun);
        foreach(local x in temp) {
            if (dataType(x) != TypeObject) continue;
            lst.append(x);
        }
        if (lst.length == 1) return lst[1];
        temp = prev.subset({y: lst.indexOf(y) });
        if (temp.length == 1) return temp[1];
        prev = lst.toList;
        lst.setLength(0);
    }
    return temp;
}
;