Require antother Object: problem to exclude unnecessary items

  1. created the verb "interact" (new verb)
  2. select "require another object"

Now too many objects appear in the list: static objects scenario, inventory objects...
I would like to exclude many items...also a container/menu incorporated on inventory (weapon menù)

EVERYTHING appears in the numbered list (when choosing the object)

Solution: if player is carrying the object.... ecc
But it's automatic ... too easy, there's no choice (ex. multiple keys)


You can change how the menu is generated by modifying the verb's script; but this might be a bit of a pain to do. It would probably make more sense to make this a command rather than a verb, which gives you more control.


Basically, a 'verb' is just a command with a default script, which is inherited from the type defaultverb.

So you could make a command whose script is similar to that, and it would act like a verb.
For example, you could make a command "interact" with the regex pattern ^interact (?<object>.+?)(\s+with\s+(?<object2>.*))?$ - which allows the player to enter "interact key" or "interact key with door", which I think is the same as a verb with the "require another object" type.

You would give it a script something like:

switch (TypeOf (object, "interact")) {
  case ("script") {
    do (object, "interact")
  }
  case ("string") {
    msg (object.interact)
  }
  case ("scriptdictionary") {
    if (IsDefined ("object2")) {
      HandleMultiVerb (object, "interact", object2, this.multiobjectdefault)
    }
    else {
      candidates = NewObjectList()
      foreach (candidate, RemoveSceneryObjects(ScopeReachableNotHeld()) {
        if (not (candidate = game.pov or candidate = object)) {
          if (some condition here) {
            list add (candidates, candidate)
          }
        }
      }
      if (ListCount (candidates) = 0) {
        msg ("There's nothing it can interact with here.")
      }
      else {
        this.object = object
        ShowMenu ("What do you want to interact it with?", candidates, true) {
          if (result <> null) {
            HandleMultiVerb (interact.object, "interact", GetObject (result), interact.multiobjectdefault)
          }
        }
      }
    }
  }
  default {
    msg ("You can't interact with that!")
  }
}

That's a cut-down and simplified version of how verbs work; it should work just like a verb, except that you can replace some condition here with whatever restrictions you want, to control whether or not each candidate appears in the menu.

If you're doing this in the web editor and you want to be able to use the "Verbs" tab for the object, you would create "interact" as a normal verb, and then in your start script you would put:

interact.script => {
  the script above goes here
}

This basically takes an existing verb (which is recognised as a verb by the editor, so it's easy to add to objects), and then changes its behaviour when the game starts so that it will show fewer objects in the menu.


If you want to restrict the list to just objects that the particular object can interact with, your some condition here would be DictionaryContains (object.interact, candidate.name).

In this version, the menu only considers visible, reachable, non-scenery objects in the room. If you want to change this, you could change ScopeReachableNotHeld to ScopeReachableInventory, ScopeReachable, or ScopeVisible


Log in to post a reply.

Support

Forums