I'm writing a lua script that sends joypad input during parts of the game and returns control back to me during other parts of the game. I can't figure out how to do this though based on the joypad documentation. Here is an example script:
function testing(allow)
local keytable = joypad.get()
if allow then
for key, _ in pairs(keytable) do
keytable[key] = nil
end
else
keytable["P1 Left"] = "False"
keytable["P1 Right"] = "True"
end
joypad.set(keytable)
end
framecount = 0
while true do
if framecount > 100 then
testing(true)
else
testing(false)
framecount = framecount + 1
end
emu.frameadvance()
end
What I expect this script to do: Hold right on the joypad for 100 frames, then allow manual control on every frame after that.
What it actually does: Holds right for 100 frames, then only allows manually moving right on every frame after that. Also, even if I stop the script, I still don't have full control back, I have to restart BizHawk completely.
What am I doing wrong here?