StringDictionaryItem Error compiling

Error running script: Error compiling expression
'this.StringDictionaryItem(Descriptions, 1)': Unknown object or variable 'Descriptions'

I have Descriptions set as a String Dictionary in the objects Attributes, I see now after typing this that it wants a Variable but I don't know where those are or what the difference is between an Attribute and a Variable.

please help.


I think it should be:

StringListItem(this.Descriptions, 1)

where this.Descriptions is a list attribute, not a dictionary attribute. I don't think that you can reference a dictionary item by index, only a list item. So you have to make Descriptions a list, not a dictionary.

this refers to the parent object of the Descriptionsattribute. StringListItem is a function (you don't want to put this before it).

And keep in mind that the first item in a list is at index 0, not at index 1 (which would be the second item).


Ok, thankyou. :)
May I ask why I should not use a Dictionary and what the difference is?


I have it working with the List, so that's cool. But I would be better off with the Dictionary if there's any way I can use it.


In general, a list is more flexible to use. From reading the Quest documentation about functions:

http://docs.textadventures.co.uk/quest/functions/#dictionary

...it sounds like dictionaries reference their items by string key, rather than by index. You can still use a dictionary -- but you have to know the string key. I don't know if that would be a problem for you.


You give each item a string key s you make the items and it shows you the string and the key you gave it. I was using numbers anyway so that doesn't really change, but it shows you the number for each string where the list does not. Neither method lets you edit the order of the list though, so that really sucks. you have to look at the Code view and edit it that way. For me that's risky, I could break something easily.


Hello.

Have you tried this?

whatever_goes_here = StringDictionaryItem(this.Descriptions, 1)

Depending on what you have in your code, this may or may not work.

If you post some code, we can probably help you get the dictionary working.


It is much easier to just use lists, though. I agree with Dcoder (but don't tell him I said that).


If you use numbers as the keys, then the big difference between lists and dictionaries is that a list will automatically adjust the numbers when you remove an item; and will automatically work out the number to use when adding an item so you don't need to specify it.

Whether it's best to use a list or a dictionary depends on what you're doing. If you want to put something in slot "1" and something else in slot "5" while leaving the ones in between blank, you want a dictionary. If you want to put something in the first available slot, a list is easier because you don't need to keep track of which numbers you used.

Use whichever suits your situation better :)


(filler for getting my edited post, updated/posted)


Lists/Arrays and Dictionaries are basically just input-output functions


for a list's index numbers (might also work for dictionaries too if you use/assign/set numbers as int values for its inputs), they can be 'int' or 'string' as quest has built-in/automatic programming to handle/convert/parse between ints and strings, for you, so you don't need to do so (quest will convert an index number as an int value into its proper/required string value for you)


Lists:

  1. String lists:

item:

input ("key"): index number string/int value (automatically done for you, first item is index number '0' --- takes awhile to get used to starting at '0' instead of '1', second item is index number '1', and so forth. The last item's index number is: ListCount (LIST) - 1)

output ("value"): string value

  1. Object Lists:

item:

input ("key"): index number string/int value (automatically done for you, first item is index number '0' --- takes awhile to get used to starting at '0' instead of '1', second item is index number '1', and so forth. The last item's index number is: ListCount (LIST) - 1)

output ("value"): object (reference/pointer) value


Dictionaries:

  1. String Dictionary:

item:

input ("key"): string value

output ("value"): string value

  1. Object Dictionary:

item:

input ("key"): string value

output ("value"): object (reference/pointer) value

  1. Script Dictionary:

item:

input ("key"): string value

output ("value"): scripting/scripts (script value/s)


Lists:

  1. String Lists:

create ("example_object")

example_object.example_stringlist_attribute = NewStringList ()
list add (example_object.example_stringlist_attribute, "red")
list add (example_object.example_stringlist_attribute, "blue")
list add (example_object.example_stringlist_attribute, "yellow")

// item1:
// input: "0"
// output: "red"
//
// item2:
// input: "1"
// output: "blue"
//
// item3:
// input: "2"
// output: "yellow"
//
// item 4:
// input: "3"
// output: "orange"
// ERROR! there is no 4th item!

// generalized syntax concept:
// OUTPUT: string = StringListItem (LIST, "INPUT: index number")

string_variable = StringListItem (example_object.example_stringlist_attribute, "0")
// string_variable = "red"

string_variable = StringListItem (example_object.example_stringlist_attribute, "1")
// string_variable = "blue"

string_variable = StringListItem (example_object.example_stringlist_attribute, "2")
// string_variable = "yellow"

string_variable = StringListItem (example_object.example_stringlist_attribute, "3")
// ERROR! there is no 4th item!

  1. Object Lists:

create ("example_object")

create ("red_object")
create ("blue_object")
create ("yellow_object")

example_object.example_objectlist_attribute = NewObjectList ()
list add (example_object.example_stringlist_attribute, red_object)
list add (example_object.example_stringlist_attribute, blue_object)
list add (example_object.example_stringlist_attribute, yellow_object)

// item1:
// input: "0"
// output: red_object
//
// item2:
// input: "1"
// output: blue_object
//
// item3:
// input: "2"
// output: yellow_object
//
// item 4:
// input: "3"
// output: orange_object
// ERROR! there is no 4th item!

// generalized syntax concept:
// OUTPUT: object (reference/pointer) = ObjectListItem (LIST, "INPUT: index number")

object_variable = ObjectListItem (example_object.example_stringlist_attribute, "0")
// object_variable = red_object

object_variable = ObjectListItem (example_object.example_stringlist_attribute, "1")
// object_variable = blue_object

object_variable = ObjectListItem (example_object.example_stringlist_attribute, "2")
// object_variable = yellow_object

object_variable = ObjectListItem (example_object.example_stringlist_attribute, "3")
// ERROR! there is no 4th item!


Dictionaries:

  1. String Dictionary:

create ("example_object")

example_object.example_stringdictionary_attribute = NewStringDictionary ()
dictionary add (example_object.example_stringdictionary_attribute, "princess", "the princess was kidnapped by the dragon")
dictionary add (example_object.example_stringdictionary_attribute, "dragon", "the dragon can only be killed by the dragon slaying sword")
dictionary add (example_object.example_stringdictionary_attribute, "sword", "the dragon slaying sword was stolen by an evil wizard")

// item1:
// input: "princess"
// output: "the princess was kidnapped by the dragon"
//
// item2:
// input: "dragon"
// output: "the dragon can only be killed by the dragon slaying sword"
//
// item3:
// input: "sword"
// output: "the dragon slaying sword was stolen by an evil wizard"
//
// item 4:
// input: "wizard"
// output: "the evil wizard can be found in the dark lands"
// ERROR! there is no 4th item!

// generalized syntax concept:
// OUTPUT: string = StringDictionaryItem (DICTIONARY, "INPUT: string value")

string_variable = StringDictionaryItem (example_object.example_stringdictionary_attribute, "princess")
// string_variable = "the princess was kidnapped by the dragon"

string_variable = StringDictionaryItem (example_object.example_stringdictionary_attribute, "dragon")
// string_variable = "the dragon can only be killed by the dragon slaying sword"

string_variable = StringDictionaryItem (example_object.example_stringdictionary_attribute, "sword")
// string_variable = "the dragon slaying sword was stolen by an evil wizard"

string_variable = StringDictionaryItem (example_object.example_stringdictionary_attribute, "wizard")
// ERROR! there is no 4th item!


Randomization, example:

// GetRandomInt (MIN,MAX)

create ("example_object")

example_object.example_stringlist_attribute = NewStringList ()
list add (example_object.example_stringlist_attribute, "red")
list add (example_object.example_stringlist_attribute, "blue")
list add (example_object.example_stringlist_attribute, "yellow")

random_string_variable = StringListItem (example_object.example_stringlist_attribute, GetRandomInt (0, ListCount (example_object.example_stringlist_attribute) - 1))

// random_string_variable = [randomly selects only one of these: "red"/"blue"/"yellow"]


combining all the operations as seen above into a single line of code is a bit confusing (especially making sure you get the correct equal number of parenthesis on both sides and in the right places), so here it is broken down:

item_count_variable = ListCount (example_object.example_stringlist_attribute)
// item_count_variable = 3

index_number_of_last_item_variable = item_count_variable - 1
// index_number_of_last_item_variable = 2

viable_random_index_number_selected_variable = GetRandomInt (0, index_number_of_last_item_variable)

random_string_variable = StringListItem (example_object.example_stringlist_attribute, viable_random_index_number_selected_variable)
// random_string_variable = [randomly selects only one of these: "red"/"blue"/"yellow"]


"Literally" creating a String List from/with/as a String Dictionary:

create ("example_object")

example_object.example_stringdictionary_attribute = NewStringDictionary ()
dictionary add (example_object.example_stringdictionary_attribute, "0", "red")
dictionary add (example_object.example_stringdictionary_attribute, "1", "blue")
dictionary add (example_object.example_stringdictionary_attribute, "2", "yellow")

// the above is the "exact same" as below:

create ("example_object")

example_object.example_stringlist_attribute = NewStringList ()
list add (example_object.example_stringlist_attribute, "red")
list add (example_object.example_stringlist_attribute, "blue")
list add (example_object.example_stringlist_attribute, "yellow")

// as can be seen, a 'list' simply does the setting of the string inputs for you: the contigious index numbering (starting at "0" for the first item, and then for the next X items: "1", "2", "3", "4, "ETC")

// a 'list' is just a specialized/specific type of 'dictionary'


Neither method lets you edit the order of the list though, so that really sucks. you have to look at the Code view and edit it that way. For me that's risky, I could break something easily (Millie Jonasen)

managing (sorting, searching, etc) collections/data is an entirely different can of worms...

(arrays/lists are the most simple forms of collections/data storage, and while modern computers/hardware can extremely efficiently/fast-quickly go through the "assembly-line" (sequence) of data storage, which is arrays/lists, but, especially with massive data/collection storage and its managament needs, it can be better/required to use these more advanced/complex forms of collections/data shown below)

Data Management Programming:

(ADTs: Abstract Data Types/Structures): Linked Lists/Nodes/Chains, Stacks, Queues, Deques, Trees, Maps, Dictionaries

https://en.wikipedia.org/wiki/Linked_list
https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
https://en.wikipedia.org/wiki/Queue_(abstract_data_type)
https://en.wikipedia.org/wiki/Double-ended_queue (deques)
https://en.wikipedia.org/wiki/Tree_(data_structure)


Log in to post a reply.

Support

Forums