Scrolling map works up and down but not left and right! ???

Blitz3D Forums/Blitz3D Beginners Area/Scrolling map works up and down but not left and right! ???

Hi folks,
I am working on some code that loads in a level of map tiles and scrolls one block at a time using the arrow keys. Thing is... i cant get left and right to scroll correctly, all the tiles are jumbled up - rather than scrolling they appear random.

Any help would be appreciated.
heres the code:


global tileset
global locationx
global locationy
locationx=100 : locationy=100
dim tile_position_array(500,500)

;### Load in Level
myfile = ReadFile("D:\Projects\Learning\Level1.dat")
For i = 0 to 500
For j = 0 to 500
Tile_Position_Array(i,j) = ReadByte (myfile)
Next
Next
Closefile myfile

graphics 1024,768,32,1
setbuffer backbuffer()
tileset=LoadanimImage("d:\projects\game graphics\tileset2.bmp",64,64,0,50)

while not keyhit(1)
a=0
b=0
for x=0 to 1024 step 64
for y=0 to 768 step 64
bob = Tile_Position_Array(locationx +a,locationy +b)
drawimage tileset,x,y,bob
a=a+1
next
b=b+1
next
flip
if locationx<500 and keyhit(208) then locationx=locationx+1
if locationx>0 and keyhit(200) then locationx=locationx-1
if locationy<500 and keyhit(205) then locationy=locationy+1
if locationy>0 and keyhit(203) then locationy=locationy-1

wend