Just a quick update. The PRNG Button press function itself has been genericized and now takes player as an int argument. It shouldn't be passed anything else as an argument simply because it passes player to joypad.get() and joypad.set().
Unfortunately, I haven't put in the return nil case kludge yet, this was just a patch job to get the refactoring started. In other words, it will fail for any core in which joypad.get(1) returns nil. In other other words, it will fail if the core only expects one controller (such as GBx)
Language: lua
checkTime = 0
keyNames = {[1] = {},[2] = {}}
keysArray = {[1] = {},[2] = {}}
blacklist = {"Power", "Reset"}
frequency = 10
mplay = false
function core()
checkTime = emu.framecount() % frequency
if (checkTime == 0) then
sendRandomButtonPress(1)
if mplay == true then
sendRandomButtonPress(2)
end
elseif (checkTime < frequency/2) then
joypad.set(keysArray[1],1)
if mplay == true then
joypad.set(keysArray[2],2)
end
end
end
function getButtonNames()
k = 1
j = 1
for key,v in pairs(joypad.get(1)) do
keyNames[1][k] = key
k = k+1
end
if joypad.get(2) ~= nil then
for key,v in pairs(joypad.get(2)) do
keyNames[2][j] = key
j = j+1
mplay = true
end
end
end
function sendRandomButtonPress(player)
keysArray[player] = joypad.get(player)
i = math.random(table.getn(keyNames[player]))
push = keyNames[player][i]
if checkBlacklist(push) == true then
keysArray[player][push] = "True"
else
sendRandomButtonPress(player)
end
joypad.set(keysArray[player],player)
end
function checkBlacklist(key)
result = true
for i, v in pairs(blacklist) do
if key == blacklist[i] then
result = false
end
end
return result
end
function initializeKeyArray()
keysArray[1] = joypad.get(1)
if mplay == true then
keysArray[2] = joypad.get(2)
end
end
getButtonNames()
initializeKeyArray()
while true do
core()
emu.frameadvance()
end
E: So, the upshot is now I'm going to be requesting a new joypad function: joypad.countPlayers(). Should just return the number of controllers the core will accept inputs for at that time - example, if in N64 mode you have it set up for three controllers, joypad.countPlayers() should return 3.