Could you help me to understand what's bad with this code ? Thanks !
My goal is to replace list by arrays into my game to access quickly and directly to an occurence (avoid a lot of 'for-eachin MyList-next loops) !
My goal is to replace list by arrays into my game to access quickly and directly to an occurence (avoid a lot of 'for-eachin MyList-next loops) !
Strict Global Rect_list : TList = CreateList() Type TRect Field Id : Int Field x : Int Field y : Int Field r : Int Field g : Int Field b : Int Function Create:TRect (id, x,y) Local r:TRect = New TRect r.Id = Id r.x = x r.y = y r.r = Rand (0,255) r.g = Rand (0,255) r.b = Rand (0,255) ListAddLast Rect_list, r End Function Function Draw_all_with_list () For Local r:TRect = EachIn Rect_list SetColor r.r,r.g,r.b DrawRect r.x, r.y, 32,32 Next SetColor 255,255,255 End Function Method Draw_it () SetColor r,g,b DrawRect x, y, 32,32 SetColor 255,255,255 End Method End Type Graphics 800,600 Global array_of_rect : TRect[] Local NbRect = Rand (100,200) For Local i=1 To NbRect TRect.Create (i,Rand (0,800),Rand (0,600)) Next array_of_rect = New TRect[NbRect] For Local i=0 To NbRect - 1 array_of_rect[i] = TRect.Create (i,Rand (0,800),Rand (0,600)) Next While Not KeyDown (KEY_ESCAPE) Cls TRect.Draw_all_with_list() array_of_rect[15].Draw_it() ' <---- i want display item 15 : ERROR : attempt to access field or null object Flip Wend