Go Back   PSP Crazy Forums - PSP Games, PSP Downloads, PSP News, and PSP Themes > Playstation Chat > PSP Homebrew Discussion

Reply
 
LinkBack (1) Thread Tools
Old 04-25-2006   1 links from elsewhere to this Post. Click to view. #1 (permalink)
GamingCrazy Semi-Addict
 
c5cha7's Avatar
 
Join Date: Jul 2005
Location: You are Here ---> Status: Backup Provider Thanked: 35 Times in 2 Posts
Age: 17
Posts: 648
Credits: 803
Lua Programming Tutorials

LUA PROGRAMMING LINKS!
These links will help you discover more about the world of lua,
Once you finish PSPCrazy's Lua Tutorials you may be seeking more knowledge around lua so i have provided the following links until i finish the rest of this tutorials .
[Only registered and activated users can see links. ] and [Only registered and activated users can see links. ]
LUA PLAYER PROGRAMMING TUTORIALS!

I thought it would help to get pspcrazy more involved with
coding in Lua . As many others have been asking "how
do i code in lua?" or "How do i make my own game?" .
Well we will start off with hello world!
This is a simple app in lua that will display the text "Hello World"
Until you exit back to the XMB or Turn of your psp .

1 - Getting Started
Now to start off we need to create some space for your projects.
So create a new folder anywhere on your PC named "Projects" or anything
you would remember where you are going to store your projects .
When you have that done create an "EMPTY" Text document,
open the text document in your favorite Word/Text editor program.
Now this is where we are gonna start coding your first project
in Lua "HELLO WORLD!" (finally lol).

2 - Coding Your First Simple App
Okay, now we want to tell your program what color
to load for the text to display on your PSP, so insert
this into your empty text document:
Code:

white = Color.new(255, 255, 255)
 
Now i bet your wondering what the hell doe's this mean???
well "white = Color.new" is telling your program that Color.new
is gonna be named "white". The "(255, 255, 255)" is telling
your program where the specific RGB is located.
Here is what the "," stands for:
-(000, 000, 000)-
RED, GREEN, BLUE
You can find the color you want by opening any paint editor
and changing the RGB like so >

So now that we know how to load the color we will want
to keep the the program in a loop! If we didn't have our program
in a loop it would skip past the text we told it to display within
miliseconds! So now we are going to make a "LOOP" also known as
"While true do" .
So put this in our code:
Code:
while true do
This will continue looping the text until the program
is exited or given a command to stop!.
[NOTE:] The "while true do loop" will also loop
any other given command like screen:blit().
So now that we have our "while true do" we will want
to display the text "Hello World" (Finally).
This is quite easy and the text can be changed to
your liking too!
So insert this into your code:
Code:
screen:print(5, 5, "Hello World by c5cha7",white)
notice the Double Quotation marks (i.e. "")
around "Hello World by c5cha7", well
thats where you can insert any text that you want it to display.
The 5, 5, is where the text will be printed on your PSP
screen. The first 5, is known as X and the second 5, is usually known
as Y. This isn't complicated one bit, just open paint and look
at the bottom right hand side and you'll see this
when you move your cursor in paint it
will display different numbers based on where you are located
on screen!
Now then, we want to keep our text printed properly
on the screen with no "hiccups" at all!
So we are going to insert this into our code
Code:
screen.waitVblankStart()
Don't worry too much about that just yet.
It can hold more functions but i highly doubt we
will need any extra functions for it as of yet!
So if you've made it this far then please pat yourself
on the back because my grammer is not the best lol.
Now moving on! We still have to refresh the screen
and keep it updated. If we don't have this code
in our program it wouldn't display the text at all.
It is known to set the offscreen buffer to make
your screen call's visible (sorry but i aint good at explaining stuff lol).
So we are going to insert this next line of code into
your program:
Code:
screen.flip()
Okay as again we wont need any extra functions added
to this one! We can tell the screen.flip to refresh every so often.
But we dont need to do that just yet.
Moving on!
You remeber the "While true do" loop we inserted into our
small app before? Well we haven't quite finished that function yet!
Now that we have put all of our code in the "while true do"
function/loop, we will need to tell it that this is the end of our
code. So this is the last line of code we are going to put in.
Please insert this into your code at the end:
Code:
end
See it's simple! I bet you thought it was gonna be something big and
confusing, but thats for C Programmers!
Now then your code should look like the following:
Code:
white = Color.new(255, 255, 255)
while true do
screen:print(5, 5, "Hello World by c5cha7",white)
screen.waitVblankStart()
screen.flip()
end
And there you have it! your first Lua Program!
Should display as the following:


So download Lua player from [Only registered and activated users can see links. ]
and install Lua Player on you PSP in "PSP/GAME/"
Then open "PSP/GAME/LUAPLAYER/" and insert your
text document there! Rename your text document to
index.lua and startup luaplayer on your psp.

More tutorials coming soon! Including grammer check lol...
Sorry about the real bad English but i will correct it soon!

3 - Blitting Image's
Okay, now that you have learn't the basic's of the text function for
Lua i bet you want to do more? Yes really? lol! Okay this tutorial
will teach you how to blit an image to your screen! As once
again i ain't too good with my grammer and spelling so please
ask any questions if you are stuck!

Follow [1 - Getting Started] and create a new folder named
"Blitting Images" now create a new text document in the folder
you have just made.
First of all open the new text document with your favorite
text editor. Now then, lets get started shall we?
This time we want to load the image so we put this in
our new text document!
Code:
background = Image.load("background.png") 
Where it says "background = Image.load" we are telling
it that Image.load is now called background!
("background.png") is where the background is located
on your PSP .
(note that it is located in the same folder where the script is!)
Now then we have just learn't how to load our image!
Then what we want to do is put our image in a "LOOP" again!
Just like the "Hello World" Tutorial we will have to insert this
into our code! So make sure you insert the following:
Code:
while true do
There, you see it's simple! That will make sure it keep's the image
looping or as i like to say blitted on-screen.
Okay heres the fun part (or maybe not)... We next want
to blit our image to screen! So when we told
"background = Image.load" we will be calling the background.
So make sure you insert this into your code:
Code:
screen:blit(0, 0, background) 
Notice that screen:blit is similar to screen:print? Well
thats because they are both calling the screen.
The 0, 0, is once again the same as the screen:prints
0, 0, ! All that it does is tells the PSP where to place the image
(See simple!). Now then you remember we told
background = Image.load ? Well thats why our code
has background in the end of it. So our code activates the background
and our background activates the image in which we told it to load!
Please don't get confused yet with me lol.
Now we do the same as the "Hello World" tutorial again!
Remeber when we used the
screen.waitVblankStart()
screen.flip()
functions? Well we will be using them once again.
You should already know what they are for, so if
you don't please learn the "Hello World" Tutorial!
Okay, then please insert this into your code!
Code:
screen.waitVblankStart()
screen.flip()
Now we once again need to tell the "While true do loop"
that this is the end of our code! So insert this into your script:
Code:
end
And there you have it! Note that Luaplayer can only load
Jpeg/JPG/PNG images at the moment!
Your following code should look like this:
Code:
background = Image.load("background.png")
while true do
screen:blit(0,0, background)
screen.waitVblankStart()
screen.flip()
end
The out come should look like the following:
(Depending on what image you choose to load!)

Last edited by c5cha7; 06-21-2006 at 04:31 PM.
c5cha7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 04-25-2006   #2 (permalink)
GamingCrazy Semi-Addict
 
c5cha7's Avatar
 
Join Date: Jul 2005
Location: You are Here ---> Status: Backup Provider Thanked: 35 Times in 2 Posts
Age: 17
Posts: 648
Credits: 803
Re: Lua Programming Tutorials

Reserved for More tutorials!
c5cha7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-25-2006   #3 (permalink)
GamingCrazy Semi-Addict
 
c5cha7's Avatar
 
Join Date: Jul 2005
Location: You are Here ---> Status: Backup Provider Thanked: 35 Times in 2 Posts
Age: 17
Posts: 648
Credits: 803
Re: Lua Programming Tutorials

Reserved for More Tutorials!
Please check back soon and feel
free to ask questions or ask for help .
c5cha7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-25-2006   #4 (permalink)
I Haz Cheez!
 
dan_barney's Avatar
 
Join Date: Oct 2005
Location: UK,Hampshire
Age: 16
Posts: 3,954
Credits: 9,529
Send a message via MSN to dan_barney
Re: Lua Programming Tutorials

These tutorials will be useful, when I find time to learn Lua.
dan_barney is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-25-2006   #5 (permalink)
GamingCrazy Semi-Addict
 
c5cha7's Avatar
 
Join Date: Jul 2005
Location: You are Here ---> Status: Backup Provider Thanked: 35 Times in 2 Posts
Age: 17
Posts: 648
Credits: 803
Re: Lua Programming Tutorials

Quote:
Originally Posted by dan_barney
These tutorials will be useful, when I find time to learn Lua.
Thanks .
Updating them soon!
Also adding more tutorials on how to create your
own game etc...
c5cha7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-25-2006   #6 (permalink)
I Haz Cheez!
 
dan_barney's Avatar
 
Join Date: Oct 2005
Location: UK,Hampshire
Age: 16
Posts: 3,954
Credits: 9,529
Send a message via MSN to dan_barney
Re: Lua Programming Tutorials

Quote:
Originally Posted by c5cha7
Also adding more tutorials on how to create your
own game etc...
I can't wait.
dan_barney is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-25-2006   #7 (permalink)
GamingCrazy Semi-Addict
 
c5cha7's Avatar
 
Join Date: Jul 2005
Location: You are Here ---> Status: Backup Provider Thanked: 35 Times in 2 Posts
Age: 17
Posts: 648
Credits: 803
Re: Lua Programming Tutorials

Image Blitting Added !
Have fun and hopefully more coming soon!
Would it be possible to sticky this thread? unless a mod
is gonna create there own lua programming tutorials thread?
Just wondering!

Also to the mod's of pspcrazy!
Please feel free change some stuff and
add spelling checks etc. I did this tutorial
specially for pspcrazy so dont claim it for
your own site if .
c5cha7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-25-2006   #8 (permalink)
GamingCrazy Novice
 
Join Date: Nov 2005
Posts: 215
Credits: 318
Send a message via AIM to Slasher
Re: Lua Programming Tutorials

awesome c5cha7 Glad to see your helping us out here. I'll sticky it right away
Slasher is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Old 04-25-2006   #9 (permalink)
GamingCrazy Semi-Addict
 
c5cha7's Avatar
 
Join Date: Jul 2005
Location: You are Here ---> Status: Backup Provider Thanked: 35 Times in 2 Posts
Age: 17
Posts: 648
Credits: 803
Re: Lua Programming Tutorials

Quote:
Originally Posted by Slasher
awesome c5cha7 Glad to see your helping us out here. I'll sticky it right away
Neat
I did some grammer checks too!
Also thanks for deleting the double post lol!

Thanks again! your da man .
c5cha7 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-28-2006   #10 (permalink)
GamingCrazy Beginner
 
Join Date: Jan 2006
Location: United Kingdom, England
Posts: 77
Credits: 175
Re: Lua Programming Tutorials

C5cha7, these tuts are sooo rubbish, they are wrong...
Only jokin, kool tuts man.
Vaza is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  PSP Crazy Forums - PSP Games, PSP Downloads, PSP News, and PSP Themes > Playstation Chat > PSP Homebrew Discussion


LinkBacks (?)
LinkBack to this Thread: http://www.pspcrazy.com/forums/psp-homebrew-discussion/46886-lua-programming-tutorials.html
Posted By For Type Date
Как се пише homebrew? - PSP-Bulgaria Forums This thread Refback 10-01-2007 06:54 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

visitor stats
All times are GMT. The time now is 11:02 AM.


Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
© 2005-2007 PSPCrazy.com Network
vB Ad Management by =RedTyger=