go through list backwards
Monkey Forums/Monkey Programming/go through list backwards
| ||
is it possible to go through a list backwards? |
| ||
You could use a Stack and access the elements with the Get(index) method. |
| ||
thanks for the suggestion , ill take a look |
| ||
What is a stack? I need to get a random item in a list, is that possible? I could not find the .get method in the TList. |
| ||
You could do something like this:Function getRandomSprite:Sprite() Local r% = 0 Local rand% = Rnd(0, Sprite.list.Count()) Local rndSprite:Sprite For Local s:Sprite = Eachin Sprite.list If r = rand Then rndSprite = s Exit EndIf r+=1 Next Return rndSprite End Function Full Code: |
| ||
you can use nodes to remove items from the list such as with with Bmax's "Tlink". |
| ||
@Wagenheimer: a Stack is like a List, but it has direct .Get/.Set methods. See in modules/monkey/stack.monkey for documentation about the commands. |
| ||
i changed my list to a stack and it was easy to go backwards through it |