Linked List Access

BlitzMax Forums/BlitzMax Beginners Area/Linked List Access

twistedcube(Posted 2005) [#1]
Now what I have done is created a type with and index # as well as a small png for each number right now there is four but there is going to be alot more(Which is why I though a list would be an effecent way to organize them). just in the testing stages right now.

Now I need to pull those pics out at a certain time to draw them to the screen. Now I know I can use an eachin to get at them but does it not seem like a waste to time and effort to go through the list each time if I know the index number of the Item i want.

Is there a way to access an item in the list without going through the whole thing now I have tried LISTFINDLINK. But that will only return the link and when I try to access the type within the link I can't. Really I'm nor sure how. and was hoping someone else would have an idea for me. Because obviously the TLINK it returns and the TYPE I'm trying to access within the link are not convertable.. (or so it says :) cause I've tried.)

Any help would be greatly appreciated.


PGF(Posted 2005) [#2]
I suggest using an array rather than a list since you want to access them by an index. It sounds like you'll know how many there are in advance and they're not being created and destroyed all the time ? An array is the way to go.

Of course you can have your type instances and refer to them from both a list and an array, or even from within instances of another type.

Work out how you want to access data before deciding on how to store it.


twistedcube(Posted 2005) [#3]
Okay cool thanks for the info. I will have to do that. Shold be an easy switch to an array. My first time using lists I though there was a way to access individual elements easily but now I understand more of have to implement them and when.

Once again thanks

TwistedCube


skidracer(Posted 2005) [#4]
you can access an item in a list like this (note that you need to cast the result of the ValueAtIndex method to the correct type):
list:TList=CreateList()

list.AddLast "hello"
list.AddLast "there"

Print String(list.ValueAtIndex(0))



twistedcube(Posted 2005) [#5]
Wow thanks for your help skidracer. I'll give that a try as well before I convert if I need to :)


Perturbatio(Posted 2005) [#6]
Of course, ValueAtIndex uses Eachin anyway.
I think the only way to directly access them by index would be in an array.