changing an objects description after using verb
Gmarcroft
27 Apr 2020, 09:46I want to change the description of an object following an interaction with the object by the character:
I have a bed, the description says that is messy and my character has the option to tidy the bed. I have set the tidy up verb using a script to show a message and then I want to run additional scripts that 1. remove the tidy verb from the object so the character can't repeatedly tidy the bed and 2. allow me to change the description of the object so that it reflects the new state of the object (now tidy). How can I do this?
mrangel
27 Apr 2020, 10:42There are 3 main ways to go about changing a description.
1. The 'look' script
You can make the bed's description be a script. Then you can check if the verb has been run yet, and show a different description accordingly. You could check if the verb has been removed - but it's usually better to set a flag, so that
msg ("It's your bed. You sleep here.")
if (GetBoolean (this, "istidy")) {
msg ("It looks a lot better now the sheets are properly straightened.")
}
else {
msg ("The sheets are all rumpled, half on the bed and half on the floor. You really should {command:tidy bed:tidy it up}.")
}
2. Text processor
The text processor makes it easier to have an object description that varies depending on game events. Similar to the above:
It's your bed. You sleep here. The sheets are really {either GetBoolean (bed, "istidy"):neat:messy} right now.
Note that in this version, the blue bed indicates the name of the object, not it's alias. In method 1 I used this instead to refer to the current object, but I think the text processor doesn't let you use this in a look description.
In both of these cases, it's checking a flag to see if the bed is tidy. So the verb script would look something like:
if (GetBoolean (this, "istidy")) {
msg ("The bed is already tidy. You don't need to do it again.")
}
else {
msg ("You tidy the bed.")
this.istidy = true
}
3. Changing the description
This can be simpler, but runs into problems if an object has multiple ways in which it can be changed.
The verb script in this case would just have an extra line with the new description:
if (GetBoolean (this, "istidy")) {
msg ("The bed is already tidy. You don't need to do it again.")
}
else {
msg ("You tidy the bed.")
this.istidy = true
this.look = "Your bed. It looks a lot better now that it's tidy."
}
Removing the verb
In the scripts above, I've got it so that the "tidy" verb will generate a sensible message if the player tries to do it twice.
If you also want to remove it from the dropdown menu, you can use add the line:
this.generatedverbslist = ListExclude (this.generatedverbslist, "Tidy")
The way displayed verbs are handled is actually quite weird. There are three lists:
displayverbs
is used when the player is in the room with an object. It can be edited on the object's "Object" tab.inventoryverbs
is used when the player is carrying the object. It can be edited on the object's "Object" tab.generatedverbslist
is an extra list which is generated automatically from the verbs on the object's "Verbs" tab.
On the "Object" tab, ticking "Disable automatically generated display verb list for this object" will ignore generatedverbslist
; in which case you can put all the verbs onto the lists manually, and remove the verb from displayverbs
when you want to remove it. Ticking "Only display verbs from this object's Verbs tab" will cause it to use generatedverbslist
only.
Actually removing the verb
If you want to actually remove the Tidy verb from the bed, you can do that. This will mean that you get the standard response "I can't tidy it" when you try to tidy the bed. Your verb script would look like:
msg ("You tidy the bed.")
this.tidy = null
this.generatedverbslist = null
Note that I set this.tidy
to null; deleting the script from the object. But then I also need to set this.generatedverbslist
to null, otherwise it would still appear on the menus and verb buttons. Setting this.generatedverbslist
to null forces the Quest engine to regenerate the command.
If you are using this version with the text processor code above, you'd want to change GetBoolean (bed, "istidy")
to HasScript (bed, "tidy")
- there's no need to have a flag as well when you can just check for the presence of the verb.
Gmarcroft
28 Apr 2020, 09:51Wow thank you so much for such a comprehensive answer. I'll have a try and see how I get on. Thank you!!! :)