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! ???

Thanks to John (QuietBloke) I have created my first scrolling tilemap program!!!

Woohoo! The code is a bit rough and ready at the moment and it needs some checks putting in so that it cannot scroll out of the map area but appart from that I am well chuffed.
I am looking at using it for a Rebelstar Raiders game on the old speccy!

Anyway, heres the code:
______________________________________________________



;### Initialisation of Variables
global tileset
global locationx
global locationy
global locationxoffset
Global locationyoffset
dim tile_position_array(500,500)
locationxoffset=0
locationyoffset=0
locationx=100
locationy=100

;### Load in level data from a dat file created earlier
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

;### Initialise Screen and load in tileset created earlier
graphics 1024,768,32,1
setbuffer backbuffer()
tileset=LoadanimImage("d:\projects\game graphics\tileset2.bmp",64,64,0,50)

;### Main program loop
while not keyhit(1)

;### calculate screen offset for initial placement of tiles
if locationXOffset < 0 then
locationXOffset = locationXOffset + 64
locationX = locationX + 1
end if

if locationXOffset > 63 then
locationXOffset = locationXOffset - 64
locationX = locationX - 1
end if

if locationyOffset < 0 then
locationyOffset = locationyOffset + 64
locationy = locationy + 1
end if

if locationyOffset > 63 then
locationyOffset = locationyOffset - 64
locationy = locationy - 1
end if


;### Display tiles from calculated offset using origin command
origin locationxoffset,locationyoffset
a=0
for x=-64 to 1024 step 64
b=0
for y=-64 to 768 step 64
bob = Tile_Position_Array(locationx +a,locationy +b)
drawimage tileset,x,y,bob
b=b+1
next
a=a+1
next

;### Just in case... reset the origin to 0,0
origin 0,0

;### Bring created screen to the front
flip

;### Process Inputs and continue looping
if locationy<500 and keydown(208) then locationyoffset=locationyoffset+8
if locationy>0 and keydown(200) then locationyoffset=locationyoffset-8
if locationx<500 and keydown(205) then locationxoffset=locationxoffset+8
if locationx>0 and keydown(203) then locationxoffset=locationxoffset-8
wend