Editing The Basics Part 1

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:
The Basics<br>
The Basics<br>
Lua Programming Techniques<br>
Lua Programming Techniques<br>
After having read [[Hello World Part 1|Lua Lesson 01]], you should have a basic concept of how to run Lua programs and how to setup a simple script. You are now ready to move on to some more advanced concepts that will prepare you to create fully featured applications and games.<br>
After having read Lua Lesson 01, you should have a basic concept of how to run Lua programs and how to setup a simple script. You are now ready to move on to some more advanced concepts that will prepare you to create fully featured applications and games.<br>




Line 11: Line 11:




If you haven't read the first tutorial, I highly recommend it. If you decide to go on anyway, without reading it, and become baffled, and in the process having your mind transformed in to a gooey puddle of radioactive mush, don't come complaining to me. (Aside: actually it's not really that difficult, I just thought I'd add a little drama to the tutorial).<br>


If you haven't read the [[Hello World Part 1|first tutorial]], I highly recommend it. If you decide to go on anyway, without reading it, and become baffled, and in the process having your mind transformed in to a gooey puddle of radioactive mush, don't come complaining to me. (Aside: actually it's not really that difficult, I just thought I'd add a little drama to the tutorial).<br>


 
Before you start, you will need to download a zip file containing the images used in this tutorial. (The preceding phrase was a link, for those of you who skimmed right over it).<br>
 
Before you start, you will need to download a [http://web.archive.org/web/20080508051830/http://www.psp-programming.com/tutorials/lua/lesson02.zip zip file containing the images used in this tutorial]. (The preceding phrase was a link, for those of you who skimmed right over it).<br>




Line 26: Line 24:


Now the USB port on the PSP will be activated when you run your script.<br>
Now the USB port on the PSP will be activated when you run your script.<br>




Line 35: Line 32:
gray = Color.new(153, 153, 153)
gray = Color.new(153, 153, 153)
black = Color.new(0 , 0 , 0)
black = Color.new(0 , 0 , 0)
If you have forgotten how these lines work, go back to [[Hello World Part 1|the last lesson]] and refresh your memory.<br>
If you have forgotten how these lines work, go back to the last lesson and refresh your memory.<br>




 
Now we want to display a loading screen. Our loading screen will say "Loading: 0%" then "Loading: 1%" and so on and so forth until "Loading: 100%." To start it off, we need to print "Loading: 0%" to the screen. You should remember the screen:print function from Lua Lesson 01. But in case you don't, here's the code that you will need to insert:
Now we want to display a loading screen. Our loading screen will say "Loading: 0%" then "Loading: 1%" and so on and so forth until "Loading: 100%." To start it off, we need to print "Loading: 0%" to the screen. You should remember the screen:print function from [[Hello World Part 2|Lua Lesson 01]]. But in case you don't, here's the code that you will need to insert:
screen:print(194, 136, "Loading: 0%", pink)
screen:print(194, 136, "Loading: 0%", pink)
screen.flip()
screen.flip()
Line 45: Line 41:




 
Next, we need to load our images (which, if you missed it before, can be downloaded here). Extract the zip file into the folder where your script file is on your PSP. Then add this line. It will load the background.
Next, we need to load our images (which, if you missed it before, can be downloaded [http://web.archive.org/web/20080508051830/http://www.psp-programming.com/tutorials/lua/lesson02.zip here]). Extract the zip file into the folder where your script file is on your PSP. Then add this line. It will load the background.
background = Image.load("images/background.jpg")
background = Image.load("images/background.jpg")
Before we move on, let's get a firm understanding of what this line of code actually does. The first thing we see is a variable name, background. We then set that variable equal to the result of the function on the right ("Image.load()") using the assignment operator, or equal sign. The actual loading of the image comes through the "Image.load()" function which is built into Lua. It takes one parameter, the path to the image file we want to load. Our image is in the "images" folder, and the picture we want to load is "background.jpg." Remember, you must always use the file's extension when loading it (in this case, it was a jpeg file, so we used the extension ".jpg").<nowiki>Insert non-formatted text here</nowiki>
Before we move on, let's get a firm understanding of what this line of code actually does. The first thing we see is a variable name, background. We then set that variable equal to the result of the function on the right ("Image.load()") using the assignment operator, or equal sign. The actual loading of the image comes through the "Image.load()" function which is built into Lua. It takes one parameter, the path to the image file we want to load. Our image is in the "images" folder, and the picture we want to load is "background.jpg." Remember, you must always use the file's extension when loading it (in this case, it was a jpeg file, so we used the extension ".jpg").<nowiki>Insert non-formatted text here</nowiki>


When you understand, move on to [[The Basics Part 2|part two]] of this tutorial to continue your program.
When you understand, move on to part two of this tutorial to continue your program.
Please note that all contributions to PSP Developer wiki are considered to be released under the GNU Free Documentation License 1.2 (see PSP Developer wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)