The best way to squash nesting errors is to indent your code. I use just one space (others use tab). When you start any kind of loop you space it out so that the start of the loop is directly under the end of the loop. Using that method you can easily see when a loop starts and ends. Indenting makes it easier to debug too. Also don't be afraid to add blank lines in your code.
Non-indented Code (this code wasn't made by me):
for i = 1 to levels
for y = 1 to mapsize(i,2)
for x = 1 to mapsize(i,1)
a=rnd(7)
select a
case 0:map$(x,y,i,1) = "wall":endcase
case 1:map$(x,y,level,1) = "door":endcase
case 2:map$(x,y,level,1) = "floor":endcase
case 3:map$(x,y,level,1) = "key":endcase
case 4:map$(x,y,level,1) = "lock":endcase
case 5:map$(x,y,level,1) = "open":endcase
case 6:map$(x,y,level,1) = "up":endcase
case 7
map$(x,y,level,1) = "down"
playerx=x
playery=y
endcase
endselect
next x
next y
close file 1
next i
The above is very hard to follow whats going on because it's not indented. The next code snip is that same code only indented... notice how much easier it is to read and where each loop starts and ends.
for i = 1 to levels
for y = 1 to mapsize(i,2)
for x = 1 to mapsize(i,1)
a=rnd(7)
select a
case 0:map$(x,y,i,1) = "wall":endcase
case 1:map$(x,y,level,1) = "door":endcase
case 2:map$(x,y,level,1) = "floor":endcase
case 3:map$(x,y,level,1) = "key":endcase
case 4:map$(x,y,level,1) = "lock":endcase
case 5:map$(x,y,level,1) = "open":endcase
case 6:map$(x,y,level,1) = "up":endcase
case 7
map$(x,y,level,1) = "down"
playerx=x
playery=y
endcase
endselect
next x
next y
close file 1
next i
The next code snip is your own code indented. It appears that you had a "loop" at the end that was already closed right under the for/next loop. I just remed off the first "loop" and it runs.
rem setup screen refreshing
sync on
sync rate 30
rem setup mouse and fog and camera view
hide mouse
set camera range 1,5000
fog on
fog distance 4000
fog color rgb(128,128,128)
color backdrop rgb(128,128,128)
rem make gun
load mesh "tommygun.x",1
load image "tommy gun tex.bmp",2
make object 2,1,0
yrotate object 2,180
scale object 2,100,100,100
position object 2,5,-7,15
secondarybob=45
rem make world and texture it
make matrix 1,10000,10000,20,20
load image "texture.bmp",1
prepare matrix texture 1,1,1,1
fill matrix 1,0,1
randomize matrix 1,150
rem set variables x and z
x#=5000
z#=5000
rem main loop
do
rem variables
for i=1 to 360 step 5
secondarybob=secondarybob+8
if secondarybob>360 then secondarybob=0
yrotate object 2,wrapvalue((sin(wrapvalue(i))*10))
xrotate object 2,wrapvalue(sin(wrapvalue(secondarybob))*2)
sync
next i
`loop
oldcamangley#=cameraangley#
oldcamanglex#=cameraanglex#
cameraangley#=wrapvalue(cameraangley#+mousemovex()*0.2)
cameraanglex#=wrapvalue(cameraanglex#+mousemovey()*0.2)
rem controlling char/forward move
if upkey()=1
gunlag#=1.1
xtest#=newxvalue(x#,cameraangley#,10)
ztest#=newzvalue(z#,cameraangley#,10)
if xtest#>0 and xtest#<10000 and ztest#>0 and ztest#<10000
x#=xtest#
z#=ztest#
endif
endif
rem controlling char/backward move
if downkey()=1
gunlag#=1.1
xtest#=newxvalue(x#,wrapvalue(cameraangley#-180),10)
ztest#=newzvalue(z#,wrapvalue(camearangley#-180),10)
if xtest#>0 and xtest#<10000 and ztest#>0 and ztest#<10000
x#=xtest#
z#=ztest#
endif
endif
rem controlling char/strafe left
if leftkey()
gunlag#=1.1
xtest#=newxvalue(x#,wrapvalue(cameraangley#-90),10)
ztest#=newzvalue(z#,wrapvalue(cameraangley#-90),10)
if xtest#>0 and xtest#<10000 and ztest#>0 and ztest#<10000
x#=xtest#
z#=ztest#
endif
endif
rem controlling char/strafe right
if rightkey()
gunlag#=1.1
xtest#=newxvalue(x#,wrapvalue(cameraangley#+90),10)
ztest#=newzvalue(z#,wrapvalue(cameraangley#+90),10)
if xtest#>0 and xtest#<10000 and ztest#>0 and ztest#<10000
x#=xtest#
z#=ztest#
endif
endif
yrotate camera curveangle(cameraangley#,oldcamangley#,24)
xrotate camera curveangle(cameraanglex#,oldcamanglex#,24)
y#= get ground height(1,x#,z#)
position camera x#,y#+100,z#
sync
loop
To make code snips you do this:
[ code ]
Your code here.
[ /code ]
Just remove the spaces between the brackets... always put any code in code snips. You may have had your code indented but it won't be indented in the message if it's not in a code snip.