Problem with documented dictionary functions

TinFoilMkIV
30 Aug 2015, 18:01
for some reason I seem to be having issues with the documented dictionary functions. For pretty much every dictionary related function other than adding or removing an item I get this.
Failed to load game.
The following errors occurred:
Error: Error adding script attribute 'roll_monster' to element 'combat': Function not found: 'DictionaryItem'


The code for this specific error is here
// select random monster from the combat list
count = ListCount (Monster_Control.combat_list)
monster_id = StringListItem (Monster_Control.combat_list, GetRandomInt (0, count-1))
// set monster data
DictionaryItem (dictionary, string key)


I left the function parameters at default as I was changing stuff and just trying to get the game to even register the function correctly first. Did I somehow lose a library of dictionary functions or something of the sort? I can create, the dictionary and add and remove items from it, but no other related functions seem to register, at least the ones that are currently documented.

HegemonKhan
30 Aug 2015, 18:15
take a look at this code sample, as I'm hoping it can help you understand using Lists+Dictionaries, and be able to fix your issue from it:

viewtopic.php?f=18&t=5138

viewtopic.php?f=18&t=5137

----------

I'm not sure what your design is (need more info), so... if you're using a List and a Dictionary...

make sure that Dictionary Attributes are indeed Dictionary Attributes
make sure that your List Attributes are indeed List Attributes

your code otherwise looks fine (do note that your upper code's Attributes are List Attributes), besides your 'DictionaryItem' bottom line of code, which needs to be:

VARIABLE = DictionaryItem (Object_name.Attribute_name, "key_string_name")
// and if you want to display your Dictionary's (key_string_name) selected Value:
msg (VARIABLE)

Lastly, just double-check that you got no Typos, make sure your Objects and Attributes are spelled~typed correctly

lastly lastly, from your error... maybe you got a 'combat' somewhere in your entire game code, when it should be (for example~possibly): 'combat_list'

The Pixie
30 Aug 2015, 18:48
TinFoilMkIV wrote:The code for this specific error is here
// select random monster from the combat list
count = ListCount (Monster_Control.combat_list)
monster_id = StringListItem (Monster_Control.combat_list, GetRandomInt (0, count-1))
// set monster data
DictionaryItem (dictionary, string key)

When the documentation says "string key" it means you need to supply a key, which is a string. And by "dictionary", it means you have to send the specific dictionary
I am not sure exactly what you are trying to do, but perhaps this:
DictionaryItem (Monster_Control.dictionary_of_monsters, monster_id)

... assuming you have a dictionary attribute of Monster_Control called dictionary_of_monsters, each accessed by the key you retrieve from Monster_Control.combat_list.

What exactly are you trying to do? If you have a list of monsters, I would personally put them in a room, rather than a dictionary, and use GetDirectChildren to get a list of them.

TinFoilMkIV
30 Aug 2015, 19:16
well the problem is that it's throwing an error for the function itself, it's not even getting to the point where it attempts to look at the dictionary or key in question.

Also I'm going with this method because I plan to only use one monster object which will have it's attributes modified off a master list after having a valid id chosen.

Basically it works like this. I have a monster data dictionary that contains attributes for each monster by its system name, basically a name that isn't necessarily what I want displayed, each area and such has a specific monster list which is then further limited by level requirements among other things which are used to build the combat list, which then contains the ID for each type of monster that is valid for a combat encounter, so when an encounter happens I need to pick something off the combat list, then grab its info from the master dictionary, which contains the actual monster info. If I can get that to work then I can set my universal monster object to become the monster character of an appropriate type when I need it to.

But I'm running into the above issue of Quest throwing errors for pretty much all the Dictionary functions besides add and remove.


EDIT: okay looks like I may have just needed to take some time off and step back, I think I actually see the problem, I'm trying to reference an item from the dictionary as a function instead of assigning it to something. I was playing around with a script dictionary before and it seems I've forgotten that I actually need to specify what its doing with the dictionary item. Going to test this and see if it resolves, which I suspect it will.

The Pixie
30 Aug 2015, 19:21
I put this in the start script of a test game, and it worked fine (Quest 5.6.1):
game.dict = NewStringDictionary()
dictionary add (game.dict, "one", "Item one")
dictionary add (game.dict, "two", "The second item")
msg(DictionaryCount(game.dict))
msg(StringDictionaryItem (game.dict, "one"))

TinFoilMkIV
30 Aug 2015, 19:27
Yea the problem was I was just calling 'DictionaryItem' by itself as if it were a function and not as a reference, it's working fine now that I actually took a moment to notice what I was actually trying to do with it.

Thanks for the responses, although they didn't directly point out the problem just discussing it and taking a second look at my own code helped me see what I was overlooking.

EDIT: actually HK did catch my error above although I missed that bit my first read through, maybe I subconsciously picked up on it? idk, either way I got it working now.

Also to answer the comment about 'combat' I'm using it as a control object to try and keep the references to combat related attributes clean and easy to reference, probably could stand to clean up some of my other control object names tbh.

HegemonKhan
31 Aug 2015, 01:32
I probably edited in that part, as a later addition, after you already read my post. So, it likely wasn't there when you read my post.

------

remember that the 'ListItem~XXXListItem' and 'DictionaryItem~XXXDictionaryItem' are Functions that RETURN a~n: (string~text, Object, or a Script)

-------

so, *ONLY* the 'ScriptDictionaryItem' is different, requiring:

invoke (ScriptDictionaryItem(Object_name.Attribute_name, "string_key_name"))

to activate the returned Script~s, as you don't set~assign a Script Attribute (a VARIABLE) to a VARIABLE, lol, you want to run~active~execute the Script Attribute.

--------

all of the others (String~Object List~Dictionary) require:

VARIABLE = XXXListItem (Object_name.Attribute_name, index_number)

VARIABLE = XXXDictionaryItem (Object_name.Attribute_name, "string_key_name")

-------

Lists:

input: (index number: 0 to ListCount) ---> StringListItem ---> output~returns: string~text
input: (index number: 0 to ListCount) ---> ObjectListItem ---> output~returns: Object

Dictionaries:

input: string ---> StringDictionaryItem ---> output~returns: string~text
input: string ---> ObjectDictionaryItem ---> output~returns: Object
input: string ---> ScriptDictionaryItem ---> output~returns: Script~s