MatchCommand (FUNCTION) - KVonGit/quest5-stuff GitHub Wiki

  <function name="MatchCommand" parameters="command" type="dictionary"><![CDATA[
    candidates = NewObjectList()
    foreach (cmd, ScopeCommands()) {
      if (IsRegexMatch(cmd.pattern, command, cmd.name)) {
        list add (candidates, cmd)
      }
    }
    maxstrength = -1
    thiscommand = null
    foreach (candidate, candidates) {
      strength = GetMatchStrength(candidate.pattern, command, candidate.name)
      if (strength >= maxstrength) {
        skip = false
        if (thiscommand <> null) {
          if (thiscommand.parent <> null and candidate.parent = null) {
            skip = true
          }
        }
        if (not skip) {
          thiscommand = candidate
          maxstrength = strength
        }
      }
    }
    if (thiscommand = null) {
      return (null)
    }
    else {
      return (QuickParams ("command", thiscommand, "stuff", Populate(candidate.pattern, command)))
    }
  ]]></function>
⚠️ **GitHub.com Fallback** ⚠️