Trouble with Conversation/dictionaries/lists
selentte
30 Jan 2017, 15:02I'm trying to have the player talk to someone and have choice text, and then the next time the player talks to the same person, I want the text they already used to disappear. For example this to happen:
>Talk to Mom
What would you like to say?
1: Hi Mom!
2: See ya soon!
>2
"See ya soon" You say to Mom. "Bye" she says.
>Talk to mom
What would you like to say?
1: Hi Mom!
Can anyone help me?
hegemonkhan
30 Jan 2017, 21:37Links:
http://docs.textadventures.co.uk/quest/guides/using_lists.html
http://docs.textadventures.co.uk/quest/using_dictionaries.html
http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk
http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk
an example:
<object name="Mom">
<attr name="default_dialogue_stringlist_attribute" type="simplestringlist">Hi Mom!; See ya soon!; etc etc etc</attr>
<attr name="current_dialogue_stringlist_attribute" type="simplestringlist">Hi Mom!; See ya soon!; etc etc etc</attr>
<attr name="dialogue_stringdictionary_attribute" type="simplestringdictionary">Hi Mom! = blah; See ya soon! = \"See ya soon\" You say to Mom. \"Bye\" she says.; etc etc etc = blah blah blah</attr>
<attr name="chat" type="script"><![CDATA[
if (ListCount (this.current_dialogue_stringlist_attribute) > 0) {
msg ("What would you like to say? (type in the number of your choice)")
DisplayList (this.current_dialogue_stringlist_attribute, true)
get input {
if (IsInt (result) and ToInt (result) > 0 and ToInt (result) <= listCount (this.current_dialogue_stringlist_attribute)) {
choice_string_variable = StringListItem (this.current_dialogue_stringlist_attribute, ToInt (result) - 1)
msg (StringDictionaryItem (this.dialogue_stringdictionary_attribute, choice_string_variable))
list remove (this.current_dialogue_stringlist_attribute, choice_string_variable)
} else {
msg ("Wrong input, try again")
}
} else {
msg ("no more dialogue topics left")
}
}
]]></attr>
</object>
and/or
<object name="Mom">
<attr name="default_dialogue_stringlist_attribute" type="simplestringlist">Hi Mom!; See ya soon!; etc etc etc</attr>
<attr name="current_dialogue_stringlist_attribute" type="simplestringlist">Hi Mom!; See ya soon!; etc etc etc</attr>
<attr name="dialogue_stringdictionary_attribute" type="simplestringdictionary">Hi Mom! = blah; See ya soon! = \"See ya soon\" You say to Mom. \"Bye\" she says.; etc etc etc = blah blah blah</attr>
</object>
<command name="chat_to_command">
<pattern>chat to #object_parameter#</pattern>
<script><![CDATA[
if (ListCount (object_parameter.current_dialogue_stringlist_attribute) > 0) {
msg ("What would you like to say? (type in the number of your choice)")
DisplayList (object_parameter.current_dialogue_stringlist_attribute, true)
get input {
if (IsInt (result) and ToInt (result) > 0 and ToInt (result) <= listCount (object_parameter.current_dialogue_stringlist_attribute)) {
choice_string_variable = StringListItem (object_parameter.current_dialogue_stringlist_attribute, ToInt (result) - 1)
msg (StringDictionaryItem (object_parameter.dialogue_stringdictionary_attribute, choice_string_variable))
list remove (object_parameter.current_dialogue_stringlist_attribute, choice_string_variable)
} else {
msg ("Wrong input, try again")
}
} else {
msg ("no more dialogue topics left")
}
}
]]></script>
</command>
The Pixie
30 Jan 2017, 22:02If you are using the off-line editor, I suggest looking at this library:
https://github.com/ThePix/quest/wiki/Conversations:-Library
selentte
30 Jan 2017, 22:47Oh, I am on the online one.
To hegemonkhan, is it possible that you can tell me how to do that? All the coding escapes me; I can only handle small, simple stuff. It's alright if not but I would be grateful :-)
hegemonkhan
31 Jan 2017, 01:52List/Dictionary Attribute usage and iteration is a big step up, especially if you still don't understand well basic Attribute (Boolean, String, Integer/int, Double, and Object Attributes) and the 'if' Script usage.
hmm... I'm not familiar with online at all...
I forgot what the online has available for you to use... can you describe what you see and can do with the online GUI/Editor/mode whatever you got to work with?
this is just to help you understand what you're looking at with my code (I'll get to helping you do this non-code soon as I know/learn how / what you got to work with to do it, lol):
<object name="Mom"> // 'Mom' Object tag block beginning
// Attributes:
<attr name="default_dialogue_stringlist_attribute" type="simplestringlist">Hi Mom!; See ya soon!; etc etc etc</attr>
<attr name="current_dialogue_stringlist_attribute" type="simplestringlist">Hi Mom!; See ya soon!; etc etc etc</attr>
<attr name="dialogue_stringdictionary_attribute" type="simplestringdictionary">Hi Mom! = blah; See ya soon! = \"See ya soon\" You say to Mom. \"Bye\" she says.; etc etc etc = blah blah blah</attr>
</object> // 'Mom' Object tag block ending
this is a created Object named 'Mom', containing 3 Attributes (the top 2 are String List Attributes and the bottom is a String Dictionary Attribute).
A String List Attribute just has strings for its items (Values)
the items (Values) are separated by the semicolon
a String Dictionary Attribute has two sub-values for its items (Values):
the 'key' sub-value and its 'name' String Value
the 'value' sub-value and its String Value
think of a Dictionary as an input-output function, for an example:
Hi Mom! = blah
input (key): Hi Mom! // the input is to the LEFT of the equal sign
output (value): blah // the output is to the RIGHT of the equal sign
semicolons separate your 'key-value' items (Values)
string_variable = StringDictionaryItem (NAME_OF_OBJECT.NAME_OF_STRING_DICTIONARY_ATTRIBUTE, YOUR_INPUT)
string_variable = StringDictionaryItem (NAME_OF_OBJECT.NAME_OF_STRING_DICTIONARY_ATTRIBUTE, "Hi Mom!")
// string_variable = "blah" // returned output
Hi Mom! = blah
See ya soon! = "See ya soon" You say to Mom. "Bye" she says.
etc etc etc = blah blah blah
string_variable = StringDictionaryItem (NAME_OF_OBJECT.NAME_OF_STRING_DICTIONARY_ATTRIBUTE, "Hi Mom!")
// string_variable = "blah" // returned output
string_variable = StringDictionaryItem (NAME_OF_OBJECT.NAME_OF_STRING_DICTIONARY_ATTRIBUTE, "See ya soon!")
// string_variable = ""See ya soon" You say to Mom. "Bye" she says." // returned output
string_variable = StringDictionaryItem (NAME_OF_OBJECT.NAME_OF_STRING_DICTIONARY_ATTRIBUTE, "etc etc etc")
// string_variable = "blah blah blah" // returned output
msg (string_variable) // to display it during game play
List Attributes: 2 types
- String Lists: input: index number (starting at 0 for first/left-most item/value), ouput: String items/Values
- Object Lists: input: index number (starting at 0 for first/left-most item/value), Object reference items/Values
Dictionary Attributes: 3 types
- String Dictionaries: input (key): string Value, output (value): string Value
- Object Dictionaries: input (key): string Value, output (value): Object reference Value
- Script Dictionaries: input (key): string Value, output (value): scripting/script(s)
<![CDATA[
if (ListCount (this.current_dialogue_stringlist_attribute) > 0) {
msg ("What would you like to say? (type in the number of your choice)")
DisplayList (this.current_dialogue_stringlist_attribute, true)
get input {
if (IsInt (result) and ToInt (result) > 0 and ToInt (result) <= listCount (this.current_dialogue_stringlist_attribute)) {
choice_string_variable = StringListItem (this.current_dialogue_stringlist_attribute, ToInt (result) - 1)
msg (StringDictionaryItem (this.dialogue_stringdictionary_attribute, choice_string_variable))
list remove (this.current_dialogue_stringlist_attribute, choice_string_variable)
} else {
msg ("Wrong input, try again")
}
} else {
msg ("no more dialogue topics left")
}
}
]]>
this is the "meat" (the scripting: actions) of what you asked for
it's a layered/leveled ("nested"/indented) sequence ("order of operations") of many individual Scripts/Functions you create/add/write and/or use (as they're already built-in)
<command name="xxx">
<pattern>xxx</pattern>
<script>
// xxx
</script>
</command>
this is a 'Command' Element:
(there's only two ways to get and use typed-in input of the person playing the game: the 'Command' Element and the 'get input' Script/Function)
http://docs.textadventures.co.uk/quest/elements/command.html
^^^^^^^
http://docs.textadventures.co.uk/quest/elements/
if you have a left side "tree of stuff":
Objects
-> game
->-> Command -> Add -> (set it up) <----------- this is the (global) 'Command' Element
->-> Verbs
Functions
Timers
Advanced
-> Object Types
Filter -> Show Library Elements
<object name="xxx">
// content: Attributes and/or other Objects
</object>
this is a 'Object' Element
if you want to start learning Attribute and the 'if' Script usages (and quest coding/scripting):
http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk
and List/Dictionary Attribute usage:
http://docs.textadventures.co.uk/quest/guides/using_lists.html
http://docs.textadventures.co.uk/quest/using_dictionaries.html
http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk
crystalwizard
31 Jan 2017, 03:49Let's start smaller than all of that.
selentte: Can you write a command at this point to just make mom say hi.
selentte
31 Jan 2017, 21:46msg ("\"Hi\" Mom says.")
What I have learned is from trial and error. I look at some code, look at what it does, and figure it out. Then apply it to what I want. But obviously that doesn't work for everything and I was having trouble.
Here are some screenshots that I took of what I can see on a new game:
https://static.wixstatic.com/media/ef0b0b_d27da9ecc46f4fcf946312ce96d144a5~mv2.png/v1/fill/w_856,h_481,al_c,usm_0.66_1.00_0.01/ef0b0b_d27da9ecc46f4fcf946312ce96d144a5~mv2.png
https://static.wixstatic.com/media/ef0b0b_f64769eaf426451493c021f6c3f0b2ac~mv2.png/v1/fill/w_856,h_481,al_c,usm_0.66_1.00_0.01/ef0b0b_f64769eaf426451493c021f6c3f0b2ac~mv2.png
https://static.wixstatic.com/media/ef0b0b_4f1fa6038e3b4d9dbd4f8700f484a7c4~mv2.png/v1/fill/w_856,h_481,al_c,usm_0.66_1.00_0.01/ef0b0b_4f1fa6038e3b4d9dbd4f8700f484a7c4~mv2.png
I can figure out the code part, but what I don't get are the parts with the triangle brackets < >
For example: <attr ...>, <object ...>, etc
The gamequest doesn't take them so I can't figure them out. And Libraries don't work for me.
hegemonkhan
01 Feb 2017, 00:29the 'tag' blocks/lines (<xxx>xxx</xxx>), are the "physically existing/created/added things" of a quest game.
the 'tag' blocks/lines can only be done within the full game code view mode and/or directly in code, both of which I don't think are options for online quest users)
you can NOT do any of the tag stuff in/for the normal scripting
so, if you only have scripting (add new script -> ....) as option for online, some examples:
(I don't know what the GUI/Editor scripts and their options are, if the online has them, so hopefully you can figure out which ones match up to the code below)
to create an Object:
Create ("Mom")
is the same as this:
<object name="Mom">
</object>
to create and/or alter an Attribute:
offline/desktop text adventure's GUI/Editor's scripting:
run as script -> add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION
examples:
set variable Mom.alias = [EXPRESSION] "mom" // the built-in 'alias' String Attribute's Value is created/added to the 'Mom' Object with the Value of 'mom'
set variable Mom.alias = [EXPRESSION] "mother" // the 'alias' is no longer 'mom', now it's 'mother'
set variable Mom.alias = [EXPRESSION] "mama" // the 'alias' is no longer 'mother', now it's 'mama'
directly in code:
Mom.alias = "mom" // the built-in 'alias' String Attribute's Value is created/added to the 'Mom' Object with the Value of 'mom'
Mom.alias = "mother" // the 'alias' is no longer 'mom', now it's 'mother'
Mom.alias = "mama" // the 'alias' is no longer 'mother', now it's 'mama'
for Attributes:
there's also the 'set' Script/Function: http://docs.textadventures.co.uk/quest/scripts/set.html
and the 'do' Script/Function (for running/calling an Object's Script Attributes): http://docs.textadventures.co.uk/quest/scripts/do.html
http://docs.textadventures.co.uk/quest/scripts/
http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)
hegemonkhan
01 Feb 2017, 00:34within the scripting Elements: Functions, Verbs, Commands, Turnscripts, Timers, you can do the scripting I've shown above.
otherwise, to add/create/alter an Object;s Attributes, at least one way is to use the 'game' Game Settings Object's 'setup' Tab's 'start' Script:
'game' Game Settings Object -> 'setup' Tab -> 'start' Script
you may be able to right click on the left side's "tree of stuff's" Objects and get a popup menu with the choice of 'add attribute', but maybe not... meh
it looks like adding/creating Objects aren't an issue with the online, from the links of the GUI/Editor you've posted (thanks!), but it's the Attributes that are more confusing/limited in your options of using/accessing/creating/altering them.
crystalwizard
01 Feb 2017, 02:21selentte: if you've just started coding, maybe you should consider downloading the GUI and coding in it rather than the online version.
Did you work through everything in the Tutorial?
Jay Nabonne
01 Feb 2017, 12:37within the scripting Elements: Functions, Verbs, Commands, Turnscripts, Timers, you can do the scripting I've shown above.
The only caveat is that you don't use the CDATA tag if you're pasting script into the online editor's code view (or the desktop one, if you're viewing a smaller code view section and not the overall master one). Strip those out. That's still an XML thingy, and the editor should insert that as needed for you.
And the online editor doesn't support the creation or editing of attributes via the UI. If you have need for attributes, you can create them dynamically in a script by assigning values. It's a bit more manual, but it's still doable.
selentte
01 Feb 2017, 21:42Yes, I did the tutorial. And I have tried downloading it, but my computer won't do it.
With the coding part, I think I understand it all, except for how to set attributes. I can't right click either.
How would I set this?
<attr name="default_dialogue_stringlist_attribute" type="simplestringlist">Hi Mom!; See ya soon!; etc etc etc</attr>
What I don't know is where would I set it and how to include everything in the above script. Would I do the attributes in the speak-verb coding part?
hegemonkhan
02 Feb 2017, 00:25an example using a Verb:
(replace my all UPPER-CASE stuff with the names of the stuff in your game, that you're using or want to use)
'WHATEVER' Object -> 'WHATEVER' Verb -> (see below)
add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
set variable NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute = [EXPRESSION] NewStringList ()
(I don't know the GUI/Editor's scripting path for the 'list add' Script/Function, hopefully you can find it):
list add (NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute, "Hi Mom!")
list add (NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute, "See ya soon!")
list add (NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute, "etc etc etc")
OR
add new script -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
set variable NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute = [EXPRESSION] split ("Hi Mom!; See ya soon!; etc etc etc", ";")
directly in-code (aka: you right click on your game file on your computer and/or you click on the full game code toggle notepaper button at the top of the screen in the menu bar for the offline quest --- so, this is probably stuff that you can't use, as the online is online and it only has the specific code parts code view mode, no full game code view mode. But, I like to include this anyways, so you can see the subtle differences between the syntax for the GUI/Editor's scripting and the directly in-code scripting):
NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute = NewStringList ()
list add (NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute, "Hi Mom!")
list add (NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute, "See ya soon!")
list add (NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute, "etc etc etc")
OR
NAME_OF_WHATEVER_OBJECT.default_dialogue_stringlist_attribute = split ("Hi Mom!; See ya soon!; etc etc etc", ";")
http://docs.textadventures.co.uk/quest/functions/string/split.html ::: split ("STRING_ITEM_1 SEPARATOR STRING_ITEM_2 SEPARATOR STRING_ITEM_3", "SEPARATOR") --- you can use whatever you want for my 'SEPARATOR' character/symbol, but the convention with quest is to use the semicolon, and you can of course have as many items as you want (it doesn't have to be 3 as in my examples given)
http://docs.textadventures.co.uk/quest/guides/using_lists.html
http://docs.textadventures.co.uk/quest/functions/newlist.html
http://docs.textadventures.co.uk/quest/functions/newstringlist.html
http://docs.textadventures.co.uk/quest/functions/newobjectlist.html
http://docs.textadventures.co.uk/quest/scripts/list_add.html
http://docs.textadventures.co.uk/quest/scripts/list_remove.html
http://docs.textadventures.co.uk/quest/using_dictionaries.html
http://docs.textadventures.co.uk/quest/functions/newdictionary.html
http://docs.textadventures.co.uk/quest/functions/newstringdictionary.html
http://docs.textadventures.co.uk/quest/functions/newobjectdictionary.html
??? (NewScriptDictionary) ??? --- I guess you could maybe use the 'NewDictionary', if it's possible to create a Script Dictionary
http://docs.textadventures.co.uk/quest/scripts/dictionary_add.html
http://docs.textadventures.co.uk/quest/scripts/dictionary_remove.html
let me know if you need help with anything (I'll try to help you step by step through it) and/or if you got any questions or need any thing explained. (as due to being online, you're forced to jump right into coding/scripting, and some advanced coding/scripting, too. Not easy if you've never done coding/scripting before...)
The Pixie
02 Feb 2017, 08:28selentte
Try this. I am going to be typing code, but you can paste it in the right place, and then click View Code, and you will see the GUI for it. Using code is easier for me to type, and easier for you to copy-and-paste.
So first we need to set up a list of topics for Mom (I assume you have an object called Mom already). We want this to exist from the start, and as you are using the web version, you nend to do that in the start script. Go to the Scripts tab of the game object. At the top is a section for a script to run at the start of the game. Click Code View, and paste this in:
Mom.topics = NewStringList()
list add (Mom.topics, "Hi Mom!")
list add (Mom.topics, "See ya soon!")
The first line there sets a new attribute on your Mom object that is a list of strings. The next two lines add the topics. You can add as many as you like (however, do not put double quotes or apostrophes in them).
Now go to the Mom object, and the Verbs tab. Click Add and type an S, then select "Speak to..." from the list. Set it to run a script, then click Code view, and paste this in:
ShowMenu("What would you like to say?", Mom.topics, true) {
switch (result) {
case ("Hi Mom!") {
msg("\"Hi, Mom,\" you say to your Mom.")
}
case ("See ya soon!") {
msg("\"See ya soon\" You say to Mom. \"Bye" she says.\")
}
}
list remove (Mom.topics, result)
}
The first line there will show the menu, using Mom.topics as the options. After the player makes a choice, that choice goes in a special variable called "result", and the code uses that to decide what to do next with the select
statement. Lastly, the topic is removed from the list.
When you add other topics, you will need to add your own case
bits.
Hope this helps.
selentte
05 Feb 2017, 13:39Thank you so much! I got my computer to work and tried this and it worked. And then I looked at it and now I understand it too! Thank you everyone for helping me!!