I'm trying to figure out a problem. This picture should sum it up nicely

Can't pastebin the code because for some reason my browser hangs when I use pastebin. But here is the most important code. Hope someone can help
Language: Lua
local NPCPreviewTable = {}
local AddressTableNPC = {
["FPC"] = {[1]=	{0,"FPC",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		   [4] = {1,"Z",0xFFFFD080,"EWRAM",0x18,4,true,nil,nil,nil},
		   [5] = {1,"Altitude",0xFFFFD080,"EWRAM",0x1C,4,true,nil,nil,nil},
		  },
["FCHR"] = {[1]= {0,"FCHR",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FBRD"] = {[1]= {0,"FBRD",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FMON"] = {[1]= {0,"FMON",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FMCH"] = {[1]= {0,"FMCH",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FBRL"] = {[1]= {0,"FBRL",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FRCK"] = {[1]= {0,"FRCK",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FSPL"] = {[1]= {0,"FSPL",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FBLK"] = {[1]= {0,"FBLK",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["FPSB"] = {[1]= {0,"FPSB",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
["SBLK"] = {[1]= {0,"SBLK",0xFFB0B0B0},
		   [2] = {1,"X",0xFFFFD080,"EWRAM",0x10,4,true,nil,nil,nil},
		   [3] = {1,"Y",0xFFFFD080,"EWRAM",0x14,4,true,nil,nil,nil},
		  },
}
local updateNPCPreviewTable = function()
	NPCPreviewTable={}
	AddressTableDisplayOffset["NPCPreview"]=0
	memory.usememorydomain("IWRAM")
	basepointer=0x0D7C 		-- this might be version specific
	basepointer=memory.read_u16_le(basepointer) + 0x28
	startingaddress=memory.read_u16_le(basepointer) - 0x04
	memory.usememorydomain("EWRAM")
	--going through the 32 slots
	for z=1,32,1 do
		if memory.read_u32_le(startingaddress) == 0x00435046 then 
			npctype="FPC" -- Field Player Character (e.g. Mario, Luigi)
			nextslot=0x39C
		elseif memory.read_u32_le(startingaddress) == 0x52484346 then
			npctype="FCHR" -- Field Character (e.g. NPC)
			nextslot=0x34C
		elseif memory.read_u32_le(startingaddress) == 0x44524246 then
			npctype="FBRD" -- Field Board (e.g. pedal)
			nextslot=0x34C
		elseif memory.read_u32_le(startingaddress) == 0x4E4F4D46 then
			npctype="FMON" -- Field Monster
			nextslot=0x358
		elseif memory.read_u32_le(startingaddress) == 0x48434D46 then
			npctype="FMCH" -- ?
			nextslot=0x358
		elseif memory.read_u32_le(startingaddress) == 0x4C524246 then
			npctype="FBRL" -- Field Barrel
			nextslot=0x34C			
		elseif memory.read_u32_le(startingaddress) == 0x4B435246 then
			npctype="FRCK" -- Field Rock
			nextslot=0x34C
		elseif memory.read_u32_le(startingaddress) == 0x4C505346 then
			npctype="FSPL" -- Field Special
			nextslot=0x34C
		elseif memory.read_u32_le(startingaddress) == 0x4B4C4246 then
			npctype="FBLK" -- Field Block (e.g. saveblocks, special blocks)
			nextslot=0x360
		elseif memory.read_u32_le(startingaddress) == 0x42535046 then
			npctype="FPSB" -- ?
			nextslot=0x5C
		elseif memory.read_u32_le(startingaddress) == 0x4B4C4253 then
			npctype="SBLK" -- Block
			nextslot=0x360
		else
			break
		end
		NPCPreviewTable[z]=AddressTableNPC[npctype]
		print("z: " .. z .. " " .. NPCPreviewTable[1][2][5])
		for r=2,table.getn(NPCPreviewTable[z]),1 do
		print("z: " .. z .. " r: " .. r .. " " .. NPCPreviewTable[1][2][5])
			NPCPreviewTable[z][r][5]=NPCPreviewTable[z][r][5]+startingaddress
		print("z: " .. z .. " r: " .. r .. " " .. NPCPreviewTable[1][2][5])
		end
			
		if nextslot~=nil then
			startingaddress=startingaddress+nextslot
		end
	end	
end