5.4 - New list and dictionary types in function return

jaynabonne
08 Mar 2013, 18:30The new NewList API is very nice. I love the general-purpose handing this allows.
My first attempt to use it failed, though, as I wanted to create a list and return it from a function. There doesn't seem to be a type that matches what that list is (unless I missed it). I tried a general-purpose "list", and that failed. And there is nothing in the GUI that would match.
Is there some way to do something like this:
Thanks!
My first attempt to use it failed, though, as I wanted to create a list and return it from a function. There doesn't seem to be a type that matches what that list is (unless I missed it). I tried a general-purpose "list", and that failed. And there is nothing in the GUI that would match.
Is there some way to do something like this:
<function name="MyFunc" parameters="" type="????">
List = NewList()
list add(List, 1)
list add(List, 2)
return (List)
</function>
Thanks!
levicki
10 Mar 2013, 14:34jaynabonne wrote:The new NewList API is very nice. I love the general-purpose handing this allows.
My first attempt to use it failed, though, as I wanted to create a list and return it from a function. There doesn't seem to be a type that matches what that list is (unless I missed it). I tried a general-purpose "list", and that failed. And there is nothing in the GUI that would match.
Is there some way to do something like this:
<function name="MyFunc" parameters="" type="????">
List = NewList()
list add(List, 1)
list add(List, 2)
return (List)
</function>
Thanks!
NewList() returns an empty list of the type "list" so you should use:
<function name="MyFunc" parameters="" type="list">
List = NewList()
list add(List, 1)
list add(List, 2)
return (List)
</function>
However, if you know the type of list items in advance, it would be better to use NewStringList() / "stringlist", and NewObjectList() / "objectlist" respectively.
<function name="MakeStringList" parameters="" type="stringlist">
List = NewStringList()
list add(List, "123")
list add(List, "456")
return (List)
</function>
<function name="MakeObjectList" parameters="" type="objectlist">
List = NewObjectList()
list add(List, room1)
list add(List, room2)
return (List)
</function>
You can also use dictionaries instead of lists:
<function name="MakeRoomDictionary" parameters="" type="dictionary">
dict = NewDictionary()
dictionary add(dict, "Bedroom", room1)
dictionary add(dict, "Lounge", room2)
return (dict)
</function>

jaynabonne
10 Mar 2013, 14:47I would have bet my life that I had tried "list" before and it didn't work. I must have made a mistake then or something. (I probably typed "List".)
Thanks!
Thanks!