For eachln?
BlitzMax Forums/BlitzMax Beginners Area/For eachln?
| ||
I cant to get it work and just want get some enemys ship coming down
Type Ship
Field x,y
End Type
Enemy_Ship=LoadImage("Ship.bmp")
' To create 20 Enemys Ship
For i=1 To 20
a:Ship=New Ship
a.x=Rand(1,640)
a.y=-10
Next
Repeat
For a:Ship=EachIn ship
DrawImage(Enemy_Ship,a.x,a.y)
a.y=a.y+Rand(1,5)
Next
Flip
Until KeyHit(KEY_ESCAPE)
|
| ||
It doesn't work like Blitz3D. You need to put your ship objects into a linked list (TList). Something like this (untested, straight into reply box):Type Ship
Field x,y
End Type
Enemy_Ship=LoadImage("Ship.bmp")
Local shipList:TList = New TList
' To create 20 Enemys Ship
For i=1 To 20
Local a:Ship=New Ship
a.x=Rand(1,640)
a.y=-10
shipList.AddLast(a)
Next
Repeat
Cls
For Local a:Ship=EachIn shipList
DrawImage(Enemy_Ship,a.x,a.y)
a.y=a.y+Rand(1,5)
Next
Flip
Until KeyHit(KEY_ESCAPE) |
| ||
| thanks for example GFK:) I get the error saying Unhandled exception: Attempt to access field or method of null object What does it really mean? |
| ||
Possibly because Enemy_Ship is an Int (by default). Change it to:
Local Enemy_Ship:TImage = LoadImage("Ship.bmp")
If not Enemy_Ship
RuntimeError "Nope, don't like that image you just tried to load. Either that or it just isn't where you said it was"
EndIf |
| ||
| thanks and managed get it working. I think Superstrict make the code more readable and handle better. Do you agree? |
| ||
| I think Superstrict make the code more readable and handle better. Do you agree? Always. |