Access_Denied's Forums

Site Resources => Tutorials => Topic started by: Access_Denied on June 14, 2007, 03:07:51 AM



Title: Tutorial Four: Button Input
Post by: Access_Denied on June 14, 2007, 03:07:51 AM
In this lesson, we are going to be focusing on button input. Yes, that's right, we'll finally be able to have the player do something instead of just watch a screen that says "Hello World". So let's get to it. First off, our notes:

--Button Input
--June 14, 2007

Now for our color variable:

white = Color.new(255,255,255)

Now to our main loop:

while true do
screen:clear()

Now we're going to throw in something new:

pad = Controls.read()

What this line does is it identifies the buttons on your PSP as the variable "pad". You don't have to
understand this now, we'll get to it later. One thing you do understand is that it doesn't have to be
"pad". You could make it "turkey" or "shoe". Any word will do. Now we're going to make it so when
we press a button, something displays on the screen.

if pad:up() then
screen:print(100,100,"You are pressing UP",white)
end

Now, you've seen this before. An if/then statement. But what you haven't seen is the pad variable.
By writing "if pad:up() then" you are saying "if you press up then". Simple right? The next line should
be familiar.  And the third line is the end of our "if" statement. Let's try it with another button:

if pad:circle() then
screen:print(100,100,"You are pressing CIRCLE",white)
end

Getting the hang of it? Now, I'm going to finish off the tutorial, but you can add other button input
statements. Here's the button list:

pad:cross()
pad:circle()
pad:triangle()
pad:square()
pad:r()
pad:l()
pad:up()
pad:down()
pad:left()
pad:right()
pad:start()
pad:select()
pad:home()

Experiment a little. You can even do this:

if pad:cross() and pad:down() then
blah blah
end

What this does it, it says, "if you are pressing up AND cross then"

Now to finish the script

screen.waitVblankStart()
screen.flip()
end

See you in the next tutorial!


Hosted by www.Geocities.ws

1