i created a nice little function that makes either bullets or missles but when i check the mode value it always seams to crash but only if i'm near a collidable object such as a spaceship if i'm not near an object it just doesn't create a bullet. i call the function using fire(1,1) for a laser and fire(1,2) for a missle. i have read through it once and there doesn,t seem to be any big problems with the code but i might have missed something.
Function fire(src,mode=1) If src=1 And mode=1 For p.player=Each player LinePick EntityX(p\piv),EntityY(p\piv),EntityZ(p\piv),0,0,-1000 If PickedEntity>0 PositionEntity p\apiv,PickedX(),PickedY(),PickedZ() Else PositionEntity p\apiv,0,0,-100 MoveEntity p\apiv,0,0,-10000 End If pnum=1-pnum If pnum=1 q=p\fpiv1 Else q=p\fpiv2 End If b.bullet=New bullet b\ent=CreateCube(q);LoadSprite("media\laser1.bmp",4,q) b\mode=1 b\x=0 b\y=0 b\z=0 PointEntity b\ent,p\apiv EntityParent b\ent,0 EntityType b\ent,lazer Next ElseIf src=1 And mode=2 For p.player=Each player If p\missle>0 p\missle=p\missle-1 b.bullet=New bullet b\ent=CreateCube(p\ent) b\mode=2 b\x=0 b\y=0 b\z=0 ScaleEntity b\ent,15,15,15 PointEntity b\ent,p\apiv EntityParent b\ent,0 EntityType b\ent,lazer End If Next Else If src=2 For e.enemy=Each enemy If e\firing=1 b.bullet=New bullet b\ent=LoadSprite("media\laser2.bmp",4,e\ent) b\x=0 b\y=0 b\z=0 PointEntity b\ent,e\apiv EntityParent b\ent,0 EntityType b\ent,lazer End If Next End If End Function Function updatefire() For b.bullet=Each bullet For e.enemy=Each enemy If b\mode=1 MoveEntity b\ent,0,0,-1 If EntityCollided (e\ent,lazer) FreeEntity b\ent Delete b e\hp=e\hp-10 End If ElseIf b\mode=2 MoveEntity b\ent,0,0,1 If EntityCollided (e\ent,lazer) FreeEntity b\ent Delete b e\hp=e\hp-100 End If End If Next Next End Function