Now I have another problem. The game randomly crashes when it starts up. I was messing around with this code and I noticed it crashed at times.
sync on
sync rate 30
makenewtonworld(10000,5000,10000,0,-400,0)
setupnewtonvariables(100,100)
maketerrain("Mission 1.x","Mission 1.dds",1,1,0,0,0)
makebox(2,2000,150,-1000,125,25,80,50,1)
makesphere(3,30,250,55,25,2,0)
makesphere(4,30,250,-55,25,2,0)
makesphere(5,-30,250,55,25,2,0)
makesphere(6,-30,250,-55,25,2,0)
makevehicle(2,3,4,5,6,3,15,20,400,400,10,45,-40,40)
do
updatenewton()
controlvehicle(2,3,4,5,6,17,31,30,32,900000,-900000,.9,20,5,.25)
position camera object position x(2),object position y(2)+800,object position z(2)-900
point camera object position x(2),object position y(2),object position z(2)
sync
loop
function makenewtonworld(sizex#,sizey#,sizez#,gravityx#,gravityy#,gravityz#)
NDB_NewtonCreate
NDB_SetVector 1,-sizex#,-sizey#,-sizez#
NDB_SetVector 2,sizex#,sizey#,sizez#
NDB_NewtonSetWorldSize
NDB_SetVector 1,gravityx#,gravityy#,gravityz#
NDB_SetStandardGravity
endfunction
function setupnewtonvariables(vehicles,objects)
if vehicles>0
dim vehid(vehicles)
dim torque#(vehicles)
dim turnangle#(vehicles)
dim timer#(vehicles)
endif
if objects>0 then dim objid(objects)
endfunction
function updatenewton()
Sec#=NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate Sec#
yo=Array Count(vehid(0))
for x=1 to yo
if vehid(x)>0 then NDB_NewtonUpdateTires vehid(x)
next x
endfunction
function makebox(obj,px#,py#,pz#,sx#,sy#,sz#,mass#,flag)
make object box obj,sx#,sy#,sz#
if flag>0
position object obj,px#,py#,pz#
Col1=NDB_NewtonCreateBox(sx#,sy#,sz#)
Cube1=NDB_NewtonCreateBody(Col1)
NDB_NewtonReleaseCollision Col1
NDB_BuildMatrix 0,0,0,px#,py#,pz#
NDB_NewtonBodySetMatrix Cube1
NDB_CalculateMIBoxSolid mass#,sx#,sy#,sz#
NDB_NewtonBodySetMassMatrix Cube1,mass#
NDB_BodySetDBProData Cube1,obj
NDB_BodySetGravity Cube1,1
objid(obj)=Cube1
endif
endfunction
function makesphere(obj,px#,py#,pz#,s#,mass#,flag)
make object sphere obj,s#*2
if flag>0
position object obj,px#,py#,pz#
Col1=NDB_NewtonCreateSphere(s#)
Cube1=NDB_NewtonCreateBody(Col1)
NDB_NewtonReleaseCollision Col1
NDB_BuildMatrix 0,0,0,px#,py#,pz#
NDB_NewtonBodySetMatrix Cube1
NDB_CalculateMISphereSolid mass#,s#
NDB_NewtonBodySetMassMatrix Cube1,mass#
NDB_BodySetDBProData Cube1,obj
NDB_BodySetGravity Cube1,1
objid(obj)=Cube1
endif
endfunction
function makevehiclebody(x#,y#,z#,chaobj,chaimg,fronimg,backimg,w1,w2,w3,w4,chaobj$,chaimg$,fronobj$,fronimg$,backobj$,backimg,chamass#)
load object chaobj$,chaobj
load image chaimg$,chaimg
load object fronobj$,w1
load object fronobj$,w2
load image fronimg$,fronimg
load object backobj$,w3
load object backobj$,w4
load image backimg$,backimg
texture object chaobj,chaimg
texture object w1,fronimg
texture object w2,fronimg
texture object w3,backimg
texture object w4,backimg
Col1=NDB_NewtonCreateConvexHull(chaobj)
objid(chaobj)=NDB_NewtonCreateBody(Col1)
NDB_NewtonReleaseCollision Col1
NDB_BuildMatrix 0,0,0,x#,y#,z#
NDB_NewtonBodySetMatrix objid(chaobj)
NDB_NewtonBodySetMassMatrix objid(chaobj),chamass#
NDB_BodySetDBProData objid(chaobj),chaobj
NDB_BodySetGravity objid(chaboj),1
endfunction
function makevehicle(chassis,w1,w2,w3,w4,mass#,width#,radius#,sho#,spr#,length#,x#,y#,z#)
NDB_SetVector 0,1,0
vehid(chassis)=NDB_NewtonConstraintCreateVehicle(objid(chassis))
NDB_BuildMatrix 0,0,0,x#,y#,z#
NDB_SetVector 0,0,1
objid(w1)=NDB_NewtonVehicleAddTire(vehid(chassis),mass#,width#,radius#,sho#,spr#,length#)
NDB_VehicleTireSetDBProData vehid(chassis),objid(w1),w1
NDB_BuildMatrix 0,0,0,x#,y#,-z#
NDB_SetVector 0,0,1
objid(w2)=NDB_NewtonVehicleAddTire(vehid(chassis),mass#,width#,radius#,sho#,spr#,length#)
NDB_VehicleTireSetDBProData vehid(chassis),objid(w2),w2
NDB_BuildMatrix 0,0,0,-x#,y#,z#
NDB_SetVector 0,0,1
objid(w3)=NDB_NewtonVehicleAddTire(vehid(chassis),mass#,width#,radius#,sho#,spr#,length#)
NDB_VehicleTireSetDBProData vehid(chassis),objid(w3),w3
NDB_BuildMatrix 0,0,0,-x#,y#,-z#
NDB_SetVector 0,0,1
objid(w4)=NDB_NewtonVehicleAddTire(vehid(chassis),mass#,width#,radius#,sho#,spr#,length#)
NDB_VehicleTireSetDBProData vehid(chassis),objid(w4),w4
NDB_NewtonBodySetAutoFreeze objid(chassis),0
endfunction
function controlvehicle(vehid,w1,w2,w3,w4,forwardkey,backwardkey,turnleftkey,turnrightkey,forwardtorque#,backwardtorque#,torqueloss#,maxturn#,turnspeed#,turnloss#)
Okay=1
if timer#(vehid)>1 then dec timer#(vehid)
if keystate(forwardkey)=1 then torque#(vehid)=forwardtorque#
if keystate(backwardkey)=1 then torque#(vehid)=backwardtorque#
if keystate(turnleftkey)=1 then turnangle#(vehid)=turnangle#(vehid)-turnspeed#
if keystate(turnrightkey)=1 then turnangle#(vehid)=turnangle#(vehid)+turnspeed#
if keystate(forwardkey)=0 and keystate(backward)=0 then torque#(vehid)=torque#(vehid)*torqueloss#
if keystate(turnleftkey)=0 and keystate(turnrightkey)=0 then turnangle#(vehid)=turnangle#(vehid)*turnloss#
if turnangle#(vehid)>maxturn# then turnangle#(vehid)=maxturn#
if turnangle#(vehid)<-maxturn# then turnangle#(vehid)=maxturn#
for x=w1 to w4
if NDB_NewtonVehicleTireLostTraction(vehid(vehid),objid(x))=1
if timer#(vehid)=0 then timer#(vehid)=60
Okay=0
endif
next x
if Okay=1 then timer#(vehid)=0
if timer#(vehid)=1 then torque#(vehid)=0
for x=w1 to w4
NDB_VehicleTireSetTorque vehid(vehid),objid(x),torque#(vehid)
next x
for x=w3 to w4
NDB_VehicleTireSetSteeringAngle vehid(vehid),objid(x),turnangle#(vehid)
next x
endfunction
function maketerrain(file$,file2$,obj,img,xpos#,ypos#,zpos#)
load object file$,obj
load image file2$,img
texture object obj,img
position object obj,xpos#,ypos#,zpos#
Col=NDB_NewtonCreateTreeCollision(obj)
objid(obj)=NDB_NewtonCreateBody(Col)
NDB_NewtonReleaseCollision Col
NDB_BuildMatrix 0,0,0,xpos#,ypos#,zpos#
NDB_NewtonBodySetMatrix objid(obj)
NDB_NewtonBodySetMassMatrix objid(obj),0
NDB_BodySetDBProData objid(obj),obj
endfunction
function NEVAR()
if mesh exist(1) then end
if memblock exist(1) then end
endfunction
I compiled it 7 times in a row with the exact same code and one of them crashed. The new functions are setupnewtonvariables, makenewtonworld, makevehiclebody (which isn't used yet) and controlvehicle. Why is it crashing, and why does it only do it every once in a while, thanks in advance.
Codesurge is so awesome, thanks Hyrichter.