Require another object

I realise this is a basic question for code savvy people but.
Is it possible for a non coder to eliminate the list of miscellaneous objects that appear when setting up a verb with require another item
I.e. . hit man
With what object
1 table
2 door
3 wallpaper
And just restrict it to certain objects ( club?) or say there’s nothing suitable.

)


I would expect this a standard feature, but it doesn't seem to be. This is one of the reasons I would disagree with the way Getcope was split up in Quest 5.8 – I can see a way to handle it more logically, but it would mean replacing a couple of the core functions. (I would have made it so that multiverbs can have a scope attribute in the same way commands do, to specify what they can be used with)

It should be possible to write up a command script that you can copy and paste for this; but I don't have time to work on that right now (as I haven't finished writing a chapter that's supposed to be posted today). But if you want me to work on it, I can give it a shot when I have a little more time.


The way I do stuff is easier and simple :

Make a new global command (the very top "command" menu on the online left menu bar list) called : hit man

I tend to add additional possible things people may type onto the 1 command i.e. hit man;punch man;kill man;kick man

Now you have control of "hit man" as a command.

So you decide what happens and what conditions there are by using the choice of multiple "scripts" available. "if" scripts are very handy.

e.g. if object "bat"is not visible....print message : You need a weapon (bat) to hurt this person. He is too powerful to fight with your bare hands.

You can have fun deciding the rules of what a player can and cannot do based on your scripts guiding the player.

Hope that helps.


If you make your own command, it gives you a lot more flexibility than a verb.

The basic structure would be a command with a pattern that looks like ^(hit|attack)\s+(?<object>.+)(\s+(with|using)\s+(?<object2>.+))?$. That allows the player to enter "hit man" or "hit man with bat".

Then you'd have a script something like:

if (IsDefined ("object2")) {
  // the player has entered "hit man with bat" or similar
}
else {
  // no weapon specified
}

Now, if you want it to behave like a verb, where every person you can hit has the same script, you'd fill that in with something similar to the defaultverb script:

if (HasAttribute (object, "hit")) {
  params = QuickParams ("target", object, "this", object)
  action = object.hit
  if (IsDefined ("object2")) {
    dictionary add (params, "weapon", object2)
  }
  else {
    object2 = null
  }
  switch (TypeOf (action)) {
    case ("string") {
      game.text_processor_variables = params
      msg (action)
    }
    case ("script") {
      invoke (action, params)
    }
    case ("scriptdictionary") {
      if (object2 = null) {
        if (DictionaryContains (action, game.pov.name)) {
          invoke (ScriptDictionaryItem (action, game.pov.name), params)
        }
        else {
          options = NewObjectList()
          foreach (weapon, ScopeReachableInventory()) {
            if (DictionaryContains (action, weapon.name)) {
              list add (options, weapon)
            }
          }
          if (ListCount (options) = 0) {
            msg ("You haven't got anything to hit " + object.article + " with.")
          }
          else if (ListCount (options) = 1) {
            // If there's only one option, we don't need to show a menu
            do (hit, "script", QuickParams ("object", object, "object2", ListItem (options, 0)))
          }
          else {
            hit.target = object
            SuppressTurnScripts()
            ShowMenu ("What do you want to hit " + object.article + " with?", options, true) {
              do (hit, "script", QuickParams ("object", hit.target, "object2", GetObject (result))
            }
          }
        }
      }
      else {
        if (not ContainsReachable (game.pov, object2)) {
          msg ("You haven't got that.")
        }
        else if (not DictionaryContains (action, object2.name)) {
          if (DictionaryContains (action, "default")) {
            invoke (DictionaryItem (action, "default"), params)
          }
          else {
            msg ("That's not something you can hit " + object.article + " with.")
          }
        }
        else {
          invoke (DictionaryItem (action, object2.name), params)
        }
      }
    }
  }
}
else {
  msg ("That's not something you can hit.")
}

That should give you a menu something like what you want.
If you want to change the behaviour of the default verb but still have the ability to tweak stuff on the object's "Verbs" tab and have it do the usual verb magic, you could go to full code view, find the bit with all the <verb … /> lines, and add:

  <verb template="hit" property="hit" response="DefaultHit">
    <script><![CDATA[
      Insert the code block here
    ]]></script>
  </verb>

Or if you're using the online editor, in your game start script you would put:

hit.script => {
  Insert the code block here
}

This should make it so that it will only present you with a menu of the objects that are actually available for that verb.

Hope that works… writing on my phone again, so haven't tested it.


Thank you both. I never thought of using commands instead of custom verbs. Much better. I think iantommo’s way is adequate to my simple programming. But thank you mrangel for taking all that trouble.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums