Script Dictionary Case For Null
Liam315
27 Jul 2013, 10:41When adding verbs that require another object, is there a way to add a case for if the second object is not specified? i.e. rather than displaying a menu of possible second objects or printing a default expression, is there a way to run a script like you would for any defined object?
e.g. "pick nose using pencil" would run one script that you specify, but "pick nose" would also run another script in the same way.
e.g. "pick nose using pencil" would run one script that you specify, but "pick nose" would also run another script in the same way.

jaynabonne
27 Jul 2013, 11:22Could you please provide a simple snippet of code that exhibits the problem. I can't seem to even get something to behave the way you say (which I know is a deficiency on my part) in order to work out how to modify it.
Also, could you state your use case a bit: do you want just the two cases you list (e.g. with a specific object and then without any objects) or you do want to be able to use with a whole bunch of objects as well as none. If the former, sometimes a command is easier to use than a general verb.
Also, could you state your use case a bit: do you want just the two cases you list (e.g. with a specific object and then without any objects) or you do want to be able to use with a whole bunch of objects as well as none. If the former, sometimes a command is easier to use than a general verb.
Liam315
27 Jul 2013, 21:24jaynabonne wrote:Could you please provide a simple snippet of code that exhibits the problem. I can't seem to even get something to behave the way you say (which I know is a deficiency on my part) in order to work out how to modify it.
I haven't tried to do it yet so it's not like I have something that I can't get to work, I was just wondering if anyone else had tried. I know I can create a command and have done this in a few cases but I'd rather try and create a universal rule if I can.
The problem is when you select a verb from the object tree, under the "multiple object" rules you can only enter strings. I'm looking for a way to enter scripts. My theory is that by finding the built in function that handles the compiling of menus when a second object is not specified, I can insert a script there to get the desired effect.

jaynabonne
27 Jul 2013, 22:08That's handled in the "else" in the "scriptdictionary" case in the "script" attribute of "defaultverb". You'd have to bring that type up into your game and modify it to do what you want (depending on how you want to do it).
Liam315
27 Jul 2013, 22:13Cool, thanks for the tip
.

tbritton
08 Oct 2013, 19:03I got this partly working by modifying the else portion of HandleMultiVerb as follows. In this case the object default response will override the container response. You could reverse them to change that.
Then for every container I can add an attribute (defaultputcontainer) and have a different response for each container. Ditto for objects with defaultputobject.
I may need to add a test to see if the verb being used is "put" just to make sure I don't get odd responses if another verb is used with that object. Still working on that.
dictionary = GetAttribute(object, property)
if (DictionaryContains(dictionary, object2.name)) {
invoke (ScriptDictionaryItem(dictionary, object2.name))
}
else {
parameters = NewDictionary()
dictionary add (parameters, "object", object2)
if (DictionaryContains(dictionary, "default")) {
invoke (ScriptDictionaryItem(dictionary, "default"), parameters)
}
else {
if (HasAttribute ( object , "defaultputobject" ) ) {
msg (object.defaultputobject)
}
else if (HasAttribute ( object2 , "defaultputcontainer" ) ) {
msg (object2.defaultputcontainer)
}
else {
msg (default)
}
}
}
Then for every container I can add an attribute (defaultputcontainer) and have a different response for each container. Ditto for objects with defaultputobject.
I may need to add a test to see if the verb being used is "put" just to make sure I don't get odd responses if another verb is used with that object. Still working on that.
Liam315
09 Nov 2013, 03:17So I finally got around to having a look at this and sorting it out and eventually got it working. Thanks for all the help.
@tbritton -
Altering the HandleMultiVerb function doesn't help in the case I was originally describing as that function is only called once object2 has been defined. I was more interested in cases where object2 can be defined but a script (rather than string) response can be made if it isn't. Your code did help me though, I was banging my head against the wall because I couldn't get quest to recognize the script dictionary until I realized I'd not used GetAttribute.
For anyone who is interested in achieving this, here is a quick recap of the problem and (my) solution.
Situation: You have a verb that requires another object. e.g. kill orc (using object2). Quest gets you to add all the objects you can use to "kill orc." The author can specify different outcomes for each: kill orc with sword, kill orc with axe, etc.
The problem: When the player types "kill orc" without specifying a second object, a list of available objects are displayed for the player to choose from. But there is no option to set a script of your own devising to run instead of the selection menu.
The Solution:
- In the object tree select Advanced > Object Types, making sure that you have set the filter to view library elements.
- Highlight defaultverb and copy it in (the yellow bar that appears at the top of the screen).
- Select the "script" attribute, scroll down to the switch script and open the case for "scriptdictionary."
- Replace what is there with the following code:
Now the menu showing available objects will still show as before by default, but if you want to replace that with a script of your own devising, simply add a case called "default" in the relevant verb tab alongside the other objects that could be used.
@tbritton -
Altering the HandleMultiVerb function doesn't help in the case I was originally describing as that function is only called once object2 has been defined. I was more interested in cases where object2 can be defined but a script (rather than string) response can be made if it isn't. Your code did help me though, I was banging my head against the wall because I couldn't get quest to recognize the script dictionary until I realized I'd not used GetAttribute.
For anyone who is interested in achieving this, here is a quick recap of the problem and (my) solution.
Situation: You have a verb that requires another object. e.g. kill orc (using object2). Quest gets you to add all the objects you can use to "kill orc." The author can specify different outcomes for each: kill orc with sword, kill orc with axe, etc.
The problem: When the player types "kill orc" without specifying a second object, a list of available objects are displayed for the player to choose from. But there is no option to set a script of your own devising to run instead of the selection menu.
The Solution:
- In the object tree select Advanced > Object Types, making sure that you have set the filter to view library elements.
- Highlight defaultverb and copy it in (the yellow bar that appears at the top of the screen).
- Select the "script" attribute, scroll down to the switch script and open the case for "scriptdictionary."
- Replace what is there with the following code:
if (object2 <> null) {
HandleMultiVerb (object, this.property, object2, this.multiobjectdefault)
}
else {
verbname = this.name
dictionary = GetAttribute(object,verbname)
if (DictionaryContains(dictionary,"default")) {
invoke (ScriptDictionaryItem(dictionary,"default"))
}
else {
menu = NewStringDictionary()
objectlist = ListCombine (ScopeReachableInventory(), ScopeReachableNotHeld())
excludelist = NewObjectList()
list add (excludelist, game.pov)
list add (excludelist, object)
candidates = ListExclude(RemoveSceneryObjects(objectlist), excludelist)
if (ListCount(candidates) = 0) {
msg (this.multiobjectmenuempty)
}
else {
GenerateMenuChoices (menu, candidates)
game.pov.multiverb = this.property
game.pov.multiverbobject = object
game.pov.multiverbobjectdefault = this.multiobjectdefault
ShowMenu (this.multiobjectmenu, menu, true) {
if (result <> null) {
HandleMultiVerb (game.pov.multiverbobject, game.pov.multiverb, GetObject(result), game.pov.multiverbobjectdefault)
game.pov.multiverb = null
game.pov.multiverbobject = null
game.pov.multiverbobjectdefault = null
}
}
}
}
}
Now the menu showing available objects will still show as before by default, but if you want to replace that with a script of your own devising, simply add a case called "default" in the relevant verb tab alongside the other objects that could be used.