Results 1 to 30 of 419
PSP Programming Tutorials in Lua - Lesson One, Hello World
This is a discussion on PSP Programming Tutorials in Lua - Lesson One, Hello World within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Now before you start, download 'Lua Player 0.9' thanks to Shine, from the PSPUpdates download sections here , or at ...
-
09-04-2005, 09:03 AM #1I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
PSP Programming Tutorials in Lua - Lesson One and Two
Now before you start, download 'Lua Player 0.9' thanks to Shine, from the PSPUpdates download sections here , or at the Official Lua Player website here.
You will need to take the two folders, 'luaplayer' and 'luaplayer%'.
Put them in PSP/GAME/ directory on your PSP.
And save your code as script.lua in the luaplayer folder.
Now to the tutorial!
This is defidently the easiest program to do. Only about 4 lines of code,
easy to understand, and no compiling, in Lua (Thanks to Shine for the Lua player).
So this program will just have 1 line of Text that says "Hello World", and this is how you do it.
So open up notepad, or any sort of text editing program, and start off with this line of code
What it does is define a colour. This time, it's defining it as blue. This is so you can type textCode:blue = Color.new(0, 0, 255)
on the PSP's screen in the colour (or color, I'm canadian) blue!
Let's examine the line of code.
Where it says blue = Color.new, it is saying "make blue as a new color". So now we have blue
as a new color that we can use.
(0, 0, 255) is the most important part of the code. This actually tells the PSP what color it will be.
When we typed blue = Color.new, we could have typed, 'red', 'yellow', 'green' or even 'Cublecursome'.
But we used blue, so it's easier to remember, and to make things simpiler.
So the three numbers, in this case (0, 0, 255), tells the PSP what the color displayed will be. These numbers
are part of the RGB color mode. The first number stands for red, the second for green, and the third is blue.
Here is a picture to explain it even better.

So since we want the text to be blue, the number on the right will go as high as it can go, 255.
If we wanted purple though, for example we would want to have both the blue and red numbers the highest, so the numbers
would be (255, 0, 255).
So now we have the first line of code, explained all nice and dandy.
Now we want to display some text right? So this is the next line of code we need.
The first part is almost self explanitory, but I'm going to explain it anyways.Code:screen:print(200, 130, "Hello World!", blue)
screen
rint is simply telling the PSP to print text to the screen. Simple as that.
Now where it says 200, 130, that is telling the PSP where to display the text.
The PSP has a resolution of 480 pixels width and 272 pixels height. So Now the text will be displayed on the 200 pixels
width, and 130 height.
Next!
"Hello World!" is going to be the text displayed on the actual screen. You can change this to whatever you want it to say. From 'Hello (your name here)'
to 'Aklin poopie pants'.
And blue, as we talked about before, is the color we defined before. And now that the PSP knows what "blue" is, we can use it, and tell the PSP
to display the text in blue. Hooray!
First two lines, done!
You might be wondering why we need this code, it doesnt seem like anything we need, but ah! We need it, or else our program won't workCode:screen.flip()
But first, I'm going to explain what it does.
When you print text, it is set to offscreen buffer, all drawing functions are. So, this means your text won't be visible until you type/call
screen.flip, which changes it to offscreen buffer to visible screen buffer.
There, now the code is "technically" done. The program will run, the text will be shown, but not for long. It will only display the text for a milisecond, and it will
disapear. So to change that, and make the text stay there, we need to type.
Now our code will be visible for longer than a milisecond.Code:while true do screen.waitVblankStart()
What it does is loop the code in an endless loop while it is true (which it is), so now the text will stay displayed for a longer period of time (forever to be precise).
Finally, we need to end our code. So just simply put
Now save it as script.lua in /psp/game/luaplayer, then turn on your PSP and test it!Code:end
It should look like this.

Here is what all the code should look liek when put together.
Also, just to show the simplicity of Lua compared to C++, here is the source of a 'Hello World' app for the PSP coded in C++.Code:blue = Color.new(0, 0, 255) screen:print(200, 130, "Hello World!", blue) screen.flip() while true do screen.waitVblankStart() end
But remember, Lua may be simple, but it can't do as much as C++, and isn't the best language, though it's perfect for PSP homebrew games.Code:#include <pspkernel.h> #include <pspdebug.h> PSP_MODULE_INFO("Hello World", 0, 1, 1); #define printf pspDebugScreenPrintf int exit_callback(int arg1, int arg2, void *common) { sceKernelExitGame(); return 0; } int CallbackThread(SceSize args, void *argp) { int cbid; cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL); sceKernelRegisterExitCallback(cbid); sceKernelSleepThreadCB(); return 0; } int SetupCallbacks(void) { int thid = 0; thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0); if(thid >= 0) { sceKernelStartThread(thid, 0, 0); } return thid; } int main() { pspDebugScreenInit(); SetupCallbacks(); printf("Hello World"); sceKernelSleepThread(); return 0; }
If you have any questions just post a comment and I'll try to help.
Second tutorial coming.
PS3Lounge.net
-whitehawk
-
09-04-2005, 09:04 AM #2I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
PSP Programming Tutorials in Lua - Lesson Two

Here it is, my second Lua tutorial.
This tutorial will cover:
-If statements
-Displaying backrounds
-Displaying pictures
-Button inputs
-Taking a screenshot
-Fancy loading screen
-Displaying text in complete custom colours (doesn't really have to do with coding)
-A few more small things.
This tutorial is just an application that will display a picture when you press a button, has a fancy loading screen, and a fancy intro.
If you haven't read my first tutorial, you should, for this is more complicated,
and read the first one will help you if your a beginner. You can read it here
Also, you will need some images for this tutorial. You can download them here or here (waiting for PSPU to upload them).
Now, off to the tutorial!
The first thing we're going to do is activate the USB port. This step isn't needed, but I did it incase I wanted to edit anything, without going back to the main PSP menu over and over again.
so put this in as your first line of code.
Not the USB port on the PSP is activated.Code:System.usbDiskModeActivate()
Next, we're going to define our colors, like we did in the first tutorial.
We will be defining yellow, blue, orange, grey and black.
So put this in your code.
Done, and now we need to do the first part of the code that will display on the screen, the loading screen!Code:yellow = Color.new(255, 255, 0) blue = Color.new(0, 0, 255) orange = Color.new(223, 88, 6) grey = Color.new(94, 97, 111) black = Color.new(0, 0, 0)
Now our loading screen will say "Loading 0-100%".
To do this, we need to first print "Loading 0%" to the sreen.
So put this in your code.
So we've now printed "Loading 0%" to the screen, and flipped to to visible buffer.Code:screen:print(194, 136, "Loading: 0%", yellow) screen.flip()
Now we need to load our first images, which you can download HERE.
So put this code in to load the first image, the background.
Before anything, let me explain loading an image.Code:background = Image.load("background.png")
The first work in the code, is defining the name of the image, just like how we defined color.
Then Image.load is telling the PSP that this line of code is to load an image.
And of course, then we need to tell the PSP the name of the image, or else it wont be able to load it!
So we put ("background.png").
And remember, you must include the file extension in the name of the image, the same when loading a sound.
Now that the backround is loaded, we need the PSP to say "Loading 20%".
So put this in your code.
The only difference from this code from the other code we printed to the screen, is that we had to clear the screen first,Code:screen:clear() screen:print(194, 136, "Loading: 20%", yellow) screen.flip()
so it wouldn't print overtop of "Loading 0%".
Now we just do the same thing, but load the different images, and 1 sound. So put this in your code. I'm not going to explain it because it's all the same.
The one thing I am going to explain in that code is loading sound.Code:circle = Image.load("circle.png") down = Image.load("down.png") screen:clear() screen:print(194, 136, "Loading: 40%", yellow) screen.flip() l = Image.load("l.png") left = Image.load("left.png") screen:clear() screen:print(194, 136, "Loading: 60%", yellow) screen.flip() r = Image.load("r.png") right = Image.load("right.png") boltsnd = Sound.load("comp.wav") screen:clear() screen:print(194, 136, "Loading: 80%", yellow) screen.flip() square = Image.load("square.png") triangle = Image.load("triangle.png") screen:clear() screen:print(194, 136, "Loading: 90%", yellow) screen.flip() up = Image.load("up.png") x = Image.load("x.png") splash = Image.load("luasplash.png") screen:clear() screen:print(194, 136, "Loading: 100%", yellow) screen.flip()
Loading sound is almost the exact same as loading an image, in fact, it's practically identical. Only difference is that it is Sound.load instead of Image.load. And like I said earlier, you need toCode:boltsnd = Sound.load("comp.wav")
include the extension in the name, just like when you load an image.
Now we're just going to quickly freeze the "Loading 100%" screen for 1 second, or 60 vblanks (there are 60 vblanks in a second).
Put this code in.
There, our loading screen is finished. You can edit the color of the text, or even add an image above it (which I will explain at the end of my tutorial.)Code:screen.waitVblankStart(60)
Now it's time for the intro screen, thanks to indianajonesilm, author of PSP Air Hockey.
Save this image. I forgot to Include it in the Image pack download. Sorry :wall:
First things first, display the backround.
Displaying the backround is simple. We first type screen:blit, which is the code toCode:screen:blit(0, 0, splash, false) screen.waitVblankStart() screen.flip()
display an image, or a backround in our case. The next part, the two numbers, are where you want the backround to display exactly, but
since we want it to take up the whole screen, we're going to leave them at 0, and at the end of the code, put "false" to confirm that.
And splash is the name that we defined for the picture when we loaded it, so we put that in. Now we have the backround in our
intro screen.!
But of course, the intro screen is not done, we need MUSIC!...Or at least a sound.
So first we're going to play the music.
That is the code to play the music/sound.Code:boltsnd:play()
Now we're going to flip the screen again, configure the volume for the sound, and make it wait at that screen for 4 seconds.
Put this code, in your code.
As I noted before, there are 60 vblanks in a second, so when we put 240 inbetween ( and ), that means it will wait atCode:screen.waitVblankStart(240) screen.flip() Music.volume(128)
that screen for 240 vblanks, which is equal to 4 seconds.
Music.volume(128) is simple. It's just changing the music volume to 128.
Now our loading screen, and our intro are both done! Hooray! Give yourself a big hug.
But it's not all fun and games yet, we need to code the actual program!
So...Let's go!
The first thing we're going to do is display the backround.
Now the backround will be displayed while it is true (and it always is true).Code:while true do screen:blit(0, 0, background, false)
Now almost to the part where we code our button input, but first we need to read the state of the controls.
If you don't do this, then no buttons will respond.Code:pad = Controls.read()
Oops, not time for the button input yet, we're first just going to display some text. Telling us the controls and whatnot.
Put the following code chunk in your code.
Now it will tell us near the bottom of the screen that if you press Start, it will reset the application, and if you pressCode:screen:print(135, 251, "Press 'Start' to restart", blue) screen:print(110, 261, "Press 'Select' for a screenshot", blue) screen:print(383, 35, "Support:", black) screen:print(365, 45, "PS3Lounge.net", orange) screen:print(365, 65, "PSPHacks.net", orange) screen:print(365, 55, "PSPUpdates.com", grey) screen.flip()
Select, it will take a screenshot.
And of course we need to flip the screen, or else it won't be visible.
NOW, it is time for the button input code!
What is going to happen in our little application is this.
When we press 'X', it will display a picture of the PSP X button on the screen.
When we press 'UP', it will display a picture of the PSP UP button on the screen.
When we press 'L', it will display a picture of the PSP L button on the screen.
Etc, etc, etc..
Now that you understand what will happen, I can explain to you how we're going to write this code.
We're going to use "if" statements. "If" statements are used WIDLEY over any type of application/game etc. Everything has it.
What it does, is do something, if something else it true. Example, "If the X button is pressed, then display x.png".
The code is similar to that example, but it will be written a little different.
Put this in your code.
First of all, pad:cross() is the code for the button X. pad:cirlce(), pad:triangle() etc..Code:if pad:cross() then screen:blit(50, 228, x) screen.flip() end
The first line of code is saying "If X is pressed, then do this.."
Now we need to tell it what to do when X is pressed.
So we need to blit/display an image.
Put the following in your code.
Now if X is pressed, it will display an image, on the 50 pixel in width, and the 228 pixel in height.Code:screen:blit(50, 228, x) screen.flip()
And of course, we need to flip our screen.
Now we just need to end our 'if' statement.
Our first code of button input is done. Now if X is displayed, an image of 'X' will be displayed.Code:end
Now we need to do the exact same thing with Circle, triangle, square, up, down, left, right, l and r.
Put this in your code for those buttons.
Congratulations! You've finished your PSP Lua Application!... Or are we?Code:if pad:circle() then screen:blit(90, 195, circle) screen.flip() end if pad:triangle() then screen:blit(45, 165, triangle) screen.flip() end if pad:square() then screen:blit(15, 195, square) screen.flip() end if pad:up() then screen:blit(60, 40, up) screen.flip() end if pad:right() then screen:blit(90, 65, right) screen.flip() end if pad:down() then screen:blit(60, 80, down) screen.flip() end if pad:left() then screen:blit(30, 65, left) screen.flip() end if pad:l() then screen:blit(4, 6, l) screen.flip() end if pad:r() then screen:blit(403, 4, r) screen.flip() end
Nope.
But don't fret, we only have 5 lines of code to go! We need to put in the code so if you press Start, it will reset the application,
and so if you press Select, it will take a screenshot.
So put this in your code.
We've just used another 'if' statement. Now if you press select, it will take a screenshot and save it on the memory stick.Code:if pad:select() then screen:save("screenshot.tga") end
Almost done! Here is the last portion of code!
Again, we've used an 'if' statement. Now if Start is pressed it will restart the application.Code:if pad:start() then break end
Now we just need to end the whole application, by putting end as the last line of code.
NOW! We are done! Now you can really hug yourself, because your PSP Application coded in LUA, is DONE!Code:end
Here is what your code should look like:
And here is what your application should look like when you launch it.Code:System.usbDiskModeActivate() blue = Color.new(0, 0, 255) orange = Color.new(223, 88, 6) grey = Color.new(94, 97, 111) yellow = Color.new(255, 255, 0) black = Color.new(0, 0, 0) screen:print(194, 136, "Loading: 0%", yellow) screen.flip() background = Image.load("background.png") screen:clear() screen:print(194, 136, "Loading: 20%", yellow) screen.flip() circle = Image.load("circle.png") down = Image.load("down.png") screen:clear() screen:print(194, 136, "Loading: 40%", yellow) screen.flip() l = Image.load("l.png") left = Image.load("left.png") screen:clear() screen:print(194, 136, "Loading: 60%", yellow) screen.flip() r = Image.load("r.png") right = Image.load("right.png") boltsnd = Sound.load("comp.wav") screen:clear() screen:print(194, 136, "Loading: 80%", yellow) screen.flip() square = Image.load("square.png") triangle = Image.load("triangle.png") screen:clear() screen:print(194, 136, "Loading: 90%", yellow) screen.flip() up = Image.load("up.png") x = Image.load("x.png") splash = Image.load("luasplash.png") screen:clear() screen:print(194, 136, "Loading: 100%", yellow) screen.flip() screen.waitVblankStart(60) screen:blit(0, 0, splash, false) screen.waitVblankStart() screen.flip() boltsnd:play() screen.waitVblankStart(240) screen.flip() Music.volume(128) while true do screen:blit(0, 0, background, false) pad = Controls.read() screen:print(135, 251, "Press 'Start' to restart", blue) screen:print(110, 261, "Press 'Select' for a screenshot", blue) screen:print(383, 35, "Support:", black) screen:print(365, 45, "PS3Lounge.net", orange) screen:print(365, 65, "PSPHacks.net", orange) screen:print(365, 55, "PSPUpdates.com", grey) screen.flip() if pad:cross() then screen:blit(50, 228, x) screen.flip() end if pad:circle() then screen:blit(90, 195, circle) screen.flip() end if pad:triangle() then screen:blit(45, 165, triangle) screen.flip() end if pad:square() then screen:blit(15, 195, square) screen.flip() end if pad:up() then screen:blit(60, 40, up) screen.flip() end if pad:right() then screen:blit(90, 65, right) screen.flip() end if pad:down() then screen:blit(60, 80, down) screen.flip() end if pad:left() then screen:blit(30, 65, left) screen.flip() end if pad:l() then screen:blit(4, 6, l) screen.flip() end if pad:r() then screen:blit(403, 4, r) screen.flip() end if pad:select() then screen:save("screenshot.tga") end if pad:start() then break end end

Special Thanks:
Shine - for the wonderful Lua Player. Keep up the good work! Thanks!
indianajonesilm - For the Awesome "Powered by Lua" Intro. Thanks!
PSPUpdates.com - For up to the minute news and supporting developers, and helping out the PSP scene. Thanks!
Extras and Notes:
- Creating custom text colours.
It's very simple. Open up paint, go under Colors > Edit Colors. Then click define custom colors. Then make a color, and near the bottom right, it will display some numbers, under red, green and blue. These are the RGB numbers, just fill those in when you are defining a color.
And remember, the first number is Red, the second is Green, and the last is Blue.
- Displaying an Image during the Loading Screen
This is very simple to do. We're going to take 1 part of the code from the loading screen code in my tutorial and work of that.
There is only one thing we need to add to this code. A background.Code:screen:print(194, 136, "Loading: 0%", yellow) screen.flip()
First, right click this image and save it.

Now we need to add the code to display it.
Add this to the beginning of the code.
Now you just need to add that to all of the code throught, and now the image/backround will display during the loading screen.Code:screen:blit(0, 0, lua, false)
But now, the yellow text will be on top of a white background. It won't be very visible, will it. :doh:
So I suggest defining a new color, black. Put this code in where you define your colors.
Then just change yellow when you print text to the screen to black.Code:black = Color.new(0, 0, 0)
Now it will almost work, but we need to load the image, at the BEGINNIG of our code, because it blits the image while it load the other images, so if we loaded it later, it wouldn't be able to display/blit the image, and we would get an error. So put this after you define black.
The finished code should look like this.Code:lua = Image.load("luasplash.png")
Code:black = Color.new(0, 0, 0) lua = Image.load("luasplash.png") screen:blit(0, 0, lua, false) screen:print(194, 136, "Loading: 0%", black) screen.flip()
Well, I hope you enjoyed my tutorial, and I'm thinking about doing a 3rd now.
Again, post any comments, suggestions below.
One last this, I've noticed a bug in my code, but I can't figure out why it happens.
When it goes from the Lua intro screen, to the main code, it flickers for a second. If someone knew the cause, PM me, I'll edit the code and mention you in the special thanks list.
-
09-04-2005, 09:04 AM #3I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Listen!
I would like to take this moment to tell you all to NOT PIRATE. Think about it. If all this code just does this little button pressing program, think about how hard it would be to program a full flegged 3-D program?
DO NOT PIRATELast edited by whitehawk; 01-28-2006 at 08:50 AM.
-
09-04-2005, 09:18 AM #4
Ahhhhhhhhhhhhhhhhhhhhhhh. ... screen:flip()..... I think I know what's wrong wit my code!
"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me
[URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL]
-
09-04-2005, 09:19 AM #5
Oh!! Lua tutorials :) I might start soon ;)
Can I have one suggestion: Is it possible to show the finished code all in one code box?Do you know who I am?
-
09-04-2005, 09:23 AM #6I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Ya, sure, I'll edit it, hold on.
Originally Posted by FrozenIpaq
Sorry I didn't think of that before when I looked at your code :doh:
Originally Posted by MagicianFB
Oh well, at least your program will work now! :dance:
-
09-04-2005, 10:25 AM #7
would this be correct?
Code:if xx==3 and yy==2
"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me
[URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL]
-
09-04-2005, 10:27 AM #8QJ Gamer Blue
- Join Date
- Jul 2005
- Posts
- 68
- QJ Pts
- 4,688
- Level
- 43
- Downloads
- 0
- Uploads
- 0
Lua doesn't seem to be the greatest language, but it may have a redeeming factor if you can indeed edit the code on the go with another homebrew application. Can anyone confirm that?
-
09-04-2005, 10:30 AM #9I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
It's not supposed to be the best language, just the simpilest language. And my tutorial may seem too explained, but that's because this tutorial is for someone who can atl least install homebrew, not for someone experienced in coding, but not in lua.
Originally Posted by tehhunter
And ya, If you have a text editor for the PSP, then you can just open up the script and edit :) Never thought of that. Thanks.
-
09-04-2005, 10:30 AM #10I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Can you post the whole code first?
Originally Posted by MagicianFB
-
09-04-2005, 10:34 AM #11
I mean could that work as an if statement.
Originally Posted by whitehawk
but hear's my code anyways:
Code:k1 = Image.load("key1.png") k1a = Image.load("key1a.png") k2 = Image.load("key2.png") k2a = Image.load("key2a.png") k3 = Image.load("key3.png") k3a = Image.load("key3a.png") k4 = Image.load("key4.png") k4a = Image.load("key4a.png") k5 = Image.load("key5.png") k5a = Image.load("key5a.png") k6 = Image.load("key6.png") k6a = Image.load("key6a.png") k7 = Image.load("key7.png") k7a = Image.load("key7a.png") screen.waitVblankStart() while true do xx = 1 yy = 1 screen:blit(0, 194, k1a) screen:blit(26, 194, k2) screen:blit(52, 194, k3) screen:blit(0, 220, k4) screen:blit(26, 220, k5) screen:blit(52, 220, k6) screen:blit(0, 246, k7) screen.flip() pad = Controls.read() if pad:up() then if yy==1 then yy = 3 else yy = yy-1 end elseif pad:down() then if yy==3 then yy = 1 else yy = yy+1 end elseif pad:left() then if xx==1 then xx = 3 else xx = xx-1 end elseif pad:right() then if xx==3 then xx = 1 else xx = xx+1 end elseif pad:triangle() then if yy==1 then if xx==1 then print("a") elseif xx==2 then print("e") elseif xx==3 then print("i") end elseif yy==2 then if xx==1 then print("m") elseif xx==2 then print("q") elseif xx==3 then print("u") end elseif yy==3 then print("y") end elseif pad:circle() then if yy==1 then if xx==1 then print("b") elseif xx==2 then print("f") elseif xx==3 then print("j") end elseif yy==2 then if xx==1 then print("n") elseif xx==2 then print("r") elseif xx==3 then print("v") end elseif yy==3 then print("z") end elseif pad:cross() then if yy==1 then if xx==1 then print("c") elseif xx==2 then print("g") elseif xx==3 then print("k") end elseif yy==2 then if xx==1 then print("o") elseif xx==2 then print("s") elseif xx==3 then print("w") end end elseif pad:square() then if yy==1 then if xx==1 then print("d") elseif xx==2 then print("h") elseif xx==3 then print("l") end elseif yy==2 then if xx==1 then print("p") elseif xx==2 then print("t") elseif xx==3 then print("x") end end end if xx==1 and yy==1 then screen:blit(0, 194, k1a) else screen:blit(0, 194, k1) end if xx==2 and yy==1 then screen:blit(0, 194, k2a) else screen:blit(0, 194, k2) end if xx==3 and yy==1 then screen:blit(0, 194, k3a) else screen:blit(0, 194, k3) end if xx==1 and yy==2 then screen:blit(0, 220, k4a) else screen:blit(0, 220, k4) end if xx==2 and yy==2 then screen:blit(0, 220, k5a) else screen:blit(0, 220, k5) end if xx==3 and yy==2 then screen:blit(0, 220, k6a) else screen:blit(0, 220, k6) end if yy==3 then screen:blit(0, 246, k7a) else screen:blit(0, 246, k7) end screen.flip() end"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me
[URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL]
-
09-04-2005, 10:45 AM #126201ymereJ

- Join Date
- Jul 2005
- Location
- Baltimore
- Posts
- 588
- QJ Pts
- 7,062
- Level
- 55
- Downloads
- 0
- Uploads
- 0
ok, now, how to clear the screen :)
-
09-04-2005, 10:56 AM #13I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Here's the code to clear the screen.
Originally Posted by Jeremy1026
Code:screen:clear()
-
09-04-2005, 10:58 AM #14I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
I'll look into that (I'm actually not the most experienced coder here)
Originally Posted by MagicianFB
-
09-04-2005, 11:05 AM #15
:o gasp.... your still prety good though :)
Originally Posted by whitehawk
"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me
[URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL]
-
09-04-2005, 11:10 AM #16I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Thanks. :)
Originally Posted by MagicianFB
And, do you think im the youngest PSP coder? I'm 13
-
09-04-2005, 11:20 AM #17QJ Gamer Blue
- Join Date
- Jun 2005
- Location
- Canada
- Posts
- 248
- QJ Pts
- 5,194
- Level
- 46
- Downloads
- 0
- Uploads
- 0
To answer your question, yes "if xx==3 and yy==2" is proper. Though I dunno if thats how I would have typed it. I'd prefer seeing it as "if (xx==3 and yy==2)" (Kind of a prick when it comes to code neatness
), but ya... I've never actually used the LUA player so I don't know how much it would like that.
-
09-04-2005, 12:30 PM #18
lua doesn't use parentheses in if. Took me a little bit to get used to that ;)
Originally Posted by azt3k
"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me
[URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL]
-
09-04-2005, 01:05 PM #19QJ Gamer Blue
- Join Date
- Jun 2005
- Location
- Canada
- Posts
- 248
- QJ Pts
- 5,194
- Level
- 46
- Downloads
- 0
- Uploads
- 0
Acutally, Lua does indeed use them. I've been using LUA to script games like Far Cry for a bit now. Does the LUA player support them? That's another question.
-
09-04-2005, 01:52 PM #20
Well on lua-user.org The tutorial says they don't. :think:
Originally Posted by azt3k
What are the d-pad controls? Are they pad:up(), pad:down(), pad:left(), and pad:right()?"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me
[URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL]
-
09-04-2005, 02:22 PM #21I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Yup, it's exactly that.
Originally Posted by MagicianFB
Also, I'm working on tutorial 2.
-
09-04-2005, 03:18 PM #22
I found it informative anyway, thanks and looking forward to more.
-
09-04-2005, 03:19 PM #23
Thanks so much, omfg you pwn. Can you explain to me a bit more about what this means, and what it exactly does. THank you so much
while true do
screen.waitVblankStart()
-
09-04-2005, 04:08 PM #24
- Join Date
- Aug 2005
- Posts
- 5
- QJ Pts
- 4,528
- Level
- 42
- Downloads
- 0
- Uploads
- 0
I don't have the patience to try myself so I will make a request.
Remember Coleco "head to head football"? like all of the old school Matell football games that came back to market the last 3 years. This one had buttons on both sides of the screen. if Someone could duplicate this game I would bust a nut in my pants, plus, it could really be a cool homebrew when the PSP is held end to end by 2 players. ( I got the idea from ape academy)
See game here
-
09-04-2005, 04:45 PM #25QJ Gamer Blue
- Join Date
- Jul 2005
- Location
- In New York
- Posts
- 297
- QJ Pts
- 5,803
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Thanks, this is really cool, but im bored now, because i did my hello world in a sec, i guess i gotta wait for the other tuturial......
-
09-04-2005, 04:48 PM #26
hey, this tutorial helps, its great cuz I wanted to start coding in LUA. anyway, wut are the command promts for the other buttons like O, X, ^, and [_]. Are they sumthin like button:circle() - button:square() - button:triangle() - button:cross?? Also, could you maybe type up a list of a whole bunch of random commands that you know. I definatley think that will help evryone. thx again, its gerat to know that there are ppl otu there trying to help other coders
-
09-04-2005, 04:49 PM #27I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Basicaly, it repeats the code, so over and over again, the code to display the text will processed.
Originally Posted by Slasher
Without it, it will process the code, the text will be displayed, and then go away quickly.
And where it says 'while true do', is used in many cases. Here's a simple example.
If you wanted 'X is being pressed' when X is pressed, then you would write that exact code, so, while it is true (while X is being presses) display the text and repeat the code.
Same thing with this app, the whole time it is true, so it is being displayed.
-
09-04-2005, 04:50 PM #28
- Join Date
- Jun 2005
- Posts
- 16
- QJ Pts
- 4,650
- Level
- 43
- Downloads
- 0
- Uploads
- 0
Ok,
Originally Posted by Slasher
while true do
the While statement works as follows:
while <test> do
<some code>
end
So while the conditions in the <test> piece of code evaluate to True, then keep doing the code in the <some code> section.
In the example given, because true *is* true anyway, the while..do..end will loop endlessly around the code between the do and the end statements.
See the Lua Manual chapter on Control Structures for more details: http://www.lua.org/manual/5.0/manual.html#2.4.4
The screen.waitVblankStart() means:
Wait until the PSP gets to the next point where it is ready to draw the screen. Vblank is the period it takes for the PSP to draw a screen. On the PSP there are 60 Vblanks per second. So, waitVblankStart() means wait until the next Vblank. If you put a number in there, it'll effectively do nothing for that period, ie waitVblankStart(60) will wait for 60 Vblank periods, and as there are 60 Vblanks a second, the PSP will appear to wait for 1 second.
Then you can do screen.flip() to copy the off screen buffer to the actual screen the user sees - remember that all drawing operations in Lua go to the off screen buffer (a copy of the screen in memory if you like) and don't get sent to the actual PSP screen until you call the flip.
Hope that helps a little.
-
09-04-2005, 04:58 PM #29
opne more querstion aloong with the one i posted up there. WHat si the code 2 display an image? is it screen.print and the rooute to the image??
-
09-04-2005, 05:20 PM #30I think I ripped my pants
- Join Date
- Jul 2005
- Location
- Toronto
- Posts
- 6,484
- QJ Pts
- 33,140
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Your close, it's:
Originally Posted by RaiderX
Circle: pad:circle()
X: pad:cross()
Square: pad:square()
Triangle
ad:triangle()
L: pad:l()
R: pad:r()
Up: pad:up()
Right: pad:right()
Down: pad:down()
Left: pad:left()
Now the analog stick is a bit tricky.
pad:analogX()
Then, if you want for example, the analog stick to the left, you need to put
pad:analogX() < -30
And to the right..
pad:analogX() > 30
Now if you want the analog stick up
pad:analogY() > 30
And down..
pad:analogY() < -30
If your wondering why left and right have an X, and up and down have Y, it's simple, and you should know.
Just like when doing a graph, Y is vertical, and X is horizantal. It's the XY axis.
So analog:Y() is vertical, and then if you want it to be up, the value has to be 1 or above. So you put '> 30', for 30 or above.
And for down, the value has to be -1 or lower, so we put < -30.
Same thing for analog:X(), left is below -1, and right is above 1.
Last thing, if your wondering why i put 30 isntead of 1, is because the analog stick is so sensitive, that if you put something like 5, the analog stick value could be at 10 even when not being touched.


LinkBack URL
About LinkBacks
Reply With Quote

I recently played a bit of Super Mario 3D World + Bowser's Fury and I enjoyed playing this...
Super Mario Fans Out There!