Hi, I'm getting some strange things happen when i run my code. For some reason when i run my code the program closes itself with an "This program has encounterd an error and needs to be closed" error. i have checked my code many times and found a few bugs, corrected them and still i get this error. Dark Basic Pro will not hint at what is wrong. I ran my program in stepthrough mode to see if it would shed any light on the matter although it sadly didnt although for some reason its not going into some of my FOR loops.
here is the code i'm useing and sorry if its not to neat. I have also included my array maps at the end incase this makes any difrence.
sync on
sync rate 40
autocam off
set camera range 1,1000000000
set image colorkey 0,0,0
`load image "outhers\loading.bmp",99
`sprite 1,screen width()/2,screen height()/2,99
gosub setup:
do
Gosub rotate_textures:
Gosub control:
Gosub AI:
Gosub Setup:
Gosub Bullet_handler:
sync
loop
control:
if upkey()=1 then pitch camera up 1
if downkey()=1 then pitch camera down 1
if leftkey()=1 then turn camera left 1
if rightkey()=1 then turn camera right 1
if mouseclick()=1 then move camera 2
if mouseclick()=2 then move camera -2
if mouseclick()=3 then rotate camera 0,0,0
return
AI:
`==========================================================
for B = Blue_Start_Range# to (Blue_Start_Range# + Ship_Max_Blue#)
`Check to see if ship is alive
If Blue(B,2) = Red(Blue(B,2),1)=1
Blue(B,2) = Rnd(Ship_Max_Red#)+1
else
Point object (Blue_Start_Range#+B),object position x(Blue(B,2)),Object position y(Blue(B,2)), object position z(Blue(B,2))
Move Object (Blue_Start_Range#+B),Blue(B,7)
px=abs(object position x((Blue_Start_Range#+B))-object position x(Blue(B,2)))
py=abs(object position y((Blue_Start_Range#+B))-object position y(Blue(B,2)))
pz=abs(object position z((Blue_Start_Range#+B))-object position z(Blue(B,2)))
Blue(B,3)=sqrt((px*px)+(py*py)+(pz*pz))
If Blue(B,3) =< 500 and Blue(B,8) = 0
For Bullet = Bullet_Start_Range# to bullet_stop#=1 or bullet=(bullet_start_range# + bullet_max#)
If Bullet(Bullet,1)=0
position object bullet,object position x((Blue_Start_Range#+B)),object position y((Blue_Start_Range#+B)),object position z((Blue_Start_Range#+B))
point object bullet,object position x(Blue(B,2)),Object position y(Blue(B,2)), object position z(Blue(B,2))
show object bullet
bullet(bullet,1) = 1
bullet(bullet,2) = 650
Bullet(bullet,3) = 50
Bullet_stop=1
Blue(B,8)=1000
endif
Next Bullet
else
Blue(B,8) = Blue(B,8)-1
endif
endif
next B
`==========================================================
For R = Red_Start_Range# to (Red_Start_Range# + Ship_Max_Red#)
`Check to see if ship is alive
If Red(R,2) = Blue(Red(R,2),1)=1
Red(R,2) = Rnd(Ship_Max_Blue#)+1
else
Point object (Red_Start_Range#+R),object position x(Red(R,2)),Object position y(Red(R,2)), object position z(Red(R,2))
Move Object (Red_Start_Range#+R),Red(R,7)
px=abs(object position x((Red_Start_Range#+R))-object position x(Red(R,2)))
py=abs(object position y((Red_Start_Range#+R))-object position y(Red(R,2)))
pz=abs(object position z((Red_Start_Range#+R))-object position z(Red(R,2)))
Red(R,3)=sqrt((px*px)+(py*py)+(pz*pz))
If Red(R,3) =< 500 and Red(R,8) = 0
For Bullet = Bullet_Start_Range# to bullet_stop#=1 or bullet=(bullet_start_range# + bullet_max#)
If Bullet(Bullet,1)=0
Red(R,8)=1000
position object bullet,object position x((Red_Start_Range#+R)),object position y((Red_Start_Range#+R)),object position z((Red_Start_Range#+R))
point object bullet,object position x(Red(R,2)),Object position y(Red(R,2)), object position z(Red(R,2))
show object bullet
bullet(bullet,1) = 2
bullet(bullet,2) = 650
Bullet(bullet,3) = 50
Bullet_stop=1
endif
Next Bullet
else
Red(R,8) = Red(R,8)-1
endif
endif
Next R
`==========================================================
Return
Bullet_handler:
for Bullet = Bullet_Start_Range# to bullet = (bullet_start_range# + bullet_max#)
If Bullet(bullet,1) > 0
move object bullet,Bullet(bullet,4)
Bullet(bullet,2) = bullet(bullet,2) - 1
Bullet(bullet,3) = Bullet(bullet,3) - 0.02
If bullet(bullet,2) =< 0
bullet(bullet,1) = 0
bullet(bullet,2) = 0
bullet(bullet,3) = 25
bullet(bullet,4) = 25
Hide object Bullet
endif
endif
next bullet
return
Setup:
`Textures:
load image "textures\space\starscape.bmp",1 : sync
load image "textures\planet\Planet_Ice_0006.bmp",2 : sync
load image "textures\planet\cloud.jpg",3 : sync
load image "textures\planet\PlanetGlow 3.bmp",4 : sync
load image "textures\space\storm5.bmp",5 : sync
load image "textures\sfx\bullet.bmp",6 : sync
`Objects
`skysphere
make object sphere 1,-20000,20,20
texture object 1,1
`planet
make object sphere 2,100,40,40
texture object 2,2
`Inner Sky
make object sphere 3,-19900,20,20
texture object 3,5
ghost object on 3
`planet atmosphere
make object sphere 6,101,40,40
texture object 6,3
ghost object on 6
`Planet Glow
make object plain 7,165,165
texture object 7,4
ghost object on 7,10
set object 7,1,1,1,0
`Arrays:
`(See end of code for array maps.)
`The ship max can not be higher than the difrence in the blue and red start ranges.
`if they are this will crash the program.
Ship_Max_Blue#=2
Ship_Max_Red#=2
Bullet_Max#=15
`setup the arrays
Dim Blue(Ship_Max_Blue#,8)
Dim Red(Ship_Max_Red#,8)
Dim Bullet(bullet_max#,4)
`this is the starting object number for the ships. they MUST NOT overlap.
Blue_Start_Range#=100
Red_Start_Range#=300
Bullet_Start_Range#=500
Red_Total# = ( Red_Start_Range# + Ship_Max_Red# )
Blue_Total# = ( Blue_Start_Range# + Ship_Max_Blue# )
`=============
`=Setup Ships=
`=============
load object "testin.3ds",10 : hide object 10
For R = Red_Start_Range to R = Red_Total#
clone object R,10
position object R,rnd(5000)+1,rnd(5000)+1,rnd(5000)+1
color object R,rgb(255,0,0)
wait 1000
sync
next R
load object "testin.3ds",11 : hide object 11
For B = Blue_Start_Range# to B = Blue_Total#
Clone object B,11
position object B,rnd(5000)+1,rnd(5000)+1,rnd(5000)+1
color object B,rgb(0,0,255)
sync
next B
For B = 1 to B = Ship_Max_Blue#
Blue(B,1) = 0
Blue(B,2) = Rnd(Ship_Max_Red#)+1
Blue(B,4) = 2500
Blue(B,5) = 500
Blue(B,6) = 1 `only 1 wepon type since theres only 1 ship type at the min ^^
Blue(B,7) = 10
Blue(B,8) = 0
sync
Next B
For R = 1 to R = Ship_Max_Red#
Red(R,1) = 0
Red(R,2) = Rnd(Ship_Max_Blue#)+1
Red(R,4) = 2500
Red(R,5) = 500
Red(R,6) = 1 `only 1 wepon type since theres only 1 ship type at the min ^^
Red(R,7) = 10
Red(R,8) = 0
sync
Next R#
For Bullet=Bullet_Start_Range# to Bullet=(Bullet_start_range# + bullet_max#)
Make object plain bullet#,10,10
Bullet(Bullet,1) = 0
Bullet(Bullet,2) = 0
Bullet(Bullet,3) = 25
Bullet(Bullet,4) = 25
texture object bullet,6
hide object bullet
sync
Next Bullet
` delete sprite 1
` delete image 99
Return
rotate_textures:
`i know this is not a texture but meh it still needs to move and behave kinda like one.
point object 7,camera position x(),camera position y(), camera position z()
`scroll the clouds.
scroll object texture 6,0.0005,0
return
remstart
============================================================================
========================Array map for team 1 & 2============================
==========================ship information:=================================
ship number number of ship (must be unique) =
=
Sheilds max shield strength =
=
Hull max hull strength =
=
Wepon type: Stored in difrent array: =
wepon strength =
wepon range =
wepon file =
Team =
combat ship or not: 1=combat 0= non combat =
score: score for killing ship =
=
=
Blue(ship number,stat , value ) =
1. destroyed , 0 = alive =
1 = dead =
2. targit X = targit num =
3. Targit dist X = Distance to targit =
4. shields X = Shields left =
5. hull X = Hull points left =
6. wepon X = wepon Type (not rely used yet.) =
7. move speed X = Max speed =
8. Cooldown X = time till can next fire =
Ship model Range's =
=
============================================================================
========================Array map for Bullets===============================
=========================Bullet information:================================
Bullet(number,value ) =
1. Owner 0. Dead =
1. Blue =
2. Red =
2. Life X = bullet life (range in units it can travel) =
3. Damage X = Damage of projectile. (Based upon wepon of ship)
can lower with bullet life. =
4. Speed X = Bullet speed =
=============================================================================
remend
If anyone can help i would be V greatful
also i have attached the media used and the project files.