Taking that information, I was able to clean up the Zelda II script quite quickly.
When I try to apply the same idea to the SMB2 script, it breaks citing unable to find cherry.png - which is in the same folder that I'm running the script out of.
(Code block below actually does work, it's when I convert from this to on frame end that it breaks)
Download smb2hudv2.luaLanguage: lua
-- "Super Mario Bros. 2"
local cherryCount
local foeLifeA
local foeLifeB
local foeLifeC
local foeLifeD
local foeLifeE
local squatTimer
local carpetTimer
local starTimer
local dreamTimer
local bigVegCount
local stopTimer
local starPercent
local carpetPercent
local dreamPercent
local stopPercent
TIMER = 100;
while (true) do
cherryCount = memory.readbyte(0x062A);
bigVegCount = memory.readbyte(0x062C);
squatTimer = memory.readbyte(0x04CA);
carpetTimer = memory.readbyte(0x00B9);
dreamTimer = memory.readbyte(0x04B7);
starTimer = memory.readbyte(0x04E0);
stopTimer = memory.readbyte(0x04FF);
carpetPercent = carpetTimer / 160;
dreamPercent = dreamTimer / 96;
starPercent = starTimer / 62;
stopPercent = stopTimer / 255;
foeLifeA = memory.read_s8(0x0465);
foeLifeB = memory.read_s8(0x0466);
foeLifeC = memory.read_s8(0x0467);
foeLifeD = memory.read_s8(0x0468);
foeLifeE = memory.read_s8(0x0469);
gui.drawRectangle(100,8,squatTimer,4,"Cyan","Cyan");
gui.drawRectangle(100,8,60,4,"RED");
gui.drawRectangle(100,15,TIMER*carpetPercent,5,"Red","Red");
gui.drawRectangle(100,15,TIMER*dreamPercent,5,"CYAN","CYAN");
gui.drawRectangle(100,15,TIMER*starPercent,5,"MAGENTA","MAGENTA");
gui.drawRectangle(100,15,TIMER*stopPercent,5,"Yellow","Yellow");
gui.drawRectangle(100,15,TIMER,5,"White");
for i = 0, cherryCount, 1 do
gui.drawImage("cherry.png",(i*8)-8,16);
end
for j = 0, bigVegCount, 1 do
gui.drawImage("veg.png",(j*8)-8,8);
end
for k = 0, foeLifeA, 1 do
gui.drawImage("heart.png",(k*8)-8,144);
end
for l = 0, foeLifeB, 1 do
gui.drawImage("heart.png",(l*8)-8,160);
end
for m = 0, foeLifeC, 1 do
gui.drawImage("heart.png",(m*8)-8,176);
end
for n = 0, foeLifeD, 1 do
gui.drawImage("heart.png",(n*8)-8,184);
end
for o = 0, foeLifeE, 1 do
gui.drawImage("heart.png",(o*8)-8,192);
end
emu.frameadvance();
end
Lua HUD Package for SMB2, v2