how to get next object in a list
BlitzMax Forums/BlitzMax Beginners Area/how to get next object in a list
| ||
Im trying to use blitz3d type access as in the 'blitzmax tutorial forum' bit when I use link.findnext() it says trying to access field of null object is there another way to get the next object in a list? EDIT= this works Local link:TLink = the_List.FindLink(Self) this causes a crash= Local link:TLink = the_List.FindLink(Self).nextlink() |
| ||
The problem is that you need to check if the link provided by FindLink() exists or not. edit - simple example (I hope...) Try to change FindLink(myobj[1]) with FindLink(myobj[11]) - this link doesn't exist - but you catch the possible error |
| ||
From the user help:'Author:Assari 'FirstLink(), Value() and NextLink() 'Note that Value() and NextLink Methods from Type TLink 'Whereas FirstLink() is a method from Type TList SuperStrict Local MyList:TList = CreateList() MyList.AddFirst("A") MyList.AddFirst("B") MyList.AddFirst("C") Local NLink:TLink = MyList.FirstLink() 'get first Link Repeat Print NLink.Value().ToString() 'Need to convert value from object to string NLink = NLink.NextLink() 'Move to the next link in list Until Nlink = Null 'Null means we've reached the end of the list ================ Output C B A |
| ||
Hello. Be cautious with findLink(). The search as O(n) speed. If you call findlink() often on a large list your fps fall down. Use a tmap to save all tlinks . Search self in tmap and call nextlink() only in not null result. The same operation take O(1) speed at cost of memory. Bye, Paposo |