Maybe I'm just having a brain fart or some such, and as best I can figure this bit of code should work.

Background:

This code takes world chunks arranged in a 10x10 grid (0-9). Each chunk is a 96x96 tiled map. The display area of the map is 13x13 This code should read parts from other world chunks if the player is on the edge of a particular world chunk. However, when the player walks into another world chunk it seems to forget to read the chunk they just came from. Any help would be appreciated.

FOR Y = -6 TO 6
FOR X = -6 TO 6
rem The target square is always in the middle.
rem We must establish if the surrounding squares are in the same chunk, and if
rem not, we have to read the proper chunk.
rem if its no longer on the map, make it dark water
rem 13x13 display
iOceanFlag = 0
iModX = iPosX + X
iModY = iPosY + Y
iModChunkY = iCurChunkY
iModChunkX = iCurChunkX
rem BEGIN CHECK FOR OFFSETS
rem Chunk North
IF iPosY + Y < 1
iModChunkY = iCurChunkY - 1
iModY = 96 + Y
ENDIF
rem Chunk South
IF iPosY + Y > 96
iModChunkY = iCurChunkY + 1
iModY = 0 + Y
ENDIF
rem Chunk West
IF iPosX + X < 1
iModChunkX = iCurChunkX - 1
iModX = 96 + X
ENDIF
rem Chunk East
IF iPosX + X > 96
iModChunkX = iCurChunkX + 1
iModX = 0 + X
ENDIF
rem Make Sure Chunks are legal
IF iModChunkY < 0 OR iModChunkY > 9 OR iModChunkX < 0 OR iModChunk > 96
iOceanFlag = 1
ENDIF
IF iOceanFlag = 1
uTile(X+7,Y+7).iBase = 0
ENDIF
IF iOceanFlag = 0
REM Set Bases
iBiome = iWorldBiome(iModChunkX,iModChunkY,iModX,iModY)
iHeight = iWorldHeight(iModChunkX,iModChunkY,iModX,iModY)
iVar = iVariation(iModChunkX,iModChunkY,iModX,iModY)
rem iRiver = Blah blah
rem iRoad = Blah Blah
IF iBiome = 0 THEN uTile(X+7,Y+7).iBase = 1 : REM Water
IF iBiome = 1 THEN uTile(X+7,Y+7).iBase = 3 : REM Snow
IF iBiome = 2 THEN uTile(X+7,Y+7).iBase = 1 : REM Thick Ice
IF iBiome = 3 THEN uTile(X+7,Y+7).iBase = 3 : REM Rocks and Snow
IF iBiome = 4 THEN uTile(X+7,Y+7).iBase = 2 : REM Cracking Ice
IF iBiome = 5 THEN uTile(X+7,Y+7).iBase = 2 : REM Breaking Ice
IF iBiome = 6 THEN uTile(X+7,Y+7).iBase = 1 : REM Ice Bergs
IF iBiome = 7 THEN uTile(X+7,Y+7).iBase = 4 : REM Rocky/Stoneland
IF iBiome = 8 THEN uTile(X+7,Y+7).iBase = 6 : REM Steppe
IF iBiome = 9 THEN uTile(X+7,Y+7).iBase = 7 : REM Evergreen Woods
IF iBiome = 10 THEN uTile(X+7,Y+7).iBase = 7 : REM Temperate Woods
IF iBiome = 11 THEN uTile(X+7,Y+7).iBase = 5 : REM Prairie
IF iBiome = 12 THEN uTile(X+7,Y+7).iBase = 5 : REM Temperate Shrublands
IF iBiome = 13 THEN uTile(X+7,Y+7).iBase = 7 : REM Lush Woodland
IF iBiome = 14 THEN uTile(X+7,Y+7).iBase = 7 : REM Thick Woodland
IF iBiome = 15 THEN uTile(X+7,Y+7).iBase = 5 : REM Tropical Shrubland
IF iBiome = 16 THEN uTile(X+7,Y+7).iBase = 8 : REM Desert
IF iBiome = 17 THEN uTile(X+7,Y+7).iBase = 7 : REM Jungle
IF iBiome = 18 THEN uTile(X+7,Y+7).iBase = 4 : REM Volcano
IF iBiome = 19 THEN uTile(X+7,Y+7).iBase = 6 : REM Swamp
IF iBiome = 20 THEN uTile(X+7,Y+7).iBase = 1 : REM Marshland
IF iBiome = 21 THEN uTile(X+7,Y+7).iBase = 1 : REM Corrupted Land
IF iBiome = 22 THEN uTile(X+7,Y+7).iBase = 1 : REM Blast Land
REM Stack 1 is for Altitude
uTile(X+7,Y+7).iStack1 =0
remstart
IF iHeight >= 6 AND iHeight <= 9 THEN uTile(X+7,Y+7).iStack1 = 11 : REM Low Hills
IF iHeight >= 10 AND iHeight <= 12 THEN uTile(X+7,Y+7).iStack1 = 12 : REM Tall Hills
IF iHeight > 12 THEN uTile(X+7,Y+7).iStack1 = 18 : REM Mountains (Will need multiple versions)
REM Stack 2 is for Rivers
REM Stack 3 is for Vegitation
remend
uTile(X+7,Y+7).iStack2 = 0
uTile(X+7,Y+7).iStack3 = 0
REM IF iBiome = 7 THEN uTile(X+7,Y+7).iStack3 = 17 :REM Rocks on Stony Lands
IF iBiome = 9 THEN uTile(X+7,Y+7).iStack3 = 16 + iVar :REM Evergreen Woods
IF iBiome = 10 THEN uTile(X+7,Y+7).iStack3 = 21 + iVar :REM Temperate Woods
IF iBiome = 11 THEN uTile(X+7,Y+7).iStack3 = 46 + iVar :REM Prairie
IF iBiome = 12 THEN uTile(X+7,Y+7).iStack3 = 11 + iVar :REM Temp. Shrubland
IF iBiome = 13 THEN uTile(X+7,Y+7).iStack3 = 26 + iVar :REM Lush Woodlands
IF iBiome = 14 THEN uTile(X+7,Y+7).iStack3 = 26 + iVar :REM Thick Woodlands
IF iBiome = 15 THEN uTile(X+7,Y+7).iStack3 = 31 + iVar :REM Topical Shrub
IF iBiome = 16 THEN uTile(X+7,Y+7).iStack3 = 41 + iVar :REM Desert
IF iBiome = 17 THEN uTile(X+7,Y+7).iStack3 = 36 + iVar :REM Jungle
ENDIF
NEXT X
NEXT Y

-Grim