Another object question

BlitzMax Forums/BlitzMax Beginners Area/Another object question

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Your code is a bit confusing.
If you do your eachin against playerselection it will show all playerselection objects. If you do it against displayitem it will do all playerselection AND any other objects on displist which has been extended from displayitem.
I was hoping the colours would show this better but this might help...
SetGraphicsDriver GLMax2DDriver()
Type displayitem
  Global displist:TList 
  Field x
  Field y
  Method showitem()
    DrawRect x,y,10,10
  End Method

  Method New()
    displist.addlast Self
  End Method
End Type

Type player1 Extends displayitem

  Function create()
     If displist=Null displist=CreateList()
     p1:player1 = New player1
     p1.x = Rand(1,200)
     p1.y = Rand(1,200)  
     displist.addlast p1  
  End Function
End Type
Type player2 Extends displayitem

  Function create()
     If displist=Null displist=CreateList()
     p2:player2= New player2
     p2.x = Rand(1,200)
     p2.y = Rand(1,200) 
     displist.addlast p2   
  End Function
End Type


Graphics 640,480
SeedRnd MilliSecs()
Local p1:player1
Local p2:player2
Local a

For a = 1 To 10
   player1.create()
Next
For a = 1 To 10
   player2.create()
Next
  Cls
  SetColor 255,0,0
  DrawText "Player 1 types",0,0
  For my1:player1 = EachIn player1.displist
    my1.showitem()
  Next
  Flip
  WaitChar
  SetColor 0,0,255
  DrawText "and Player 2 types",0,10
  DrawText "Hit any key",0,30
  For my2:player2 = EachIn player2.displist
    my2.showitem()
  Next
  Flip
  WaitChar
  Cls
  SetColor 0,255,0
  DrawText "and displayitem",0,0
  For my3:displayitem = EachIn displayitem.displist
    my3.showitem()
  Next
  Flip
  WaitChar
End

<edit> that's better. Good ole GLdriver