Accessing List Objects
BlitzMax Forums/BlitzMax Beginners Area/Accessing List Objects
| ||
Hello. I've a Type called Objects_Type, a list of said Objects called ObjectsList where I've added above objects using ObjectsList.AddLast(obj) (where obj is local Objects_Type). When I try to access the list using for..eachin everything is fine, eg for local obj:Objects_Type = eachin ObjectsList print obj.Id next However, if I use : local obj:Objects_Type = ObjectsList.first() I get the error Cannot convert Object Type to Objects_Type. Can someone point out where I'm going wrong. Goodbye. |
| ||
I'm not sure, but try casting ObjectList.first() to a Objects_type type, like this:local obj:Objects_Type = Objects_Type(ObjectList.first()) |
| ||
Hello. Perhaps that what it is. I've tried casting but perhaps used wrong (c) syntax: local obj:Objects_Type = (Objects_Type)ObjectsList.first() I could have sworn that was correct. Goodbye. |
| ||
Check that the first object is "Objects_Type" not some other type, which cannot be cast to "Objects_Type". EachIn will skip objects that are not "Objects_Type" |
| ||
Global mylist:Tlist=CreateList() Type mytype Field x End Type For x = 1 To 100 my:mytype = New mytype my.x = x ListAddLast(mylist,my) Next myfirst:mytype=mytype(mylist.first()) Print myfirst.x |
| ||
Hello. Ta, all. Me and my multilingual incompetency :o) Goodbye. |
| ||
Taking what Luke said...Global mylist:Tlist=CreateList() Type mytype Field x End Type Type notmytype Field x End Type Rem my1:notmytype = New Notmytype my1.x=9999 ListAddLast(mylist,my1) End Rem For x = 1 To 100 my:mytype = New mytype my.x = x ListAddLast(mylist,my) Next If mytype(mylist.first()) myfirst:mytype=mytype(mylist.first()) Print "First *IS* a mytype" Print "Myfirst.x : " + myfirst.x Else Print "First is not a mytype" EndIf |