And here's my new, improved program:
local state1 = savestate.create()
local state2 = savestate.create()
local H,S,D,A,M,X,Y= "hp","st","df","ag","mn","AB","!!"
local _ = "__"
local Growth={[0]=H,
_,_,D,X,_,M,_,A,_,_,X,_,X,_,_,
_,_,X,M,A,_,_,M,_,_,_,_,M,X,_,M,
_,_,_,_,_,_,A,_,_,_,X,M,X,H,X,_,
_,_,_,X,_,_,H,X,A,_,_,S,A,M,S,S,
H,_,X,_,A,_,_,_,X,_,_,_,_,A,_,M,
X,_,D,H,X,S,_,H,M,_,H,H,_,Y,H,_,
S,_,_,_,M,M,X,_,_,_,S,_,S,_,M,X,
_,S,H,A,_,H,_,S,_,S,_,X,X,_,_,_,
_,A,A,A,_,X,_,A,_,M,M,_,H,_,M,H,
A,M,_,_,D,X,X,_,H,H,M,H,_,_,H,_,
X,H,M,H,H,X,Y,H,H,X,_,_,_,_,_,A,
M,X,M,_,H,H,_,_,D,X,A,S,_,_,S,S,
_,X,_,X,_,M,H,X,_,H,H,M,H,D,X,_,
_,H,S,_,_,S,A,_,_,M,_,_,H,A,_,H,
S,M,H,M,_,_,_,M,M,A,D,X,S,M,_,_,
_,S,_,Y,M,_,M,D,X,D,X,_,_,H,X,X
}
local FrameTable={}
local FTI = 1
for i = 1, 16 do
FrameTable[i] = 0
end
savestate.save(state1)
for i = 1, 50 do
emu.frameadvance()
savestate.save(state2)
frame = emu.framecount()
for k = 1, 8 do
joypad.set(1, {A = 1, B = 1, select = 1, start = 1})
emu.frameadvance()
end
local rng = memory.readbyte(0xC30B)
if Growth[rng] == "ag" then
FrameTable[FTI]=frame
FTI = FTI+1
end
savestate.load(state2)
end
savestate.load(state1)
for i = 1, 16 do
gui.text(100, 9*i - 8 ,FrameTable[i])
end
emu.pause()
You'll see I picked up a few pointers from your script. As far as I can tell, it works like a charm. Just wait until the specified frame to restart and the next battle should give you an Agility bonus.
Edit:
Are you familiar with GlovePIE? Do you have a Wii Classic Controller? I found that using a Classic Controller helped a lot when making my Skitchin' run. VBA doesn't accept joystick buttons for menu commands, so I had to work around it in GlovePIE. I've come up with the following program:
ppjoy1.Digital0=wiimote.Classic.a
ppjoy1.Digital1=wiimote.Classic.b
keyboard.Escape=wiimote.Classic.x
ppjoy1.Digital4=wiimote.Classic.Minus
ppjoy1.Digital5=wiimote.Classic.Plus
ppjoy1.Digital7=wiimote.Classic.LFull
keyboard.Backslash=wiimote.Classic.RFull
ppjoy1.Digital8=wiimote.Classic.ZL
ppjoy1.Digital9=wiimote.Classic.ZR
ppjoy1.Digital0=wiimote.Classic.Home
ppjoy1.Digital1=wiimote.Classic.Home
ppjoy1.Digital4=wiimote.Classic.Home
ppjoy1.Digital5=wiimote.Classic.Home
ppjoy1.Digital16=wiimote.Classic.Up
ppjoy1.Digital17=wiimote.Classic.Down
ppjoy1.Digital18=wiimote.Classic.Left
ppjoy1.Digital19=wiimote.Classic.Right
if Classic.LFull
mouse.x = 0.69
mouse.y = 0.29
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
mouse.x = .55
mouse.y = .29
wait 10 ms
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
mouse.x = .65
mouse.y = .48
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
wait 200 ms
keyboard.G = true
wait 10 ms
keyboard.G = false
keyboard.R = true
wait 10 ms
keyboard.R = false
keyboard.O = true
wait 10 ms
keyboard.O = false
keyboard.W = true
wait 10 ms
keyboard.W = false
keyboard.T = true
wait 10 ms
keyboard.T = false
keyboard.H = true
wait 10 ms
keyboard.H = false
keyboard.Enter = true
wait 10 ms
keyboard.Enter = false
mouse.x = 0.74
mouse.y = 0.29
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
mouse.x = 0.35
mouse.y = 0.2
wait 100 ms
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
endif
if Classic.y
mouse.x = 0.69
mouse.y = 0.29
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
mouse.x = .55
mouse.y = .29
wait 10 ms
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
mouse.x = .65
mouse.y = .48
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
wait 200 ms
keyboard.R = true
wait 10 ms
keyboard.R = false
keyboard.E = true
wait 10 ms
keyboard.E = false
keyboard.S = true
wait 10 ms
keyboard.S = false
keyboard.T = true
wait 10 ms
keyboard.T = false
keyboard.A = true
wait 10 ms
keyboard.A = false
keyboard.R = true
wait 10 ms
keyboard.R = false
keyboard.T = true
wait 10 ms
keyboard.T = false
keyboard.NUMPAD2 = true
wait 10 ms
keyboard.NUMPAD2 = false
keyboard.Enter = true
wait 10 ms
keyboard.Enter = false
mouse.x = 0.74
mouse.y = 0.29
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
mouse.x = 0.35
mouse.y = 0.2
wait 100 ms
mouse.LeftButton = true
wait 10 ms
mouse.LeftButton = false
endif
debug = [mouse.x, mouse.y]
ppjoy1.Analog0=wiimote.Classic.Joy1X
ppjoy1.Analog1=wiimote.Classic.Joy1Y
ppjoy1.Analog2=wiimote.Classic.Joy2X
ppjoy1.Analog3=wiimote.Classic.Joy2Y
Okay, some explanations are warranted...
The Classic Controller's A and B buttons are mapped to the Game Boy's A and B buttons respectively through VBA. The minus and plus buttons are mapped to select and start, also through VBA. Of course, the d-pad is mapped to the Game Boy's d-pad, also through VBA.
The X button is mapped to the keyboard's escape key so that I can run the emulator at full speed. I don't think I'll be using that one much.
The right shoulder button is mapped to the backslash key, advancing emulation one frame.
The Home button is mapped to the same joystick buttons that cover A, B, select, and start, so pressing Home allows me to restart the game. Before I started toying with GlovePIE, I had to change control configurations just to restart.
The left shoulder button clicks "Stop" to stop any currently running Lua scripts, then clicks "Browse..." to open a new Lua script. It then types "growth" to load your Lua script (which I've titled "growth.lua"), presses enter to run it, and clicks on the main VBA window. Note that this entirely dependent on where I put the VBA window, so it probably won't work for your computer without tweaking it significantly.
The Y button is just like the left shoulder button, except it types "restart2" to run my script. If I set the emulation speed to 1000% in advance, my script executes in a few seconds.
This leaves the ZL and ZR buttons, as well as the two analog sticks. I don't know what to do with them just yet, but I was thinking of making a script that automatically saves and resets the game. I'm hoping there's a consistent frame rule and it always takes, say, 60 frames to save the game. We'll see.
So with all of these tools, I have most of what I need to start a demonstration run of the game. I'll probably be pretty lazy with my inputs, especially in battle. No reason at this point to get everything perfect to the exact frame.