forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

waiting for button input

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Thu Apr 12, 2007 8:43 pm    Post subject: waiting for button input Reply with quote

Ever since I know lua I have been using this code to wait till a button is pressed, only to find out that it doesn't work!

Code:

pad = nil
while pad == nil do
  System.sleep(100)
  pad = Controls.read()
end


If I add a print("hello") to my code after end my screen is filled with 10 hello's per second(I guess) although I don't press any buttons. This is pretty embarassing, so can anyone tell me how to do this?
_________________
Behold! The Underminer got hold of a PSP
Back to top
View user's profile Send private message
matriculated



Joined: 04 Mar 2006
Posts: 31

PostPosted: Fri Apr 13, 2007 2:23 am    Post subject: Reply with quote

pad will never = nil if you do a controls.read

do something like this:

Code:
repeat
  System.sleep(100)
  pad = Controls.read()
until pad:buttons()


This loops until a button (or dpad) is pressed
Back to top
View user's profile Send private message
the underminer



Joined: 03 Oct 2005
Posts: 124
Location: Netherlands

PostPosted: Sat Apr 14, 2007 6:22 pm    Post subject: Reply with quote

that doesn't work either
_________________
Behold! The Underminer got hold of a PSP
Back to top
View user's profile Send private message
matriculated



Joined: 04 Mar 2006
Posts: 31

PostPosted: Sun Apr 15, 2007 6:26 am    Post subject: Reply with quote

It does work because I use a slightly modified code in all my programs to pause for input.

Code:
function pause()
  local pad
  repeat
    pad = Controls.read()
    screen.waitVblankStart(5)
  until pad:start()
end
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Mon Apr 16, 2007 3:07 am    Post subject: Reply with quote

Code:
-- Coded by romero126
GlassEyeInput = {
   ["KeyList"] = { }
}

table.insert(GlassEyeInput["KeyList"], {Controls.selectMask, "Select", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.startMask, "Start", nil})

table.insert(GlassEyeInput["KeyList"], {Controls.upMask, "Up", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.rightMask, "Right", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.downMask, "Down", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.leftMask, "Left", nil})

table.insert(GlassEyeInput["KeyList"], {Controls.ltriggerMask, "LTrigger", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.rtriggerMask, "RTrigger", nil})

table.insert(GlassEyeInput["KeyList"], {Controls.triangleMask, "Triangle", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.circleMask, "Circle", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.crossMask, "Cross", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.squareMask, "Square", nil})

table.insert(GlassEyeInput["KeyList"], {Controls.homeMask, "Home", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.holdMask, "Hold", nil})
table.insert(GlassEyeInput["KeyList"], {Controls.noteMask, "Note", nil})

function GlassEyeInput:CheckInput(key)
   result = nil
   for k, v in GlassEyeInput["KeyList"] do
      if (key:buttons() & v[1] > 0) then
         if (not v[3]) then
            v[3] = 1
            if (not result) then result = { } end
            result[v[2]] = 1
         end
      else
         if (v[3]) then
            if (not result) then result = { } end
            result[v[2]] = 0
            v[3] = nil
         end
      end
   end
   return result
end


Code:
-- Coded by romero126
if (GlassEyeInput) then
   local check = GlassEyeInput:CheckInput(key)
   if (check) then
      for k,v in check do
         if (k == "Start") and (v == 0) then
            print("You lifted your finger on the start key")
         end
         if (k == "Start") and (v == 1) then
            print("You pressed your finger on the start key")
         end
      end
   end
end


Enjoy!
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Mon Apr 16, 2007 9:35 am    Post subject: Reply with quote

cheap input is also done by
key = Controls.read()
while true do

if (key != Controls.read())
key = Controls.read()
-- do stuff here
end

end
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group