Before object
Parameters
| object - a variable holding an object of a custom type |
Description
|
Returns the previous object in the type's list, or Null at the start. Before is the mirror of After. Like After it takes an object rather than a type name, and it returns Null when there is nothing further back. Start from Last and step with Before to walk a list from newest to oldest - handy for drawing order, for undo stacks, or for finding the most recent object that matches some test. It is also how you look backwards from where you already are. Given a linked list of waypoints or an ordered inventory, Before gets you the neighbour on the other side without another search. The second use of the word is as part of Insert: Insert a Before b moves object a to sit just ahead of b in the list. See also: After, Last, First, Each, Null, Insert. |
Example
; Before Example ; -------------- ; A squad of enemies, kept in a Type collection Type Enemy Field name$ Field hp End Type ; New appends each enemy to the end of the collection Spawn("Scout",20) Spawn("Grunt",50) Spawn("Brute",80) ; Walk the squad from back to front using Before Print "Roll call, back to front:" e.Enemy=Last Enemy While e<>Null Print " "+e\name+" ("+e\hp+" hp)" ; Before moves to the previous object - it returns Null past the first one e=Before e Wend Print "No one is before the first enemy - the walk ends." Print "" Print "Press any key to close the example" WaitKey End ; Create one enemy and set its fields Function Spawn(n$,hp) e.Enemy=New Enemy e\name=n$ e\hp=hp End Function
Index