Too late James!
I wrote an Indenting tool to format Peter's code.
There were a number of end if : end if lines which I also straightened out but I think the main problem was the ghostparam() function was placed beyond the main function. So I put in the directive for forward referencing #lookahead.
See if this works Peter
Charles
#basic
#lookahead
dim as sys map2(200),map3(200),map4(200),map5(200),xgos(100),ygos(100),rgos(200)
dim as sys idx,icx,ibx,rasreg
function rand(sys a) as sys
end function
function ghost()
if rasreg >0 then exit function 'you needn't brackets if a single "if" is giving!
for icx =1 to 13
for idx =1 to 18
ibx = icx *20 + idx
if ((map5(ibx)=103) or (map5(ibx)=102)) and ((map5(ibx-20)=84) or (map5(ibx+20)=84))
if map5(ibx-20)=84
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx+20)=84
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
end if
elseif ((map5(ibx)=86) or (map5(ibx)=101)) and ((map5(ibx-1)=84) or (map5(ibx+1)=84))
if map5(ibx-1)=84
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx+1)=84
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
end if
elseif (map5(ibx)=103) and (map5(ibx+1) =84)
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif (map5(ibx)=102) and (map5(ibx-1) =84)
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif (map5(ibx)=101) and (map5(ibx-20) =84)
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif (map5(ibx)=86) and (map5(ibx+20) =84)
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
'---------
elseif ((map5(ibx)=103) and (map5(ibx+1)>0)) or ((map5(ibx)=102) and (map5(ibx-1)>0)) '<--- here
iax = rand(2)
if iax =1
if map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx+20) =0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif (map5(ibx)=103) and (map5(ibx-1)=0)
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif (map5(ibx)=102) and (map5(ibx+1)=0)
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
else
ghostparam(5)
end if
elseif iax =2
if map5(ibx+20) =0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif map5(ibx-20) =0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif (map5(ibx)=103) and (map5(ibx-1)=0)
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif (map5(ibx)=102) and (map5(ibx+1)=0)
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
else
ghostparam(5)
end if
end if
elseif ((map5(ibx)=101) and (map5(ibx-20)>0)) or ((map5(ibx)=86) and (map5(ibx+20)>0)) '<--- here
iax = rand(2)
if iax =1
if map5(ibx-1) =0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx+1) =0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif (map5(ibx)=101) and (map5(ibx+20)=0)
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif (map5(ibx)=86) and (map5(ibx-20)=0)
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
else
ghostparam(5)
end if
elseif iax =2
if map5(ibx+1) =0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif map5(ibx-1) =0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif (map5(ibx)=101) and (map5(ibx+20)=0)
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif (map5(ibx)=86) and (map5(ibx-20)=0)
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
else
ghostparam(5)
end if
end if
'----------
elseif (map5(ibx)=103) and (map3(ibx)=167)
iax = rand(3)
if iax =1
if map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
else
ghostparam(5)
end if
elseif iax =2
if map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
else
ghostparam(5)
end if
elseif iax =3
if map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
else
ghostparam(5)
end if
end if
'-------
elseif (map5(ibx)=102) and (map3(ibx)=167)
iax = rand(3)
if iax =1
if map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
else
ghostparam(5)
end if
elseif iax =2
if map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
else
ghostparam(5)
end if
elseif iax =3
if map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
else
ghostparam(5)
end if
end if
'-------
elseif (map5(ibx)=101) and (map3(ibx)=167)
iax = rand(3)
if iax =1
if map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
else
ghostparam(5)
end if
elseif iax =2
if map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
else
ghostparam(5)
end if
elseif iax =3
if map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif map5(ibx-20)=0
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
else
ghostparam(5)
end if
end if
'-------
elseif (map5(ibx)=86) and (map3(ibx)=167)
iax = rand(3)
if iax =1
if map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
else
ghostparam(5)
end if
elseif iax =2
if map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
else
ghostparam(5)
end if
elseif iax =3
if map5(ibx+1)=0
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif map5(ibx+20)=0
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
elseif map5(ibx-1)=0
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
else
ghostparam(5)
end if
end if
'----------
elseif (map5(ibx)=103) and (map5(ibx+1)=0)
map5(ibx) =0 : map5(ibx+1) =10
ghostparam(1)
elseif (map5(ibx)=102) and (map5(ibx-1)=0)
map5(ibx) =0 : map5(ibx-1) =10
ghostparam(2)
elseif (map5(ibx)=101) and (map5(ibx-20)=0)
map5(ibx) =0 : map5(ibx-20) =10
ghostparam(3)
elseif (map5(ibx)=86) and (map5(ibx+20)=0)
map5(ibx) =0 : map5(ibx+20) =10
ghostparam(4)
end if
next
next
end function
'---------------------------------------------------------------------
function ghostparam(rd as long)
xgos(ibx) = idx *32
ygos(ibx) = icx *32
rgos(ibx) = rd
end function
print "ok"