help with code...

Blitz3D Forums/Blitz3D Beginners Area/help with code...

Ok, I haven't used this for a while so I'm stumped, in finding the problem in my code... Every time I try and run the code, I get a "memory access violation". If any one can help I would be most thankful. I also am going to change the code to a more FPS format but I have to find this error first, THANKS!

here is the code...

Graphics3D 640,480
SetBuffer BackBuffer()

type_camera=1
type_entity=2
type_bullet=3
type_player=4


Function pause()
Text 100,150, "Game Paused - press any key (except P or start) to continue"

WaitKey()
WaitJoy()
End Function 

;Function fade()   
;Include "fade.bb"
;End Function 








light=CreateLight()


Global camera=CreateCamera()
PositionEntity camera,1,1,0
CameraClsColor camera,92,236,222
EntityType camera, type_camera 
CameraRange camera,.001,1000



Global camera2=CreateCamera()
PositionEntity camera2,0,1,-10
CameraClsColor camera2,92,236,222
RotateEntity camera2,0,90,0 
CameraRange camera2,.001,1000
EntityType camera2,type_camera





CameraViewport camera,0,0,GraphicsWidth()/2,GraphicsHeight()
CameraViewport camera2,GraphicsWidth()/2,0, GraphicsWidth()/2,GraphicsHeight()

Global camsphere=CreateSphere()
EntityType camsphere,type_player
Global camsphere2=CreateSphere()
EntityType camsphere2,type_player


plane=CreatePlane()
EntityType plane,type_entity 


Ptex=LoadTexture("grass.jpg")
EntityTexture plane,ptex


Global mesh=LoadMesh("building1.b3d")
PositionEntity mesh,0,.35, 10
ScaleEntity mesh,.05,.05,.05
EntityType mesh, type_entity


Global gun=LoadMesh("guns\\w_fiveseven.3ds",camera)
PositionEntity gun,.1,-.2,.3
ScaleEntity gun,.05,.05,.05
RotateEntity gun,90,-75,0


Global gun2=LoadMesh("guns\\w_fiveseven.3ds",camera2)
PositionEntity gun2,.1,-.2,.3
ScaleEntity gun2,.05,.05,.05
RotateEntity gun2,90,-75,0
;EntityParent gun2,camera2

Global fullcart=100
Dim bullet(fullcart)
For i=0 To fullcart
 bullet(i)=CreateSphere()
EntityColor bullet(i),100,100,100
ScaleEntity bullet(i),0.2,0.4,0.2
HideEntity bullet(i)
Next 

Global fullcart2=100
Dim bullet2(fullcart2)
For ii=0 To fullcart2
 bullet2(ii)=LoadMesh("guns\\bullet.3DS")
EntityColor bullet2(ii),100,100,100
ScaleEntity bullet2(ii),0.2,0.4,0.2
HideEntity bullet2(ii)
Next 
EntityType bullet2(ii),type_bullet
EntityType bullet(i),type_bullet





Collisions type_camera,type_entity,2,2
Collisions Type_bullet,type_player,2,2

While Not KeyDown(1)




;If EntityCollided(type_bullet,camsphere) Then 
;HideEntity bullet2
;EndIf 




If KeyDown(208) Then MoveEntity camera2,0,0,-.25
If KeyDown(200) Then MoveEntity camera2,0,0,.25
If KeyDown(203) Then MoveEntity camera2,-.25,0,0
If KeyDown(205) Then MoveEntity camera2,.25,0,0



TurnEntity camera2, 0, -MouseXSpeed()/5.0,0,1	;rotate player Pivot according to mouse X movement
TurnEntity camera2, MouseYSpeed()/5.0, 0,0,0

If EntityPitch(camera2) < -45					;don't allow camera to look below -45 degrees
  RotateEntity camera2, -45, EntityYaw(camera2), EntityRoll(camera2)
EndIf 
If EntityPitch(camera2) > 45					;don't allow camera to look above 45 degrees
  RotateEntity camera2, 45, EntityYaw(camera2), EntityRoll(camera2)
EndIf
MoveMouse GraphicsWidth()/1.3, GraphicsHeight()/2.1		;reset mouse position to middle of screen






If JoyXDir() = -1 MoveEntity camera,-.25,0,0
If JoyXDir() = 1 MoveEntity camera,.25,0,0
If JoyYDir() = -1 MoveEntity camera,0,0,.25
If JoyYDir() = 1 MoveEntity camera,0,0,-.25

;If JoyXDir() = -1 TurnEntity camera,0,1,0
;If JoyXDir() = 1 TurnEntity camera,0,-1,0
;If JoyYDir() = -1 TurnEntity camera,-1,0,0
;If JoyYDir() = 1 TurnEntity camera,1,0,0

;If JoyDown(1) MoveEntity camera,-.1,0,0
;If JoyDown(3) MoveEntity camera,.1,0,0
;If JoyDown(4) MoveEntity camera,0,0,.1
;If JoyDown(2) MoveEntity camera,0,0,-.1

If JoyDown(1) TurnEntity camera,0,2,0,1
If JoyDown(3) TurnEntity camera,0,-2,0,1
If JoyDown(4) TurnEntity camera,-2,0,0
If JoyDown(2) TurnEntity camera,2,0,0







If t=100
t=1
reload=1
EndIf

If tt=100
tt=1
reload2=1
EndIf




If JoyHit(6) Then
ShowEntity bullet(t)
EntityParent bullet(t),0

PositionEntity bullet(t),EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1)
RotateEntity bullet(t),EntityPitch#(camera,1),EntityYaw#(camera,1),EntityRoll#(camera,1)
EntityColor bullet(t),Rand(0,255),Rand(0,255),Rand(0,255)
t=t+1
 
End If

For q=0 To fullcart
MoveEntity bullet(q),.3,.5,3
Next


If MouseHit(1) Then
ShowEntity bullet2(tt)
EntityParent bullet2(tt),0

PositionEntity bullet2(tt),EntityX(gun2,1),EntityY(gun2,1),EntityZ(gun2,1)
RotateEntity bullet2(tt),EntityPitch#(camera2,1),EntityYaw#(camera2,1),EntityRoll#(camera2,1)
EntityColor bullet(tt),Rand(0,255),Rand(0,255),Rand(0,255)
tt=tt+1
 
End If

For qq=0 To fullcart2
MoveEntity bullet2(qq),-.3,.5,3
Next

bulletcount=100-t
bulletcount2=100-tt





PositionEntity camsphere,EntityX(camera),EntityY(camera),EntityZ(camera)
PositionEntity camsphere2,EntityX(camera2),EntityY(camera2),EntityZ(camera2)
If EntityY(camera)<2.0 Then PositionEntity camera,EntityX(camera),2.0,EntityZ(camera) 
If EntityY(camera2)<2.0 Then PositionEntity camera2,EntityX(camera2),2.0,EntityZ(camera2) 
TranslateEntity camera,0,-.25,0
TranslateEntity camera2,0,-.25,0




;If MouseHit(2) And reload2=0 Then
;tt=1

;EndIf

If bullet2(tt)=0 Then HideEntity bullet2(tt) 











RenderWorld 
UpdateWorld 


Text 0,15,  "bullets remaining:"+ bulletcount
If reload2=1 Then Text 300,30, "click right Mouse button to reload"



Text 325,15, "bullets remaining:"+ bulletcount2

Text 200,0,EntityX(camera,True)
 Text 200,15,EntityY(camera,True)
 Text 200,30,EntityZ(camera,True) 

Text 600,0,EntityX(camera2,True)
 Text 600,15,EntityY(camera2,True)
 Text 600,30,EntityZ(camera2,True) 

If KeyDown(25) Then pause 
If JoyDown(10) Then pause
Flip

Wend


End