moo.sdk.direction_argument

moo.sdk.direction_argument(parser=None, *, after_prep=None)

Recover a direction name from the parser, tolerating direction-as-preposition.

Two of our direction words — up and down — are also registered prepositions. Player input like @dig up to The Loft parses up as a preposition with no indirect object, so the verb body’s get_dobj_str() returns empty even though the player clearly typed a direction. This helper checks the obvious slots in order:

  1. parser.get_pobj_str(after_prep) when after_prep is set and was matched with an indirect-object string (e.g. look through up where the through prep captured "up" as iobj_str).

  2. parser.get_dobj_str() (the default direction-as-dobj path).

  3. Any registered direction that appears as a parsed preposition with no iobj (the up/down-as-particle case).

  4. parser.words[1] when after_prep is None; or the word immediately following after_prep in parser.words otherwise. Used as a last-resort recovery.

Parameters:
  • parser – Parser instance. Defaults to context.parser.

  • after_prep – When set, look for the direction as the iobj or the word following this preposition (e.g. "through" for look through up).

Returns:

Lowercase direction string, or "" if none recoverable.