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
-- -------------------------------------- --
-- Parodius; Non-Sense Fantasy LUA script --
-- by: samurai goroh --
-- mail: samuraigoroh@gmail.com --
-- -------------------------------------- --
-- ------- --
-- GLOBALS --
-- ------- --
wwm = 0 -- windows width min
wwM = 255 -- windows width MAX
whm = 0 -- windows height min
whM = 224 -- windows height MAX
--------------------------------------------------------------------------------
function drawAxis(x, y, color) -- Draws an Axis around ships
--------------------------------------------------------------------------------
gui.drawLine ( x, whm, x, whM, color)
gui.drawLine (wwm, y, wwM, y, color)
end
--------------------------------------------------------------------------------
function drawCollision(x, y, color) -- Draws a box around ships
--------------------------------------------------------------------------------
gui.drawBox (x-6, y-6, x+6, y+6, color)
end
--------------------------------------------------------------------------------
function EnemyInfo(Enemy) -- ENEMY addresses goes here
--------------------------------------------------------------------------------
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() -- ENEMY code goes here
--------------------------------------------------------------------------------
local enemy = {} -- Holds the enemy's information
local x,y = 0,0 -- Coord X,Y
local hp = 0 -- HP?!
local sprite = 0 -- Sprite?!
local EnemiesMax = 64 -- Max number of enemies in screen (not sure what's the limit but 64 sounds about right...)
for i=1, EnemiesMax do
enemy[i] = EnemyInfo(i) -- Populate the enemy's information
x = enemy[i].x
y = enemy[i].y
hp = enemy[i].hp
sprite = enemy[i].sprite
if (hp ~= 0) and (sprite ~= 0) then
--drawAxis(x, y, 0xFFFF4000)
drawCollision( x, y, 0xFFFF4000)
end
end
end
--------------------------------------------------------------------------------
function AllyInfo(Enemy) -- ALLY addresses goes here
--------------------------------------------------------------------------------
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() -- ALLY code goes here
--------------------------------------------------------------------------------
local ally = {} -- Holds the character's information
local x,y = 0,0 -- Coord X,Y
local hp = 0 -- HP?!
local AllyMax = 5 -- Max number of allies in screen (Ship + 4 Options)
for i=1, AllyMax do
ally[i] = AllyInfo(i) -- Populate the ally's information
x = ally[i].x
y = ally[i].y
hp = ally[i].hp
--if x > 0 then
drawAxis( x, y, 0xFF0040FF)
drawCollision( x, y, 0xFF0080FF)
--end
end
end
--------------------------------------------------------------------------------
function dumping() -- Dumps some addresses, to analyze manually. Easy to paste on Excel
--------------------------------------------------------------------------------
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 ) -- Uses a tab to split text
end
io.write( row .. "\n" )
end
io.close()
print ("dumped file")
end
--------------------------------------------------------------------------------
function main() -- Contains code that will be continiously running
--------------------------------------------------------------------------------
character_data()
enemy_data()
end
--------------------------------------------------------------------------------
--****************************************************************************--
--dumping()
while true do
main()
emu.frameadvance()
end
--****************************************************************************--