Create sth.
BlitzMax Forums/BlitzMax Beginners Area/Create sth.
| ||
Strict Type Ball Field x Field y Field bl:TList Function Create:Ball(_x:Int, _y:Int) Local b:Ball b=New Ball b.x=_x b.y=_y If b.bl=Null Then b.bl=New TList Return(b) End Function Function ShowBalls() Local b:Ball=New Ball For b:Ball=EachIn b.bl Print "lol" Next End Function End Type Local b:Ball=Ball.Create(50,50) b.ShowBalls() WaitKey() I just want to create an object called Ball, if i call ShowBalls, i get this Error: Unhandled Exception: Attempt to access field or method of Null object ShowBalls [$BMXPATH/regaa/temp/temp.bmx;21;3] I know where the mistake is, but dont know how to solv this without global variables :(. |
| ||
ok, here s the code i've needed: THX to Dreamora: Strict Type Ball Global bl:TList Field x Field y Function Create:Ball(_x:Int, _y:Int) Local b:Ball b=New Ball b.x=_x b.y=_y If bl=Null Then bl=New TList bl.addlast( b ) Return b End Function Function ShowBalls() Local b:Ball For b:Ball=EachIn Ball.bl Print "lol" Next End Function End Type Local b:Ball=Ball.Create(50,50) b.ShowBalls() WaitKey() |
| ||
Please don't ShowBalls. :P |