List of dictionaries

OK, I've been playing around with a particularly confusing bug.

I've got a list whose values are dictionaries. It seemed the most sensible way to organise things.
And I've got a simple function, DumpData(), which gives me a nice visual output of lists and dictionaries.

The issue seems to be shown off by this piece of code:

msg ("==Before assignment==")
DumpData (myList)
msg ("")
game.someattribute = myList
msg ("==After assignment==")
DumpData (myList)

This gives me:

==Before Assignment==

  1. dictionary
    • "name" (string): "First dictionary"
    • "value" (int): 3
    • "script" (script): "{ msg ("test") }"
  2. dictionary
    • "name" (string): "Second item"
    • "arbitrary parameter with a silly name" (string): "foo"
    • "nested list" (stringlist):
      1. (string) "melons"
      2. (string) "apples"
      3. (string) "bananas"

==After Assignment==

  1. dictionary
    • "name" (string): ""
    • "value" (int): 3
    • "script" (script): "Script:"
  2. dictionary
    • "name" (string): ""
    • "arbitrary parameter with a silly name" (string): ""
    • "nested list" (stringlist):

OK ... so setting a game attribute to be equal to my list mangles the values in the list?
Bizarrely, it seems that when I retrieve a value using DictionaryItem(), I get a variable that maintains its TypeOf() result, but loses its value unless it's an int.

Is this a bug in Quest, or is there something really dumb I'm overlooking?

Please tell me I don't have to create an object just to store a couple of values if I want to put it into a list?

Also, is this a new issue? I know I've used lists-of-lists and lists-of-dictionaries before without issues. Is this behaviour new with the new version of Quest? Or have I just not tried assigning these lists to an attribute before?


I had a look, and could not repeat it. This is my DumpData function:

foreach (el, list) {
  msg (el)
}
d = ListItem(list, 0)
el = DictionaryItem(d, "script")
msg (TypeOf(el))

And this sets it up:

script => {
  msg ("test")
}
d1 = QuickParams("name", "First dictionary", "value", 3, "script", script)
d2 = QuickParams("name", "Second item", "arbitrary parameter with a silly name", "foo", "nested list", Split("melons;apples;bananas"))
myList = NewList()
list add (myList, d1)
list add (myList, d2)
msg ("==Before assignment==")
DumpData (myList)
msg ("")
game.someattribute = myList
msg ("==After assignment==")
DumpData (myList)

It displays the script differently, but still sees it as a script (which is why DumpData checks it):

==Before assignment==
Dictionary: name = First dictionary;value = 3;script = { msg ("test") }
Dictionary: name = Second item;arbitrary parameter with a silly name = foo;nested list = List: melons; apples; bananas; 
script

==After assignment==
Dictionary: name = First dictionary;value = 3;script = Script: msg ("test")
Dictionary: name = Second item;arbitrary parameter with a silly name = foo;nested list = List: melons; apples; bananas; 
script

OK, I'm getting really confused now.
Tried using your DumpData function with my test code, and my DumpData with your code. Both seem to work. But put the two pieces of my code together, and it fails in a bizarre way I just can't get my head around.

As I've had the same issue with actual game code, and this simple test written to create the problem, I think I must be missing something pretty fundamental. I'm going to start from scratch, and see if it happens again.


... OK, got it working now.
Not sure what's different.

I've given up on trying to print debugging messages here, because I've found that in some circumstances (not always), I can get a variable script where TypeOf(script) returns "script", ToString(script) returns "Script: " and nothing else, but invoke (script) works fine.

So… my current guess is that I don't understand how ToString() works on scripts; and this was actually unrelated to a separate issue that was causing invoke() to fail.


Log in to post a reply.

Support

Forums