I have been programming in DarkBASIC Classic for around 2 years now, but i only recently switched to DB Pro.
Does Anyone know why can't you change the values of global variables from inside a function?...I'm working on a 3-D(3-D with 2-D perspective) space combat game, and I need to change The Data Of An Array Depending On What Numbers I Put In The Function Brackets...Here Is The Skin And Bones (about 5%) of my space game (without any media)...The following code won't work and i can't figure out why other than what i just explained...
Dim Ship#(3,25,8)
Hide Mouse
Autocam Off
Randomize Timer()
Sync On
NewShip(0,rnd(2),0,0,0)
For a=1 to 10
NewShip(rnd(3),0,rnd(100)-50,rnd(100)-50,rnd(15)*10)
Next a
Sync
Do
`If Upkey()=1 Then Ship#(0,1,1)=Ship#(0,1,1)+0.01
`If Leftkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)-0.05
`If Rightkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)+0.05
If Upkey()=1 Then Ship#(0,1,1)=Ship#(0,1,1)+Ship#(0,1,4)/200
If Leftkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)-Ship#(0,1,5)/40
If Rightkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)+Ship#(0,1,5)/40
Ship#(0,1,2)=Ship#(0,1,2)/1.03
Ship#(0,1,1)=Ship#(0,1,1)/1.02
YRotate Object 1,Wrapvalue(Object Angle Y(1)+Ship#(0,1,2))
Move Object 1,Ship#(0,1,1)
Position Camera Object Position X(1),45,Object Position Z(1)
Point Camera Object Position X(1),Object Position Y(1),Object Position Z(1)
Position Light 0,Object Position X(1),0,Object Position Z(1)
Sync
Loop
Function NewShip(Team#,Type#,XPosition#,ZPosition#,YAngle#)
For a#=(Team#*25)+1 to (Team#*25)+25
If Object Exist(a#)=0
Make Object Triangle a#,-0.5,0,-1,0.5,0,-1,0,0,1
Position Object a#,XPosition#,0,ZPosition#
YRotate Object a#,YAngle#
If Team#=0 Then Color Object a#,rgb(0,0,255)
If Team#=1 Then Color Object a#,rgb(255,0,0)
If Team#=2 Then Color Object a#,rgb(0,255,0)
If Team#=3 Then Color Object a#,rgb(255,255,0)
If Type#=0
Ship#(Team#,a#-(Team#*25),4)=2
Ship#(Team#,a#-(Team#*25),5)=2
Endif
If Type#=1
Ship#(Team#,a#-(Team#*25),4)=1
Ship#(Team#,a#-(Team#*25),5)=3
Endif
If Type#=2
Ship#(Team#,a#-(Team#*25),4)=3
Ship#(Team#,a#-(Team#*25),5)=1
Endif
ExitFunction
Endif
Next a#
Endfunction
But This Code Works Fine And It's Almost exactly the same code as before...
Dim Ship#(3,25,8)
Hide Mouse
Autocam Off
Randomize Timer()
Sync On
NewShip(0,rnd(2),0,0,0)
For a=1 to 10
NewShip(rnd(3),0,rnd(100)-50,rnd(100)-50,rnd(15)*10)
Next a
Sync
Do
If Upkey()=1 Then Ship#(0,1,1)=Ship#(0,1,1)+0.01
If Leftkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)-0.05
If Rightkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)+0.05
`If Upkey()=1 Then Ship#(0,1,1)=Ship#(0,1,1)+Ship#(0,1,4)/200
`If Leftkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)-Ship#(0,1,5)/40
`If Rightkey()=1 Then Ship#(0,1,2)=Ship#(0,1,2)+Ship#(0,1,5)/40
Ship#(0,1,2)=Ship#(0,1,2)/1.03
Ship#(0,1,1)=Ship#(0,1,1)/1.02
YRotate Object 1,Wrapvalue(Object Angle Y(1)+Ship#(0,1,2))
Move Object 1,Ship#(0,1,1)
Position Camera Object Position X(1),45,Object Position Z(1)
Point Camera Object Position X(1),Object Position Y(1),Object Position Z(1)
Position Light 0,Object Position X(1),0,Object Position Z(1)
Sync
Loop
Function NewShip(Team#,Type#,XPosition#,ZPosition#,YAngle#)
For a#=(Team#*25)+1 to (Team#*25)+25
If Object Exist(a#)=0
Make Object Triangle a#,-0.5,0,-1,0.5,0,-1,0,0,1
Position Object a#,XPosition#,0,ZPosition#
YRotate Object a#,YAngle#
If Team#=0 Then Color Object a#,rgb(0,0,255)
If Team#=1 Then Color Object a#,rgb(255,0,0)
If Team#=2 Then Color Object a#,rgb(0,255,0)
If Team#=3 Then Color Object a#,rgb(255,255,0)
If Type#=0
Ship#(Team#,a#-(Team#*25),4)=2
Ship#(Team#,a#-(Team#*25),5)=2
Endif
If Type#=1
Ship#(Team#,a#-(Team#*25),4)=1
Ship#(Team#,a#-(Team#*25),5)=3
Endif
If Type#=2
Ship#(Team#,a#-(Team#*25),4)=3
Ship#(Team#,a#-(Team#*25),5)=1
Endif
ExitFunction
Endif
Next a#
Endfunction
Any Ideas/Solutions Would Be Appreciated, and Thanks In Advance...
Anyone Can Destroy...But Few Can Create...