new array probs

Blitz3D Forums/Blitz3D Programming/new array probs

Following Sybixus [bad spelling me] suggestion and help I could read the array... worked good until I made it 3d.
; Game 1

Graphics3D 800,600,16,1			; set screen size
SetBuffer BackBuffer()
SeedRnd(MilliSecs()) + Pi
AppTitle "BlowOFF - The game for the rest of us!","Do you Quit?"
; All Bullet Stuff from Ross including timer...
Global main_bullet=LoadMesh("sperm1.b3d"); create a bullet that the type objects can copy.
Global turret=LoadAnimMesh("penis1.b3d")
Global egg=LoadMesh("egg1.b3d")
Global gun_timer=MilliSecs() ; timer to track the difference in millisecs
Global gun_time=250; time in milliseconds that the gun will fire
Dim ova(80,80,80) ; OVA array

camera=CreateCamera()			; create something to see with
PositionEntity camera,0,10,-15

ScaleEntity main_bullet,1.5,1.5,1.5
HideEntity main_bullet

Type bullet
	Field entity
	Field speed#
	Field range
	Field pivot
End Type

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- CREATE ARRAY to hold egg position and fill with 0 for now

For ov=0 To 79
For ovo= 0 To 79
For ovp = 0 To 79
ova(ov,ovo,ovp) = 0 
Next
Next




light=CreateLight()				; I will dispense with the biblical reference
RotateEntity light,45,0,0		; move the light a bit to create shadows on the model
AmbientLight 32,32,32



PositionEntity turret,0,0,0



bip=LoadSound("bip.ogg")

MoveMouse 400,300

;HidePointer



; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= load some eggs into the array
For eggz = 1 To 30
.redo
xova=Rand(79)
yova=Rand(79)
zova=Rand(79)
	If ova(xova,yova,zova)=1 Then Goto redo Else ova(xova,yova,zova)=1
Next

; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= THIS is the part I created to read the OVA array and put
;									new eggs on the screen... 
;For x=0 To 79
	;For y=0To 79
		;For z=0 To 79
		;If ova(x,y,z)=1 Then PositionEntity egg,x+10,y+10,z+10
	;Next 
;Next
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=	In or out it doesn't work!

While Not KeyHit(1)




If MouseX()>490 Then MoveMouse 490,MouseY()
If MouseX()<310 Then MoveMouse 310,MouseY()

xx=MouseXSpeed()
yy=MouseYSpeed()

TurnEntity turret,0,xx,0 	; rotate th turret
TurnEntity turret,yy,0,0		; angle the gun


	If MouseDown(1) And MilliSecs()>gun_time+gun_timer Then
	Animate turret,3
		gun_timer=MilliSecs() ; reset the timer
		create_bullet(turret); call function to create a bullet. Pass across the gun entity to the function
						  ; so the bullet can come from the guns position
		PlaySound(bip)
	End If
	
	update_bullet()



UpdateWorld
RenderWorld


Flip

Wend

End

Function create_bullet(turret_entity)
	b.bullet=New bullet
	
		temp_x=EntityX(turret_entity,True)
		temp_y=EntityY(turret_entity,True)
		temp_z=EntityZ(turret_entity,True)
		
		b\entity=CopyEntity(main_bullet) ; copy the main bullet entity , into the type object
		b\pivot=CreatePivot()
		
		PositionEntity b\entity,temp_x,temp_y,temp_z
		RotateEntity b\entity,EntityPitch(turret_entity,True),EntityYaw(turret_entity,True),0
		PositionEntity b\pivot,temp_x,temp_y,temp_z
		
		b\range=120 ; the range of the bullets
		b\speed=1 ; the speed of the bullets
End Function

Function update_bullet()
	For b.bullet = Each bullet
		MoveEntity b\entity,0,0,b\speed
			If EntityDistance#(b\entity,b\pivot) > b\range Then
			FreeEntity b\entity
			FreeEntity b\pivot
			Delete b.bullet
		End If
	Next
End Function
Now the first time I tried to run it it told me GLOBAL OUTSIDE MAIN PROGRAM... so I moved all the globals to the top near the start of the program.

NOW it tells me FUNCTION NOT ALLOWED OUTSIDE MAIN PROGRAM.

I don't understand??? I only changed the section that is noted in the source but even if I ";" it out the thing still refuses to run.

-RZ

HOLD THE PRESSES!!!

Missing one silly NEXT statement.

Never mind!

OK I fixed my "NEXT" probs... and it runs but I don't see any eggs...
; Game 1

Graphics3D 800,600,16,1			; set screen size
SetBuffer BackBuffer()
SeedRnd(MilliSecs()) + Pi
AppTitle "BlowOFF - The game for the rest of us!","Do you Quit?"
; All Bullet Stuff from Ross including timer...
Global main_bullet=LoadMesh("sperm1.b3d"); create a bullet that the type objects can copy.
Global turret=LoadAnimMesh("penis1.b3d")
Global egg=LoadMesh("egg1.b3d")
Global gun_timer=MilliSecs() ; timer to track the difference in millisecs
Global gun_time=250; time in milliseconds that the gun will fire
Dim ova(80,80) ; OVA array

camera=CreateCamera()			; create something to see with
PositionEntity camera,0,10,-15

ScaleEntity main_bullet,1.5,1.5,1.5
HideEntity main_bullet

Type bullet
	Field entity
	Field speed#
	Field range
	Field pivot
End Type

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- CREATE ARRAY to hold egg position and fill with 0 for now

For ov=0 To 79
	For ovo= 0 To 79
		ova(ov,ovo) = 0 
	Next
Next


light=CreateLight()				; I will dispense with the biblical reference
RotateEntity light,45,0,0		; move the light a bit to create shadows on the model
AmbientLight 32,32,32



PositionEntity turret,0,0,0



bip=LoadSound("bip.ogg")

MoveMouse 400,300

;HidePointer



; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= load some eggs into the array
For eggz = 1 To 30
.redo
xova=Rand(79)
yova=Rand(79)
	If ova(xova,yova)=1 Then Goto redo 
	ova(xova,yova)=1
Next

; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= THIS is the part I created to read the OVA array and put
;									New eggs on the screen... 

; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=	In or out it doesn't work!

While Not KeyHit(1)


For x=0 To 79
	For y=0To 79
		If ova(x,y)=1 Then PositionEntity egg,x*10,y*10,50
	Next
Next 



If MouseX()>490 Then MoveMouse 490,MouseY()
If MouseX()<310 Then MoveMouse 310,MouseY()
xx=MouseXSpeed()
yy=MouseYSpeed()

TurnEntity turret,0,xx,0 	; rotate th turret
TurnEntity turret,yy,0,0		; angle the gun


	If MouseDown(1) And MilliSecs()>gun_time+gun_timer Then
	Animate turret,3
		gun_timer=MilliSecs() ; reset the timer
		create_bullet(turret); call function to create a bullet. Pass across the gun entity to the function
						  ; so the bullet can come from the guns position
		PlaySound(bip)
	End If
	
	update_bullet()



UpdateWorld
RenderWorld


Flip

Wend

End

Function create_bullet(turret_entity)
	b.bullet=New bullet
	
		temp_x=EntityX(turret_entity,True)
		temp_y=EntityY(turret_entity,True)
		temp_z=EntityZ(turret_entity,True)
		
		b\entity=CopyEntity(main_bullet) ; copy the main bullet entity , into the type object
		b\pivot=CreatePivot()
		
		PositionEntity b\entity,temp_x,temp_y,temp_z
		RotateEntity b\entity,EntityPitch(turret_entity,True),EntityYaw(turret_entity,True),0
		PositionEntity b\pivot,temp_x,temp_y,temp_z
		
		b\range=120 ; the range of the bullets
		b\speed=1 ; the speed of the bullets
End Function

Function update_bullet()
	For b.bullet = Each bullet
		MoveEntity b\entity,0,0,b\speed
			If EntityDistance#(b\entity,b\pivot) > b\range Then
			FreeEntity b\entity
			FreeEntity b\pivot
			Delete b.bullet
		End If
	Next
End Function
???
Maybe... no...
-RZ