Using Ask and Tell

tbritton
26 Oct 2013, 00:42
I should first explain that my design goal is that whether a user uses the command line or the links they should have the same experience. In this case I'm struggling with ask/tell.

I can use the following to make the command line behave properly, but there are (obviously) no links for users that prefer that interface.

<ask type="scriptdictionary">
<item key="key">
msg ("It's a key.")
</item>
<item key="door">
msg ("It's a door.")
</item>
<item key="window">
msg ("It's a window.")
</item>
</ask>


I can get the links to work properly by adding the following code to verbs, but the command line doesn't work.

<ask type="script">
topics = Split ("key;door;window", ";")
show menu ("Ask orc about...", topics, true) {
switch (result) {
case ("key") {
msg ("It's a key.")
}
case ("door") {
msg ("It's a door.")
}
case ("window") {
msg ("It's a window.")
}
}
}
</ask>


I'm looking for a way to get both the links and the command line to work properly. I could setup the command line with ask and then use talk to, or something else, for the links, but would prefer not to.

tbritton
26 Oct 2013, 01:56
I got it working (not fully tested though, and one disadvantage I see already is the text has to be exact) by using the code above that makes the links work and then adding an ask command, which allows the command line to work.

  <command name="ask">
<pattern type="string"><![CDATA[^ask (?<object1>.*) (about) (?<text>.*)$]]></pattern>
<script>
if (object1 = orc and text = "key") {
msg ("It's a key...")
}
if (object1 = orc and text = "door") {
msg ("It's a door...")
}
if (object1 = orc and text = "window") {
msg ("It's a window...")
}
</script>
</command>


I would still be interested if there's a better way to do this.

george
26 Oct 2013, 02:30
Do you mean that the second bit of code duplicates the first (so you copy and paste as you go) or it replaces it?

What's your ideal UI here? That when the choice menu pops up, the player also can type the text if they want?

If there is code duplication, you can reduce it by putting your text in a stringdictionary, http://quest5.net/wiki/Stringdictionary . Then both your links and your command line can reference that one dictionary where you put all your dialog. That also lets you get rid of all those if's because you can just lookup by key. I guess you might need just one if to return a default text if the player asks about something not in the dictionary.

tbritton
26 Oct 2013, 04:23
The second code is in addition to the first code. One for links to work properly and one for the command line to work properly.

My ideal UI is whatever the user wants. Some will want to type in all the commands, some will want to just use links and some will use the command line at times and the links at times. So clicking "orc" then "ask" then "key" should work the same as "ask orc about key." In addition, as you said, you could type ask orc and then get a list of options (although this is not my primary goal).

I will look into the scriptdictionary you suggested, at least that would make the coding simpler.

To be clear, the following makes the links work properly.

<ask type="script">
topics = Split ("key;door;window", ";")
show menu ("Ask orc about...", topics, true) {
switch (result) {
case ("key") {
msg ("It's a key.")
}
case ("door") {
msg ("It's a door.")
}
case ("window") {
msg ("It's a window.")
}
}
}
</ask>


And the following makes the command line work properly.

    <command name="ask">
<pattern type="string"><![CDATA[^ask (?<object1>.*) (about) (?<text>.*)$]]></pattern>
<script>
if (object1 = orc and text = "key") {
msg ("It's a key...")
}
if (object1 = orc and text = "door") {
msg ("It's a door...")
}
if (object1 = orc and text = "window") {
msg ("It's a window...")
}
</script>
</command>


Thanks for the response.

george
26 Oct 2013, 04:59
From your code, it seems like you've looked at the conversation pages on the wiki...have you found a library that does all this I wonder? I saw a reference to one on the wiki but I'm not sure if it has what you need.

HegemonKhan
26 Oct 2013, 05:47
"ask and tell" is a default (built-in) core coding, I am still having trouble understanding it myself (in it's code form), lol.

Filter -> Show Library Objects (if you want to see the core coding in the GUI~Editor mode for the "ask and tell" scripts)

if you create your own "ask~tell" Verb and add in your own scripts to it, then you'll need to also create your own Command for it too, as the default (built-in) Command will no longer work.

to add the buttons and hyperlinks, you need to do this (at least this is how it is done in code ~ I'm not sure how the GUI~Editor handles~does it however):

<object name="orc">
-> <take />
-> <drop />
-> <give />
-> <use />
-> // blah scripting for the "take", "drop", "give", and "use" Verbs~scripts ~ see the format for the "fight" Verb~script below
-> <fight type="script">
->-> // blah scripting
-> </fight>
-> <displayverbs type="simplestringlist">Take;Drop;Give;Use;Fight</displayverbs> // when NOT in your player's inventory ~ they are still in the room
-> <inventoryverbs type="simplestringlist">Take;Drop;Give;Use;Fight</inventoryverbs> if you want these to be buttons and hypertext for items~objects that you ("player") are holding. Obviously, you'd not have "take" listed here, as you already have the item~object, nor would you have "fight" listed here either, for my example case you see here.
</object>

----------------------

see these pages, for more scripts to use (click on them to see what they do):

http://quest5.net/wiki/Category:All_Fun ... t_Commands (page 1, range: A-S)
http://quest5.net/w/index.php?title=Cat ... h#mw-pages (page 2, range: S-Z)

http://quest5.net/wiki/CommandLink
http://quest5.net/wiki/ObjectLink
http://quest5.net/wiki/GetDisplayVerbs

tbritton
26 Oct 2013, 18:13
george wrote:From your code, it seems like you've looked at the conversation pages on the wiki...have you found a library that does all this I wonder? I saw a reference to one on the wiki but I'm not sure if it has what you need.


I've looked at two libraries: one from Pixie and one that is referenced in the wiki page. Both add some nice functionality, but don't address the issue of the getting consistent behavior between the links and the command line.

The problem is, as was explained to me in regards to put (which has the same issues), "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."

I've only briefly looked into the stringdictionary, but either that or the scriptdictionary looks like the way to go. I have no problem with modifying the verb and the command, just wanted to do it efficiently (it's a pain when you modify the verb script days/weeks later and have to remember to go back and modify the command script). In any case I think the the dictionary approach may do exactly what I was looking for.

george
26 Oct 2013, 19:16
This brings up a question for me, is it not possible to select the 'show menu' script in the GUI? When I do 'add a script' it seems to show only the ShowMenu inline script.

edit: OK, I found out the answer here, viewtopic.php?f=10&t=3806#p25480 .

jaynabonne
26 Oct 2013, 22:35
Here's one way to do it:

First, use the standard ask mechanism of a script dictionary for the responses. This handles "ask X about Y".

    <object name="orc">
<inherit name="editor_object" />
<ask type="scriptdictionary">
<item key="key">
msg ("It's a key")
</item>
<item key="door">
msg ("It's a door")
</item>
<item key="window">
msg ("It's a window")
</item>
</ask>
<displayverbs type="stringlist">
<value>Look at</value>
<value>Take</value>
<value>Ask</value>
</displayverbs>
</object>

Note that I manually added in the "Ask" verb as well.

Then add this general command:

  <command name="AskGeneric">
<pattern type="string"><![CDATA[^ask (?<object>.*)]]></pattern>
<script>
topics = Split ("key;door;window", ";")
show menu ("Ask " + object + " about...", topics, true) {
DoAskTell (object, result, "ask", "askdefault", "DefaultAsk")
}
</script>
</command>


This handles the "ask X" case for links (or if the player types "ask orc" with no "about"). Basically, it just asks the topic and then hands it off to the same DoAskTell method that the built-in "ask about" command uses.

tbritton
27 Oct 2013, 01:38
Awesome Jaynabonne! Exactly what I was looking for.

Any chance I can do something similar with put? Not looking for all the details, just a point in the right direction--if it's possible. Here's the original post on put:

viewtopic.php?f=10&t=3934

tbritton
27 Oct 2013, 23:03
Worked perfectly jaynabonne. With a couple of small changes also worked great for "tell." Thanks again.