Post subject: Making Lua macros for VBA
filwac
He/Him
Joined: 12/12/2009
Posts: 29
Location: Forever floating in a secret world
In snes9x macro is done like (AB)(A).(B) meaning A and B on the first frame, A on the second frame, third frame is blank, B on the fourth frame, repeat. How would i do that on VBA using lua? I'm posting from my phone because my computer has no internet, so i can't download anything
Waiting takes too long
Player (138)
Joined: 9/18/2007
Posts: 389
this would start the macro when you press F11+frameadvance or numpad0 + frameadvance. (I haven't tested this code, but it should work)
function press(param)
    local temp={}
    for _,s in ipairs(param) do temp.s = true end
    joypad.set(1,temp)
    emu.frameadvance()
end

function macro(param)
    for _,t in ipairs(param) do press(t) end
end

while(true) do
    emu.frameadvance()
    keys=input.get()
    if keys["F11"] then
        press{"A","B"}
        press{"A"}
        press{}
        press{"B"}
    end
    
    if keys["numpad0"] then macro{{"A","B"},{"A"},{},{"B"}} end
end
filwac
He/Him
Joined: 12/12/2009
Posts: 29
Location: Forever floating in a secret world
It's not working. Perhaps I'm missing/forgetting something? i typed it in as is, made sure () {} and [] weren't mixed up. Am i supposed to replace anything?
Waiting takes too long
Player (138)
Joined: 9/18/2007
Posts: 389
the joypad.set instruction does absolutely nothing, i don't know why. Might be a bug in vba-rr
filwac
He/Him
Joined: 12/12/2009
Posts: 29
Location: Forever floating in a secret world
So does that mean i won't be able to use macros in VBA? I'm using VBA-RR v23.5 svn374 if it makes a difference
Waiting takes too long
Editor, Skilled player (1203)
Joined: 9/27/2008
Posts: 1085
In a while true do ... emu.frameadvance() end loop, v23.5 will react to joypad.set() here, however it will do so one frame late.
Language: lua

while true do joypad.set(1,{A=true}) --Usually not directly inserted like this emu.frameadvance() end
In emu.registerbefore(), emu.registerafter(), and gui.register(), joypad.set has no effect in v23.5.
Language: lua

local function HoldA() joypad.set(1,{A=true}) end emu.registerbefore(HoldA) --The joypad.set fails in a register!
An earlier version of VBA (v22) did work using joypad.set in a register. For whatever reason, emu.registerafter() has joypad.set() work immediately instead of one frame late. But this is only in v22, as v23.5 won't even respond to joypad.set() placed here. I can probably construct a simple script for macros in a bit...
filwac
He/Him
Joined: 12/12/2009
Posts: 29
Location: Forever floating in a secret world
That would be amazing thank you! I can't handle the repetition of doing it manually over and over and over
Waiting takes too long
Editor, Skilled player (1203)
Joined: 9/27/2008
Posts: 1085
For a quick solution, I'm making corrections to partyboy1a's script... Download Corrected_pb1a_Scipt.lua
Language: lua

function press(param) local temp={} for _,s in ipairs(param) do temp[s] = true end joypad.set(1,temp) emu.frameadvance() end function macro(param) for _,t in ipairs(param) do press(t) end end while(true) do keys=input.get() if keys["F11"] then press{"A","B"} press{"A"} press{} press{"B"} elseif keys["numpad0"] then macro{{"A","B"},{"A"},{},{"B"}} else emu.frameadvance() end end
I will leave it as an exercise as to what the corrections are and why I corrected them as such. I have made two basic corrections, by the way. Keep in mind -- The macro will start one frame late.
filwac
He/Him
Joined: 12/12/2009
Posts: 29
Location: Forever floating in a secret world
That works. Thanks, this'll make things so much easier. EDIT: Any chance i could make it toggle?
Waiting takes too long