scantics, LUA indexes tables normally 1 based (Starts on index 1), if you want to use it as 0 bases then you have to explicit declare it (as you did, but didn't understood why). Unless there's an specific need to have them start at 0, I would avoid it all together.
I was able to run your script and it didn't thrown any error. However the coordinates for the enemies were off...
Anyway, when I was testing the position addresses I made a LUA script. Though it was for Snes9x, I adapted it now for Bizhawk and here it is. It has the same style as the one I have for Final Fantasy V, where I save first the addresses in a table and then call them, sure you could reduce some code but I think this is very legible:
Language: LUA
wwm = 0
wwM = 255
whm = 0
whM = 224
function drawAxis(x, y, color)
gui.drawLine ( x, whm, x, whM, color)
gui.drawLine (wwm, y, wwM, y, color)
end
function drawCollision(x, y, color)
gui.drawBox (x-6, y-6, x+6, y+6, color)
end
function EnemyInfo(Enemy)
local enemy = Enemy - 1
local enemyTable = {}
enemyTable = {
sprite = memory.readbyte(0x000D61 + enemy*(0x50)),
x = memory.readbyte(0x000D68 + enemy*(0x50)),
y = memory.readbyte(0x000D6C + enemy*(0x50)),
hp = memory.readbyte(0x000D76 + enemy*(0x50)),
}
return enemyTable
end
local function enemy_data()
local enemy = {}
local x,y = 0,0
local hp = 0
local sprite = 0
local EnemiesMax = 64
for i=1, EnemiesMax do
enemy[i] = EnemyInfo(i)
x = enemy[i].x
y = enemy[i].y
hp = enemy[i].hp
sprite = enemy[i].sprite
if (hp ~= 0) and (sprite ~= 0) then
drawCollision( x, y, 0xFFFF4000)
end
end
end
function AllyInfo(Enemy)
local enemy = Enemy - 1
local enemyTable = {}
enemyTable = {
x = memory.readbyte(0x000BD8 + enemy*(0x50)),
y = memory.readbyte(0x000BDC + enemy*(0x50)),
hp = memory.readbyte(0x000BE6 + enemy*(0x50)),
}
return enemyTable
end
local function character_data()
local ally = {}
local x,y = 0,0
local hp = 0
local AllyMax = 5
for i=1, AllyMax do
ally[i] = AllyInfo(i)
x = ally[i].x
y = ally[i].y
hp = ally[i].hp
drawAxis( x, y, 0xFF0040FF)
drawCollision( x, y, 0xFF0080FF)
end
end
function dumping()
io.output("Parodius.txt")
address = 0x000B80
size = 80
iter = 64
for i=0, size do
row = ""
for j=0, iter do
x = memory.readbyte( address + i + (j*size) )
row = row .. string.format( "%2X ", x )
end
io.write( row .. "\n" )
end
io.close()
print ("dumped file")
end
function main()
character_data()
enemy_data()
end
while true do
main()
emu.frameadvance()
end