Issues with put verb
tbritton
27 Sept 2013, 19:00I'm finding disparities with the put verb between the command line and the hyperlink interface. I've attached my game file with a test room that will show what I'm describing.
The room has a player, two containers (barrel and bowl) and two objects (apple and orange). For the apple all I did was add put to the inventory verb list. For the orange I added the put verb (with a script) to the object. With the script, you can put the orange in the barrel, but not the bowl and you get 10 points if you put it in the barrel. I selected disable automatically generated display verb list for this object.
First the apple. With the links if I select apple->put it says, "you can't put it." I do not get a list of objects to select from, which I would think would be the default behavior. If I type "put apple" it says, "you can't put it." If I type "put apple in barrel" it says, "done" and moves the apple.
Now the orange. If I use the links I can select put (it provides a list of objects) and can put it in the barrel, but not the bowl. Which is according to my rules, and I get 10 points.
If I type "put orange" I then get a list of objects and when clicking on an object everything works as it should.
If I type "put orange in barrel," it puts the orange in the barrel, but does not give the points. If I type "put the orange in the bowl" it allows me to do so, but according to my rules it should not allow this. I presume it is using the default verb instead of the one I created.
I would think the links and command line for the apple should act the same. Ditto for the orange. Is this behavior a bug or a feature? Also, I would think put should be part of the use/give tab since there will typically be an object required. I have not played with use/give yet so don't know if this would solve the issues.
I presume the solution is to modify the default verb, but also wanted to raise the issue of the inconsistencies in behavior.
The room has a player, two containers (barrel and bowl) and two objects (apple and orange). For the apple all I did was add put to the inventory verb list. For the orange I added the put verb (with a script) to the object. With the script, you can put the orange in the barrel, but not the bowl and you get 10 points if you put it in the barrel. I selected disable automatically generated display verb list for this object.
First the apple. With the links if I select apple->put it says, "you can't put it." I do not get a list of objects to select from, which I would think would be the default behavior. If I type "put apple" it says, "you can't put it." If I type "put apple in barrel" it says, "done" and moves the apple.
Now the orange. If I use the links I can select put (it provides a list of objects) and can put it in the barrel, but not the bowl. Which is according to my rules, and I get 10 points.
If I type "put orange" I then get a list of objects and when clicking on an object everything works as it should.
If I type "put orange in barrel," it puts the orange in the barrel, but does not give the points. If I type "put the orange in the bowl" it allows me to do so, but according to my rules it should not allow this. I presume it is using the default verb instead of the one I created.
I would think the links and command line for the apple should act the same. Ditto for the orange. Is this behavior a bug or a feature? Also, I would think put should be part of the use/give tab since there will typically be an object required. I have not played with use/give yet so don't know if this would solve the issues.
I presume the solution is to modify the default verb, but also wanted to raise the issue of the inconsistencies in behavior.

jaynabonne
27 Sept 2013, 20:47So many issues... I hope I get them all.
First, I see you have created a "put" verb. I'm not really sure how a pattern of just "put" works (usually it would be something like "put #object#"), but there must be something built into Quest to flesh out the pattern.
Now, there is also a default *command* for put, which has pattern "^put (?<object1>.*) (on|in) (?<object2>.*)$", which means it matches things like "put apple in bowl", "put apple on bowl", "put orange on apple", etc, but not something like "put apple". So when you use the "in" variant, it is matching that command and bypassing your code altogether.
If you change your verb to this, then it will override the command:
To do that in the editor, click on the verb, change Pattern to "Regular expression" instead of "Command pattern", and then input:
^put (?<object>.*) (on|in) (?<object2>.*)$|^put (?<object>.*)$
This will force both cases to go through your verb. You do need to actually provide a "put" implementation for the apple object, though. Otherwise, it's not put-able, regardless of what the display verbs say. (It used to sort of work before because the put *command* didn't care and just put things for you.)
First, I see you have created a "put" verb. I'm not really sure how a pattern of just "put" works (usually it would be something like "put #object#"), but there must be something built into Quest to flesh out the pattern.
Now, there is also a default *command* for put, which has pattern "^put (?<object1>.*) (on|in) (?<object2>.*)$", which means it matches things like "put apple in bowl", "put apple on bowl", "put orange on apple", etc, but not something like "put apple". So when you use the "in" variant, it is matching that command and bypassing your code altogether.
If you change your verb to this, then it will override the command:
<verb>
<property>put</property>
<defaultexpression>"You can't put " + object.article + "."</defaultexpression>
<pattern type="string"><![CDATA[^put (?<object>.*) (on|in) (?<object2>.*)$|^put (?<object>.*)$]]></pattern>
</verb>
To do that in the editor, click on the verb, change Pattern to "Regular expression" instead of "Command pattern", and then input:
^put (?<object>.*) (on|in) (?<object2>.*)$|^put (?<object>.*)$
This will force both cases to go through your verb. You do need to actually provide a "put" implementation for the apple object, though. Otherwise, it's not put-able, regardless of what the display verbs say. (It used to sort of work before because the put *command* didn't care and just put things for you.)

jaynabonne
27 Sept 2013, 21:02By the way, thank you *very* much for providing the sample file. That made it so much easier to work out. 

tbritton
27 Sept 2013, 21:37Thanks jaynabonne. I'll give that a try and see how it works. I was just surprised that in both cases the command line and the links worked differently.

jaynabonne
27 Sept 2013, 22:00They work the same for me in both cases.
That sounds like the apple works the same for you as well. And you don't say what the orange does, but I suspect it's the same as well. It basically must be - it just causes "put X" to be input as if you had typed it.
With the links if I select apple->put it says, "you can't put it." I do not get a list of objects to select from, which I would think would be the default behavior. If I type "put apple" it says, "you can't put it."
That sounds like the apple works the same for you as well. And you don't say what the orange does, but I suspect it's the same as well. It basically must be - it just causes "put X" to be input as if you had typed it.
tbritton
27 Sept 2013, 22:01Works perfect. Thanks again.
tbritton
28 Sept 2013, 23:57One last (I hope) small issue. Can I prevent items from being put unless they are in the players inventory?

jaynabonne
29 Sept 2013, 00:33You could add an "if" for object.parent = player. Else spit out some message.
tbritton
29 Sept 2013, 23:23I've dug into this a little more and it appears when you add put as a verb (as you described above) it kind of breaks the put command in regards to that object. For example, the default put command only works if you are holding the object but once I add the put verb this no longer works. I tried the else statement to the object as you described and that doesn't work.
I've read through the put command logic and other parts of it also break once you add a put verb to an object.
At this point I've got it working by copying the default put command into my game and modifying it. Just want to make sure that I'm not missing a better way to solve the problem. By the time I get done with the game I'll have an extremely complex put command.
Also is there a way to control what can be put into a given container other than modifying the put command, which I can get to work but want to make sure I'm not missing something obvious.
I've read through the put command logic and other parts of it also break once you add a put verb to an object.
At this point I've got it working by copying the default put command into my game and modifying it. Just want to make sure that I'm not missing a better way to solve the problem. By the time I get done with the game I'll have an extremely complex put command.
Also is there a way to control what can be put into a given container other than modifying the put command, which I can get to work but want to make sure I'm not missing something obvious.
HegemonKhan
30 Sept 2013, 00:00I'm sure I've seen someone code a way to have both a Command and Verb of the same action work at the same time...
both the Command and Verb has to have this Attribute, "property", if I did see this done by someone:
I don't think so, your "rules" scripts have to be apart (scripts of) the action ("put" verb~command~script) itself. The only other way I can think of is this:
The Object that you don't want to put the Object inside of:
foreach (object_x, object.objectlist) {
-> if (Contains~HasAttribute (object.child, "attribute") {
->-> MoveObject (object.child, object.parent)
-> }
}
though this would be after the object is a child (within) of the object that you don't want it to be in or added to... meh...
I'll have to think on this a bit more... lol
both the Command and Verb has to have this Attribute, "property", if I did see this done by someone:
<command name="play_video_games_command">
<property>play_video_games</property>
<pattern>pvg</pattern>
<script>
// blah coding
</script>
</command>
<verb name="play_video_games_verb">
// blah coding
<property>play_video_games</property>
// blah coding
</verb>
<object name="blah">
<inherit name="editor+object" />
// blah coding
// see your Verb below
<play_video_games_script type="script">
// blah coding
</play_video_games_script>
<displayverbs type="simplestringlist">play_video_games_script</displayverbs>
</object>
tbritton wrote:Also is there a way to control what can be put into a given container other than modifying the put command, which I can get to work but want to make sure I'm not missing something obvious.
I don't think so, your "rules" scripts have to be apart (scripts of) the action ("put" verb~command~script) itself. The only other way I can think of is this:
The Object that you don't want to put the Object inside of:
foreach (object_x, object.objectlist) {
-> if (Contains~HasAttribute (object.child, "attribute") {
->-> MoveObject (object.child, object.parent)
-> }
}
though this would be after the object is a child (within) of the object that you don't want it to be in or added to... meh...
I'll have to think on this a bit more... lol
tbritton
30 Sept 2013, 00:07Thanks HegemonKhan, I'll play around with the code you provided on using verb and command with same name.
HegemonKhan
30 Sept 2013, 00:51I may not have the syntax~format correct, and it might not work at all, but I was sure I saw someone code for being able to have a verb and command work independently for the same action.
here's some links:
http://quest5.net/wiki/Command_element
http://quest5.net/wiki/Verb_element
http://quest5.net/wiki/Object_element
http://quest5.net/wiki/Displayverbs
http://quest5.net/wiki/Inventoryverbs
There's a (default) "put" Command, but there's no (default) "put" Verb, so you have to create a Verb yourself, and I believe that it is the "property" attribute (attribute name), which is the "connector" of a Command and a Verb, along with the "displayverbs" and~or "inventoryverbs" stringlist attributes of the parent Object, which also contains the script attribute of the action of the Verb and Command. Also, maybe it's the "pattern" attribute being set~added within the Verb Element, that connects it with the Command Element too, for them to both work... I'm sure there's some way to do it, one of these ways, lol
Command -> Script
Command -> property
Command -> pattern
Verb -> Script
Verb -> pattern
Verb -> property
Object -> Script
Object -> displayverbs and~or inventoryverbs
here's some links:
http://quest5.net/wiki/Command_element
http://quest5.net/wiki/Verb_element
http://quest5.net/wiki/Object_element
http://quest5.net/wiki/Displayverbs
http://quest5.net/wiki/Inventoryverbs
There's a (default) "put" Command, but there's no (default) "put" Verb, so you have to create a Verb yourself, and I believe that it is the "property" attribute (attribute name), which is the "connector" of a Command and a Verb, along with the "displayverbs" and~or "inventoryverbs" stringlist attributes of the parent Object, which also contains the script attribute of the action of the Verb and Command. Also, maybe it's the "pattern" attribute being set~added within the Verb Element, that connects it with the Command Element too, for them to both work... I'm sure there's some way to do it, one of these ways, lol
Command -> Script
Command -> property
Command -> pattern
Verb -> Script
Verb -> pattern
Verb -> property
Object -> Script
Object -> displayverbs and~or inventoryverbs
tbritton
30 Sept 2013, 17:33By default when a verb is added with the name put it is given the property of "Put." According to the wiki it should then inherit any scripts from the command Put. I can get this to work, but as mentioned in my first post the behavior is different between using links or the command line.
I have attached a sample file with the verb put added for the apple. The script allows you to put the apple in the barrel, but not the bowl. If you put the apple in the barrel, you get a custom message and the owl disappears.
Here's the differences between the links and the command line.
Type put apple in bowl.
Game says Done and moves the apple to the bowl. (incorrect behavior, should not allow)
Type: put apple
Game responds with object list.
Click on bowl and game says "The bowl is full." (correct)
Click on apple, select put and you get object list.
Click on bowl and game says "The bowl is full." (correct)
Type put apple in barrel.
Game says Done, moves apple to barrel, but does not remove owl. (incorrect, owl should be removed and custom message displayed)
Click on apple, select put and you get object list.
Click on barrel and game says "You put the apple in the barrel," moves the apple to the barrel and removes the owl. (correct)
To me this seems like a bug in that typing put apple in bowl should work the same as using the links to do the same thing. Ditto for the barrel. If I only used links everything works as expected. If I use only the command line things break.
I have attached a sample file with the verb put added for the apple. The script allows you to put the apple in the barrel, but not the bowl. If you put the apple in the barrel, you get a custom message and the owl disappears.
Here's the differences between the links and the command line.
Type put apple in bowl.
Game says Done and moves the apple to the bowl. (incorrect behavior, should not allow)
Type: put apple
Game responds with object list.
Click on bowl and game says "The bowl is full." (correct)
Click on apple, select put and you get object list.
Click on bowl and game says "The bowl is full." (correct)
Type put apple in barrel.
Game says Done, moves apple to barrel, but does not remove owl. (incorrect, owl should be removed and custom message displayed)
Click on apple, select put and you get object list.
Click on barrel and game says "You put the apple in the barrel," moves the apple to the barrel and removes the owl. (correct)
To me this seems like a bug in that typing put apple in bowl should work the same as using the links to do the same thing. Ditto for the barrel. If I only used links everything works as expected. If I use only the command line things break.

jaynabonne
30 Sept 2013, 18:01The reason why is because with the links you're going through the "put" verb. When you type, you're going through a command. It may look the same, but it's not. If you type "put x in y" that is not using the put verb. If you choose "put" on an object from the links, it is going through the put verb, period, regardless of whether you choose a target object or not. There is no "put in" verb on an object.
Try this:
- Add this line to your game file:
This will gut the default "put x in y" command.
- Go to your "put" verb, and change "with; using" in the "Object separator" field to "in". That way, it will match "put x in y".
That will route all commands through your verb. The basic problem has always been that the default "put x in y" command does not do what you want (or does things you don't want). The only way to have it be consistent is to get rid of that. You may have to code some things yourself in your put verb, but... that's life.
(I suspect this is akin to what I suggested you do before. It will have the same effect. You simply can't use the default command if you want to prevent things in certain cases. That means you will have to make sure you are carrying the object, etc if that's what you want.)
Try this:
- Add this line to your game file:
<command name="put" />
This will gut the default "put x in y" command.
- Go to your "put" verb, and change "with; using" in the "Object separator" field to "in". That way, it will match "put x in y".
That will route all commands through your verb. The basic problem has always been that the default "put x in y" command does not do what you want (or does things you don't want). The only way to have it be consistent is to get rid of that. You may have to code some things yourself in your put verb, but... that's life.

(I suspect this is akin to what I suggested you do before. It will have the same effect. You simply can't use the default command if you want to prevent things in certain cases. That means you will have to make sure you are carrying the object, etc if that's what you want.)
tbritton
30 Sept 2013, 21:55jaynabonne wrote:The reason why is because with the links you're going through the "put" verb. When you type, you're going through a command. It may look the same, but it's not. If you type "put x in y" that is not using the put verb. If you choose "put" on an object from the links, it is going through the put verb, period, regardless of whether you choose a target object or not. There is no "put in" verb on an object.
That explains the behavior I'm seeing. Thanks for the explanation.
Since there is no way to add/modify a verb and maintain (IMHO) a consistent user interface, I will continue down the path of copying the put command and then adding the additional rules I need.
I should add that yes I could probably gut the put command, then use a verb and get what I want, but that doesn't really sound any easier or less intrusive than what I'm doing.
Thanks again for all the help.