Changing/Disabling Verbs

suzums
10 Mar 2013, 23:42
Is there a way to enable/disable/change verbs on the fly?

For example, my character has a car, and I want him to have the option of slashing the tires, but only after some events take place.

In other words, I want to hide the "Slash tires" verb until it's needed.

I tried this:
list add (car.displayverbs, "Slash tires")

But I got this error:

Error running script: Cannot modify the contents of this list as it is defined by an inherited type. Clone it before attempting to modify.



And even if this did work, it wouldn't prevent people from just typing "Slash tires."

How would I do this?

TriangleGames
11 Mar 2013, 00:45
I'm not sure how that cloning trick would work, there may be a better solution there that others can explain to you.
As for keeping "slash tires" off the display list, right now I believe the only way to do that is turn off the feature that auto-generates the verb lists (meaning you have to add the verbs yourself, allowing you to leave out the ones you want to hide). It's on the "Room Descriptions" tab of the game object. This would not solve adding the verb later, however. The players would just have to know that they can type "slash tires."

To make "slash tires" not work until the right time, I would just use an IF statement that checks whether a flag is set,
then set the flag when the events occur that lead up to slashing the tires.

suzums
11 Mar 2013, 04:30
So I figured out a workaround, by deleting the "Take" verb from the car object. Somehow that made the displayverbs attribute not "inherited" anymore, and allowed list add to work.

I came across another problem though. Using IsRegexMatch on a string list causes Quest 5.4 beta to crash.

Pertex
11 Mar 2013, 07:15
suzums wrote:I came across another problem though. Using IsRegexMatch on a string list causes Quest 5.4 beta to crash.


Could you post a sample or even better, add a n issue to the tracker http://quest.codeplex.com/workitem/list/basic

HegemonKhan
11 Mar 2013, 07:41
to add verbs:

This makes a new list (if you have autogenerate turned off):

<displayverbs type="list">verb1;verb2;etc</displayverbs>
<inventoryverbs type="list">verb1;verb2;etc</inventoryverbs>


This adds more~extra verbs to your already existing list (if you don't want these verbs to exist immediately, then turn off the autogenerate):

<displayverbs type="listextend">verb1;verb2;etc</displayverbs>
<inventoryverbs type="listextend">verb1;verb2;etc</inventoryverbs>


here's the script to add a verb:

(replace "boolean_attribute" to whatever you want to use)

(place this script where ever you want it)

<create_slash_tires_verb type="script">
if (game.pov.boolean_attribute = true) {
game.pov.displayverbs = split ("slash_tires","")
}
</create_slash_tires_verb>


two ways to make lists:

split ("verb1;verb2;etc",";")

~or~

game.pov.displayverbs = NewStringList ()
list add (game.pov.displayverbs,"verb1")

game.pov.inventoryverbs = NewStringList ()
list add (game.pov.inventoryverbs,"verb1")

or you can combine lists if you don't want to lose old verbs:

http://quest5.net/wiki/Using_Lists

hopefully this helps! if not, let me know, or if you want this in~for the GUI, let me know!

jaynabonne
11 Mar 2013, 10:28
With respect to the cloning problem, when you have inherited types, the list or dictionary is the shared type attribute. It is effectively read-only. In order to modify it, you need to create a modifiable list in the object itself. There is a trick for this.

When you assign a list or dictionary to an object, Quest will make a copy of that list or dictionary. (That has caused me the occasional frustration when I forgot!) So to "clone" the list, as odd as it seems, just do this:

car.displayverbs = car.displayverbs

That will assign the current list attribute to a clone/copy of itself, making it modifiable.

levicki
11 Mar 2013, 12:45
@jaynabonne:
That's a great tip! It should be in the wiki.

suzums
11 Mar 2013, 21:15
jaynabonne wrote:With respect to the cloning problem, when you have inherited types, the list or dictionary is the shared type attribute. It is effectively read-only. In order to modify it, you need to create a modifiable list in the object itself. There is a trick for this.

When you assign a list or dictionary to an object, Quest will make a copy of that list or dictionary. (That has caused me the occasional frustration when I forgot!) So to "clone" the list, as odd as it seems, just do this:

car.displayverbs = car.displayverbs

That will assign the current list attribute to a clone/copy of itself, making it modifiable.


That is good to know. An excellent and helpful tip. Thanks!

Once the displayverbs list is no longer read-only the list add method works easy enough.

Since IsRegexMatch doesn't work, is there a way to check to see if a string matches the contents of a list without doing a foreach?

jaynabonne
11 Mar 2013, 21:29
ListContains? :)