The TypeOf() function returns the User Defined Type index of a selected type handle. It's purpose is to query elements stored within typed arrays / variables & Lists to determine what type they are.
Not sure what Types are ?, Make sure you check out the Types tutorial.
FACTS:
* TypeOf returns a zero if the passed type handle is of an unknown type.
* Type Indexs range from 1 onwards.
Mini Tutorial:
; This is a example of how you can store ; collection of USER defined types ; within a single typed array. The Example ; doesn't do much, in order to show you the ; frame work. ; Create the Base Type. This type will contain ; all the global fields common to all types. So BaseObject ; will be our generic parent type. Type BaseObject Obj X#,y#,z# Sprite EndType ;Declare the Player type as a child ; from the base object type Type Player As BaseObject ; Add any fields here that are unique to the player Score EndType ; Declare Alien1, which inherits the parent ; fields from the Base object Type Alien1 As BaseObject ; Here we'd store all the fields unique to this alien type EndType ; Declare Alien2, which inherits the parent ; fields from the Base object Type Alien2 As BaseObject ; Here we'd store all the fields unique to this alien type EndType ; Create Array of BaseObject as our parent container Dim Objects(1) As BaseObject ; Assign Element 1 in the object array the Player TYPE Objects(1) = New PLayer ; ================================================== ; Randomly Allocate 10 ALiens to the Object Array ; ================================================== For lp=0 To 10 ; Request a Free element Index from the Object() array Index=GetFreeCell(Objects()) ; Randomly allocate a NEW type and store it in ; this position in the Object() array objects(Index)= New (Alien1+Rnd(1)) Next Print "---------------------------------------" Print "Types" Print "---------------------------------------" ; Loop Through and display the User defined Type of ; each element in this array For lp=1 To GetArrayElements(objects(),1) ; Get the user defined type index of this ; element within the Object array ; using the TypeOF() function Select TypeOf(Objects(lp)) Case Player Print "Player" Case Alien1 Print "ALien 1" Case Alien2 Print "Alien 2" Default Print "unknown:"+Str$(TypeOf(Objects(lp))) EndSelect Next Sync WaitKey |
This example would output. --------------------------------------- Types --------------------------------------- Player Alien 2 ALien 1 Alien 2 Alien 2 Alien 2 ALien 1 Alien 2 Alien 2 Alien 2 Alien 2 Alien 2 |
|