I don't know why it happens but if you reduce the computer controlled cars to 4 it'll work.
Also your use of "gosub" needs to be changed. When you use "gosub" it means that somewhere you'll "return" back to the line after the "gosub".
Your "gosub"s:
If you're going to go to the next line down... there's no need for "gosub" or even the label.
`Pick Car
If car=1
Load Object "Media/car.x",1
rotate Object 1,0,180,0
Scale object 1,400,400,400
carspeed#(1)=0.3 : caraccel#(1)=0.003 : carweight#(1)=2
gosub rest
endif
If car=2
Load Object "Media/van.x",1
rotate Object 1,0,180,0
Scale object 1,400,400,400
carspeed#(1)=0.35 : caraccel#(1)=0.001 : carweight#(1)=4
gosub rest
endif
rest:
These two "if" statements don't need "gosub rest" because once the "endif" is seen in either of them it goes to the next line in the code. The label isn't needed either.
The proper use of "gosub" is like this:
do
gosub PrintT
inc Numb
loop
PrintT:
print "Hello #"+str$(Numb)
return
Make sure to always have a "return". If you use "gosub" after "gosub" without a return the program will eventually crash. If you won't want to "return" use "goto" but it's best to avoid using "goto" because it leads to spaghetti code.
Here's your code with the "gosub"s remed off and the computer cars reduced:
REM Project: RacingGame
REM Created: 2/16/2006 5:54:43 PM
REM
REM ***** Main Source File *****
`QUESTIONS!
`Pick Car
`gosub start
`start:
Set cursor 10,10
Print "PICK YER CAR KYLE!"
INPUT "Car(1) or Van(2): ",car
` Game Settings
Sync On
Sync Rate 40
Autocam Off
Set Ambient Light 100
`Declare All Variables
`AI stuff
currentturn=1
turnnum=0 : turnnum2=0 : turnnum3=0
dim track(20,20):` as integer
dim turnx(25,5) :`as integer
dim turnz(25,5) :`as integer
dim x#(6) : dim z#(6)
dim AIturn#(5) : dim AIspeed#(5)
dim AIaccel#(5) : dim AIfriction#(5)
dim currentturn(5) : dim turnpoint(5)
dim posx(5) : dim posz(5)
dim caraccel#(6) : dim carspeed#(6) : dim carweight#(6)
forward=0 : backward=0 : left#=0 : right#=0
friction#=0 : speed#=0 : accel#=0 : turn#=0
`Pick Car
If car=1
Load Object "Media/car.x",1
rotate Object 1,0,180,0
Scale object 1,400,400,400
carspeed#(1)=0.3 : caraccel#(1)=0.003 : carweight#(1)=2
`gosub rest
endif
If car=2
Load Object "Media/van.x",1
rotate Object 1,0,180,0
Scale object 1,400,400,400
carspeed#(1)=0.35 : caraccel#(1)=0.001 : carweight#(1)=4
`gosub rest
endif
`rest:
`Load Test AI cars
for a=2 to 6
c=rnd(2)
If c=1
Load Object "Media/car.x",a
rotate Object a,0,180,0
Scale object a,400,400,400
carspeed#(a)=0.3 : caraccel#(a)=0.003 : carweight#(a)=2
else
Load Object "Media/van.x",a
rotate Object a,0,180,0
Scale object a,400,400,400
carspeed#(a)=0.35 : caraccel#(a)=0.001 : carweight#(a)=4
endif
currentturn(a-1)=1
turnpoint(a-1)=a-1
next a
`Load the test-map
Load Image "Media/Road.bmp",1,1
Make Object Cube 100,200
Scale Object 100,100,2,100
Position Object 100,100,-2.5,100
Texture Object 100,1
`Read the Map.txt
xpos=0 : zpos=0
xpos1=1 : zpos1=1
turnnum=-96
for a=0 to 440
map#=Read Byte From File ("Media/TestMap.txt",a)
If map#=48
track(xpos1,zpos1)=0
endif
If map#=49
track(xpos1,zpos1)=1
endif
If map#=50
track(xpos1,zpos1)=0
endif
If map#=56
track(xpos1,zpos1)=1
endif
If map#=57
track(xpos1,zpos1)=1
x(1)#=xpos+4
z(1)#=zpos+14
magicnum=8
magicnum2=6
for h=2 to 6
x#(h)=xpos+magicnum
z#(h)=zpos+magicnum2
magicnum=magicnum-4
if magicnum<4
magicnum=8
magicnum2=magicnum2+4
endif
next h
endif
If map#>96 and map#<123
turnnum2=turnnum+map#
for b=1 to 5
if b<3 then magicx=3
if b>3 then magicx=7
if b=1 or b=4 then magicz=3
if b=2 or b=5 then magicz=7
if b=3
magicx=5
magicz=5
endif
if turnnum2>turnnum3 then turnnum3=turnnum2
track(xpos1,zpos1)=2
turnx(turnnum2,b)=xpos+magicx
turnz(turnnum2,b)=zpos+magicz
next b
b=rnd(4)+1
endif
if map#=10 or map#=13
xpos1=xpos1-1
xpos=xpos-10
endif
xpos=xpos+10
xpos1=xpos1+1
if xpos=200
xpos=0
zpos=zpos+10
endif
if xpos1=21
xpos1=1
zpos1=zpos1+1
endif
next a
Position Camera x#(1),y#,z#(1)
`Main Game Loop
Do
`ArrowKeys Movement
If upkey()=1 then forward#=caraccel#(1) else forward#=0
If downkey()=1 then backward#=caraccel#(1) else backward#=0
If leftkey()=1 then left#=1.2 else left#=0
If rightkey()=1 then right#=1.2 else right#=0
`Charecter Movement
a#=object angle y(1)
`if you're moving forward backward or not moving
accel#=(forward#-backward#)
`friction
if accel#=0
if speed#>0 then speed#=speed#-(friction#*2)
if speed#<0 then speed#=speed#+(friction#*2)
endif
speed#=(speed#+accel#)
`Max Speed and so you actually stop at some point
if speed#>carspeed#(1)-(friction#*30) then speed#=carspeed#(1)-(friction#*30)
if speed#<-carspeed#(1)+friction# then speed#=-carspeed#(1)+friction#
if speed#>-0.00009
if speed#<0.00004 then speed#=0
endif
`Turning
turn#=right#-left#
if turn#<>0
if speed#<0.00009 or speed#>-0.00004
turn#=turn#+(speed#/2)
yrotate object 1,wrapvalue(object angle y(1)+turn#)
if speed#>0.001 then speed#=speed#-caraccel#(1)-0.001
if turn#>0 then turn#=turn#-0.05
if turn#<0 then turn#=turn#+0.05
endif
endif
`Move You
x#(1)=newxvalue(x#(1),a#,speed#) : z#(1)=newzvalue(z#(1),a#,speed#)
Position Object 1,x#(1),y#,z#(1)
`Com AIS!!!!!!!
for AI=2 to 5
AIaccel#(AI)=caraccel#(AI)
AIspeed#(AI)=AIspeed#(AI)+AIaccel#(AI)
if AIspeed#(AI)>carspeed#(AI)-(AIfriction#(AI)*30) then AIspeed#(AI)=carspeed#(AI)-(AIfriction#(AI)*39)
if x#(AI)<turnx(currentturn(AI),turnpoint(AI))+8 and x#(AI)>turnx(currentturn(AI),turnpoint(AI))-8
if z#(AI)<turnz(currentturn(AI),turnpoint(AI))+8 and z#(AI)>turnz(currentturn(AI),turnpoint(AI))-8
if currentturn(AI)=turnnum3
currentturn(AI)=1
else
currentturn(AI)=currentturn(AI)+1
endif
turnpoint(AI)=turnpoint(AI)+1
if turnpoint(AI)=>5 then turnpoint(AI)=1
endif
endif
`position to the left of the object
move object left AI,5
leftx1#=object position x(AI)
leftz1#=object position z(AI)
`position to the right of the object
move object right AI,5
rightx1#=object position x(AI)
rightz1#=object position z(AI)
`Distance Formula
If Sqrt((leftx1#-turnx(currentturn(AI),turnpoint(AI)))^2+(leftz1#-turnz(currentturn(AI),turnpoint(AI)))^2) < Sqrt((rightx1#-turnx(currentturn(AI),turnpoint(AI)))^2+(rightz1#-turnz(currentturn(AI),turnpoint(AI)))^2)+0.1
yrotate object AI,wrapvalue(object angle y(AI)-1.4)
endif
If Sqrt((leftx1#-turnx(currentturn(AI),turnpoint(AI)))^2+(leftz1#-turnz(currentturn(AI),turnpoint(AI)))^2) > Sqrt((rightx1#-turnx(currentturn(AI),turnpoint(AI)))^2+(rightz1#-turnz(currentturn(AI),turnpoint(AI)))^2)-0.1
yrotate object AI,wrapvalue(object angle y(AI)+1.4)
endif
a1#=object angle y(AI)
x#(AI)=newxvalue(x#(AI),a1#,AIspeed#(AI)) : z#(AI)=newzvalue(z#(AI),a1#,AIspeed#(AI))
Position Object AI,x#(AI),y#,z#(AI)
next AI
`Car's Collision
for f=1 to 5
for g=1 to 5
if f<>g
if object collision(f,g)>0
bouncex#=x#(f)-x#(g)
bouncez#=z#(f)-z#(g)
If carweight#(f)>carweight#(g)
x#(g)=x#(g)+bouncex#
z#(g)=z#(g)+bouncez#
endif
If carweight#(f)<carweight#(g)
x#(f)=x#(f)+bouncex#
z#(f)=z#(f)+bouncez#
endif
If carweight#(f)=carweight#(g)
x#(f)=x#(f)+bouncex#
z#(f)=z#(f)+bouncez#
x#(g)=x#(g)-bouncex#
z#(g)=z#(g)-bouncez#
endif
endif
endif
next g
next f
`Friction
posx=(Object position x(1)/10)+1
posz=(Object position z(1)/10)+1
for h=2 to 6
posx(h-1)=(Object position x(h)/10)+1
posz(h-1)=(Object position z(h)/10)+1
if track(posx(h-1),posz(h-1))=0
AIfriction#(h-1)=0.002
else
AIfriction#(h-1)=0.0002
endif
next h
if track(posx,posz)=0
friction#=0.002
else
friction#=0.0002
Print "ON TRACK"
endif
`Beta Tests
Set Cursor 10,10
Print "x: ",x#(1)," z: ",z#(1)
`Chase Cam
Set camera to follow x#(1),y#,z#(1),a#,6,2,5,0
Sync
Loop