Advertisement
gocha

BizHawk - return the number of controllers

Apr 21st, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.55 KB | None | 0 0
  1. -- For BizHawk <https://code.google.com/p/bizhawk/>
  2.  
  3. --- Return the number of controllers.
  4. -- @return Number of controllers. (nil if no controller number supported)
  5. local function joypad_getcount()
  6.   local keys = joypad.get()
  7.  
  8.   local count = 0
  9.   for key, value in pairs(keys) do
  10.     controller = key:match("^P(%d) ")
  11.     if controller then
  12.       controller = tonumber(controller)
  13.       if count < controller then
  14.         count = controller
  15.       end
  16.     end
  17.   end
  18.  
  19.   if count ~= 0 then
  20.     return count
  21.   else
  22.     return nil
  23.   end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement