[Help] Deactivating/Activating a Verb.

Hi all,

I'm new here. My name's Josh. I'm Autistic and I enjoy all things IT. I'm planning on doing a Robotics/AI degree but I would like to do some game design as a hobby hence why I'm here on Quest. (Side Note: I'm a bit of a noob when it comes to game design so my apologies if my question/s are frustrating)

I'm trying to test out how to do different things before I dive into making my game. One of the things I'm trying to figure out how to do is allowing a verb to be shown when the user clicks on the object link if the item is in their inventory. If it isn't in their inventory, then the item cannot 'cook'.

My other question is if anyone has the answer to the above, would the same type of logic apply if the user typed in 'cook eggs' instead of clicking the link to 'cook' the specific object.

Thank you and I look forward to engaging with this community. :)


One of the things I'm trying to figure out how to do is allowing a verb to be shown when the user clicks on the object link if the item is in their inventory. If it isn't in their inventory, then the item cannot 'cook'.

If you're talking about the menu, or the verb buttons in the side panes, these are controlled by the three lists displayverbs, inventoryverbs, and generatedverbslist.

  • displayverbs and inventoryverbs are edited on the object's "Object" tab
  • generatedverbslist is automatically created based on the object's "Verbs" tab when the object is first seen.
  • If you want to control which verbs are shown in the menu, you can check "Disable automatically generated display verb list for this object", which causes generatedverbslist to be ignored. You can then manually add your verbs to displayverbs and inventoryverbs to control which verbs are displayed depending on whether the player is holding the object.
  • Conversely, if you check "Only display verbs from this object's Verbs tab" it will ignore displayverbs and inventoryverbs.

Note that this only controls the menu; it won't stop the player typing the verb on the command line. So if you want to stop a verb being used in some circumstances, you should make sure to start that verb's script with an 'if' statement. Something like:

if (ListContains (ScopeReachableInventory (), this)) {
  // do whatever is necessary to cook the object
}
 else {
  msg ("You need to pick it up first.")
}

Note that in this example I used ScopeReachableInventory rather than ScopeInventory. The only real difference between these two is when the object is inside a closed container in the inventory. (For the most part, "reachable" is the objects that a player can do things with)
For further clarification, in case you haven't come across it yet: the special variable this refers to the object that owns a script. In a verb, that's usually the object that has the verb, in a room enter/exit script this will be the room, and in a command script this will be the command.

It is also possible to remove a verb, but in most cases this is much more effort than just having the verb check the conditions itself.
For example, if an object has a cook verb and you want to remove it, you could do:

someobject.cook = null

This deletes the verb entirely. If the player attempts to use the verb after that, they will get the default "You can't cook it." message. However, it would still be on the menus unless you manually remove it; so you would also want to do:

if (HasAttribute (someobject, "generatedverbslist")) {
  if (ListContains (someobject.generatedverbslist, "cook")) {
    list remove (someobject.generatedverbslist, "cook")
  }
}
if (ListContains (someobject.inventoryverbs, "cook")) {
  list remove (someobject.inventoryverbs, "cook")
}

(In this case I used someobject as a placeholder for the object whose verb you want to remove)

And if you want to add back a verb which has been removed, you would have to recreate it:

someobject.cook => {
  // Script for the verb
}

and add it back to the list:

if (not ListContains (someobject.inventoryverbs, "cook")) {
  list add (someobject.inventoryverbs, "cook")
}

It can sometimes be useful to change which verbs are in the lists to be displayed. However, actually removing a verb from the object is usually more work than just making the verb check whether it can be used, so it can display a message otherwise.

I hope that makes sense.


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

Support

Forums