Hi People. I am having a major problem here. I am just trying to make a simple Space Invaders game in BMax to practice my programming. For some reason this code I have typed below is giving me an error saying:
"Unhandled Exception:Attempt to access field or method of Null Object"
The line which is highlighted is indicated by the arrow below:
Here is the code:
I just can't seem to figure this out. I know the answer is probably looking me right in the face, but at the moment I just can't see it and it's driving me up the wall.
Thank you for any help.
"Unhandled Exception:Attempt to access field or method of Null Object"
The line which is highlighted is indicated by the arrow below:
Here is the code:
Graphics 800,600,0 HideMouse() Local Player:TSpaceShip = TSpaceShip.CreateShip(0,500) Local GameObjectList:TList = CreateList() While Not KeyHit(KEY_ESCAPE) Cls For Objects:TGameObject = EachIn GameObjectList Objects.UpdateShip() Objects.DrawShip() Next Flip Wend Type TGameObject Field X:Int Field y:Int Field Speed:Int = 5 Field Image:TImage Method DrawShip() DrawImage Image,X,Y End Method Method UpdateShip() Abstract End Type Type TSpaceShip Extends TGameObject Function CreateShip:TSpaceShip(xstart:Int,ystart:Int) Local Ship:TSpaceShip = New TSpaceShip Ship.X = xstart Ship.Y = ystart Ship.Image = LoadImage("Images/ShipImage.png") ListAddLast GameObjectList,Ship <---------- Return Ship End Function Method UpdateShip() If KeyDown(KEY_LEFT) Then X:-Speed If KeyDown(KEY_RIGHT) Then X:+Speed If X<0 Then X = 0 If X> 700 Then X = 700 End Method End Type
I just can't seem to figure this out. I know the answer is probably looking me right in the face, but at the moment I just can't see it and it's driving me up the wall.
Thank you for any help.