Menu in conversation

Sharkycast
27 Nov 2016, 22:05

Hello all,

I'm new here and so still very much learning things, but for the moment I've got very stuck on how to make a menu appear when I want my player to talk to a character.

What I want to happen is, when 'speak to' is selected for the character, a menu will appear. Say:

  1. ask "How is Anne?"
  2. ask "How is Bob?"
  3. ask "How is Chris?"

For each, the character will give a different reply depending on what option is chosen. E.g.

  1. ask "How is Anne?"

"She's fine"

  1. ask "How is Bob?"

"He's not well"

  1. ask "How is Chris?"

"He's dead"

I have read the guidance here http://docs.textadventures.co.uk/quest/guides/conversations.html and tried to copy what is shown, but it doesn't work so I'm clearly doing something wrong. Can anyone give me an idiot's guide as to what I need to select, type, choose, etc?

Many thanks!


Deckrect
27 Nov 2016, 22:56

Go to the Ask/Tell tab of the selected character who will say the answers, on "Ask" add a new topic. Type "Bob" and add the script pf Print message with the text you want. Repeat the process. It is very easy and with a little research you will get it.


XanMag
28 Nov 2016, 00:51

Do you want a pop-up menu? Or, do you want a "homemade menu" like "You talk to [NPC] and they respond, 'Who would you like to know about - Anne, Bob, or Chris?'" At this point the player can type in Anne, Bob, or Chris with a default response set to something like "I'm sorry but I don't know what to tell you about that." Or, do you want to force the player to know what topics could be discussed? So the player would have to type "Ask [NPC] about Bob"?


Sharkycast
28 Nov 2016, 07:35

Hello,

Thanks for the replies. Yes, I want a pop up menu listing, say, three topics for conversation which are the only topics that can be discussed. Ideally, the player would just have to type "1" to ask about Anne; "2" to ask about Bob, etc.

Is there a way to do this? Do I need to create a 'topic' list somewhere other than the NPC tab?


hegemonkhan
28 Nov 2016, 08:25

see these links:


http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk
http://textadventures.co.uk/forum/samples/topic/4988/character-creation-crude-code-and-sample-game


http://docs.textadventures.co.uk/quest/guides/character_creation.html
http://docs.textadventures.co.uk/quest/guides/showing_a_menu.html
^^^^^
http://docs.textadventures.co.uk/quest/guides/
^^^^
http://docs.textadventures.co.uk/quest/
VVV
http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)
VVV
http://docs.textadventures.co.uk/quest/functions/corelibrary/displaylist.html


there's two types of built-in menu Functions:

  1. show menu ( http://docs.textadventures.co.uk/quest/scripts/show_menu.html ): the popup window menu
  2. ShowMenu ( http://docs.textadventures.co.uk/quest/functions/showmenu.html ): this is an 'in-line' (it's as hyperlinks in the big text box on the left side/pane)

unfortunately, the 'ask/Ask' (popup/in-line) Functions are misleading if you've been using these per-chance. What they do is to allow for you to ask only 'yes:true/no:false' type of questions: ( http://docs.textadventures.co.uk/quest/scripts/ask.html and http://docs.textadventures.co.uk/quest/functions/ask.html )


here's some (more advanced/useful/powerful) examples (in code):

<object name="npc_1">
  <attr name="displayverbs" type="simplestringlist">chat</attr>
  <attr name="topic_1_stringdictionary_attribute" type="simplestringdictionary">ask \"How is Anne?\" = "She's fine";ask \"How is Bob?\" = "He's not well";ask \"How is Chris?\" = "He's dead"</attr>
  <attr name="chat" type="script">
    ShowMenu ("Menu Choices", this.topic_1_stringdictionary_attribute, false) {
      msg (StringDictionaryItem (this.topic_1_stringdictionary_attribute, result))
    }
  </attr>
</object>

<verb>
  <property>chat</property>
  <pattern>chat</pattern>
  <defaultexpression>You can't chat with that!</defaultexpression>
</verb>

let me know if there's anything wrong (if it doesn't work - as using 'this' might be an issue and whether or not it numbers your choices)

// -----------------

<function name="dialogue_function" parameters="object_parameter,question_parameter,list_attribute_parameter,dictionary_attribute_parameter">
  msg (question_parameter)
  DisplayList (GetAttribute (object_parameter, list_attribute_parameter), true)
  get input {
    if (IsInt (result) and ToInt (result) > 0 and ToInt (result) < ListCount (GetAttribute (object_parameter, list_attribute_parameter))) {
      if (TypeOf (object_parameter, dictionary_attribute_parameter) = "scriptdictionary") {
        invoke (ScriptDictionaryItem (GetAttribute (object_parameter, dictionary_attribute_parameter), StringListItem (GetAttribute (object_parameter, list_attribute_parameter), ToInt (result))))
      } else if (TypeOf (object_parameter, dictionary_attribute_parameter) = "stringdictionary") {
        msg (StringDictionaryItem (GetAttribute (object_parameter, dictionary_attribute_parameter), StringListItem (GetAttribute (object_parameter, list_attribute_parameter), ToInt (result))))
      } else {
        msg ("Error: you didn't set up the code correctly for this Function and/or its Function call")
      }
    } else {
      msg ("Error: wrong input")
    }
  }
</function>

this probably has a ton of errors... meh


hegemonkhan
28 Nov 2016, 08:44

"Thanks for the replies. Yes, I want a pop up menu listing, say, three topics for conversation which are the only topics that can be discussed. Ideally, the player would just have to type "1" to ask about Anne; "2" to ask about Bob, etc. Is there a way to do this? Do I need to create a 'topic' list somewhere other than the NPC tab? (Sharkycast)"


there's three types of input: (1) typed-in, (2) menu selection, or (3) clicking on hyperlinks

a popup window menu means that you menu select the choice, there's no typing in an input (1, 2, or 3).

if you want to type in an input, then you can't have a popup window menu


// menu selection:

<object name="npc_1">
  <attr name="displayverbs" type="simplestringlist">chat</attr>
  <attr name="topic_1_stringdictionary_attribute" type="simplestringdictionary">1. ask \"How is Anne?\" = "She's fine";2. ask \"How is Bob?\" = "He's not well";3. ask \"How is Chris?\" = "He's dead"</attr>
  <attr name="chat" type="script">
    show menu ("Menu Choices", this.topic_1_stringdictionary_attribute, false) {
      msg (StringDictionaryItem (this.topic_1_stringdictionary_attribute, result))
    }
  </attr>
</object>

<verb>
  <property>chat</property>
  <pattern>chat</pattern>
  <defaultexpression>You can't chat with that!</defaultexpression>
</verb>

// typed-in input:

<object name="npc_1">
  <attr name="displayverbs" type="simplestringlist">chat</attr>
  <attr name="topic_1_stringlist_attribute" type="simplestringlist">ask \"How is Anne?\";ask \"How is Bob?\";ask \"How is Chris?\"</attr>
  <attr name="topic_1_stringdictionary_attribute" type="simplestringdictionary">ask \"How is Anne?\" = "She's fine";ask \"How is Bob?\" = "He's not well";ask \"How is Chris?\" = "He's dead"</attr>
  <attr name="chat" type="script">
    msg ("Choose a topic/question:")
    DisplayList (this.topic_1_stringlist_attribute, true)
    get input {
      if (IsInt (result) and ToInt (result) > 0 and ToInt (result) < ListCount (this.topic_1_stringlist_attribute)) {
        msg (StringDictionaryItem (this.topic_1_stringdictionary_attribute, StringListitem (this.topic_1_stringlist_attribute, ToInt (result))))
      } else {
        msg ("Error: wrong input")
      }
    }
  </attr>
</object>

<verb>
  <property>chat</property>
  <pattern>chat</pattern>
  <defaultexpression>You can't chat with that!</defaultexpression>
</verb>

for topic lists/dictionaries specific for an Object, have those list/dictionary Attributes contained within that Object (for your own organizational sanity/ease-of-use-or-understanding)

but for any that are universal/general/global, then have them contained within an (or many) internal data/storage Object/s (the person playing the game is unaware of it and doesn't interact with it at all, but it is used by the game - its for your organization-sanity as game designer), containing Objects/Attributes for game-wide usage, so you're not cluttering up other important Objects like the 'game' Game Object or the 'player' Player Object or whatever other Object, for example:

<game name="example_game">
</game>

<object name="global_data_object">
  <attr name="sex_stringlist_attribute" type="simplestringlist">male;female</attr>
  <attr name="race_stringlist_attribute" type="simplestringlist">human;dwarf;elf;gnome;halfling</attr>
  <attr name="class_stringlist_attribute" type="simplestringlist">warrior;hunter;thief;cleric;wizard</attr>
  // etc Attributes and/or Objects
</object>

// optionally etc internal data/storage Objects (however you want to organize), for examples:

<object name="monster_data_object">
  <attr name="monster_stringlist_attribute" type="simplestringlist">orc;dragon</attr>
  <object name="orc">
    // blah Attributes/Objects
  </object>
  <object name="dragon">
    // blah Attributes/Objects
  </object>
</object>

<object name="magic_data_object">
  <attr name="magic_type_stringlist_attribute" type="simplestringlist">fire;water</attr>
  <object name="fire_magic">
    <attr name="fire_spell_stringlist_attribute" type="simplestringlist">fireball;inferno;armaggeddon</attr>
    <object name="fireball">
    </object>
  </object>
  <object name="water_magic">
  </object>
</object>

// hopefully you get the idea now...

hegemonkhan
28 Nov 2016, 09:23

you can also create your own in-line menu too, an example:

<game name="example_game">
  <attr name="start" type="script">
    example_function
    get input {
      if (result = "1")
        msg ("you chose red")
      } else if (result = "2")
        msg ("you chose blue")
      } else if (result = "3")
        msg ("you chose yellow")
      } else {
        msg ("Error: wrong input")
      }
    }
  </attr>
</game>

<object name="global_data_object">
  <attr name="color_stringlist_attribute" type="simplestringlist">red;blue;yellow</attr>
</object>

<function name="example_function">
  msg ("Color Menu Selection:")
  x = 0
  foreach (item_variable, global_data_object.color_stringlist_attribute) {
    x = x + 1
    msg (x + ". ask about " + item_variable)
  }
  msg ("")
</function>

// outputs:
Color Menu Selection:
1. ask about red
2. ask about blue
3. ask about yellow
{ space / empty line }

The Pixie
28 Nov 2016, 11:02

You cannot have quotes (either " or ') in the options for an inline menu; that may be what the problem is.

By the way, if you are using the off-line editor, you might want to look at my conversation library:
https://github.com/ThePix/quest/wiki/Conversations:-Library


Sharkycast
28 Nov 2016, 13:11

Thanks everyone! I'll try to put this into practice later.

Am I right in saying that if I am using the web version I can't just copy & paste this code, but have to click and select all the 'run script' options?

Having hyperlinks to click on for the options would be fine - better in fact. Do I need to set a list of the topics in the NPC tab somewhere?


The Pixie
28 Nov 2016, 13:47

You can copy-and-paste script code from here to your game. Just click on the View code button under the script. What you cannot paste in is the XML code (all the stuff in < and >.


Sharkycast
28 Nov 2016, 14:34

Sorry to sound dense... but most of the code here has < > stuff. If I copy and paste code I seem to get "an internal error occured".


hegemonkhan
28 Nov 2016, 19:19
ya, most of my code is for using the off-line/desktop version of quest, as it's aslx/xml/html code (as Pixie said, all of the tag lines/blocks: <xxx>xxx</xxx> ), and you got to know how to code, to know where/how to put code into your game's code.

I don't know what the online version has, as I've never used it, but List and Dictionary Attributes are a bit more advanced stuff.

In the desktop version, there's a few ways of creating List/Dctionary Attributes:

http://docs.textadventures.co.uk/quest/guides/using_lists.html
http://docs.textadventures.co.uk/quest/using_dictionaries.html

via using the GUI/Editor's Tabs' options:

'whatever' Object -> 'Attributes' Tab -> Attributes -> Add -> (set it up: Attribute Type: list or dictionary)

however, you can't create Objectlists nor Objectdictionaries via this way.

via using scripting (using Elements that can hold scripting: Verbs, Functions, Commands, Script Attributes --- which must be within an Object, Turnscripts, Timers, and etc):

you can create/do them two ways

using the 'split' Script/Function ( http://docs.textadventures.co.uk/quest/functions/string/split.html ), this is the quick and easy way of creating lists/dictionaries. An example:

game.sex_stringlist_attribute = split ("male;female", ";")

using 'NewStringList/NewObjectList/NewStringDictionary/NewObjectDictionary/NewScriptDictionary' Functions, and then 'list/dictionary add' to add the items to your empty/new list/dictionary:

game.sex_stringlist_attribute = NewStringList ()
list add (game.sex_stringlist_attribute, "male")
list add (game.sex_stringlist_attribute, "female")

and lastly, via directly (in code, NON-GUI/Editor), which you see partially in my previous post's code box content code


in the desktop/offline version, you can access the entire game code via the horizontal menu bar at the top's notepaper-like button between the 'play' and 'help buttons, this notepaper button is a toggle between the GUI/Editor mode and Code View mode, and for individual scripting (Verbs, Commands, Functions, etc), for their options in the box in the middle of the screen, there's again a 'notepaper'-like button within the script buttons, which let's you go into code view for just that specific scripting (Verb, Command, Function, etc).