Forum    News    Downloads    Saved Games


LAU tut

<<

jtwright

User avatar

Brewery Master
Brewery Master

Posts: 1189

Joined: January 06 2006

Location: In the realms of hell <:OD

Thanks given: 0

Thanks received: 0

Post Fri Apr 21, 2006 6:57 pm

LAU tut

Getting Up and RunningWelcome to the Lua tutorial.
This series of tutorials will be aimed at the complete beginner programmer, and will teach you Lua while learning to develop small games.
Before we get started there are a few things we will need. Not all are required, but it will make it easier to follow along.
.LuaPlayer - Gotta get this, so go ahead and grab it first.

.LuaPlayer for Windows - Saves you tons of time not having to transfer files back and forth to your PSP. We will be using this with the tutorials, so be sure to download this.

.ConTEXT Editor - Great text editor. Highlights keywords in many languages. Not at all required. You can use Notepad or any other editor.

.PSP Lua Highlight File - A highlighter I made for the ConTEXT editor. Adds most PSP specific keywords so that they will highlight. Place in the Highlighters folder. To use, when you run ConTEXT navigate to Tools > Set Highlighter , then choose PSP Lua.

Using LuaPlayer For Windows

.Extract the contents of the downloaded file.
.
Inside the folder you extracted the files to create a text file with Notepad. Inside the file type luaplayer script.lua
pauseSave the file as script.cmd, and make sure it doesn't save with a txt extension. This is the file that will run your program on your PC. luaplayer runs the luaplayer in the folder, and script.lua is the name of our file that we will be programming in. Pause will keep the command box from closing when we get an error. This way we can debug our programs.

.Now create another text file with Notepad (or any editor such as ConTEXT) and name it script.lua (Note: If you get an error about script file not found when you try to run this on your psp, you may need to rename the file to index.lua). You can leave this file blank inside for now. This is the file we will code in later


Introduction:
Now, we are going to make our first Lua Program for PSP. Keep in mind throughout the tutorials we will be using the Windows version of LuaPlayer. Some things in the Windows version do not work quite as well, or at all. For example, the sound isn't very good. Some newer functions recently added to LuaPlayer also do not work at all in the Windows version. But, for the things we will be doing, all should be fine.
You should put the luaplayer and luaplayer% folders on your PSP in the PSP/Game directory.
If at anytime you want to test your program on your PSP drop your script.lua file in the directory with the EBOOT.PBP file and run LuaPlayer.

Writing Your First Lua Program:
Open up your script.lua file with your choice of text editors. Notepad is fine if that's all you have. Our first program is simply going to print something to the screen. Let's get started!
Comments:
The very first thing we're going to learn is how to make comments in your code.
Comments are used to leave notes or information about your code. It is very useful in case you let others look at your code. Believe me, it also helps yourself. If you stop a project and go back and look at your code months later you will most likely be lost within your own code, without comments!

So how do we write comments? That's what we're gonna do right now. Let's start our new program with a title and author comment.


-- My First Lua Program
-- Author: YourNameHere
As you can see, comments are typed in starting with two dashes ( -- ). Anything you type after this will not be read in as code, but will rather be skipped and ignored completely. But, be aware, you must keep the comment on the same line of code. If you use the return key to go to another line you will have to use the dashes again to comment on the next line. We did this above.
That should do you in for comments for now. See this isn't so bad is it?

Creating a Color Object:
Next we're going to create a color object in order to let us print text to the screen. We will assign a specific color to this and use it with the print command shortly. Here's the code. Go ahead and add it to your program, being sure to put it on it's own line. You may skip a line also to separate the code from your Title info.
WARNING:Lua is case sensitive meaning the commands must be typed in the exact case they are shown. Below the code will not work if you type color instead of Color.


red = Color.new(255, 0, 0)
Now, we have created our color object. This basicly creates a color using RGB values and stores it in the variable, which is red in this case. You can get RGB color values for any color you want in any image program, even Paint. The variable red is where the color information is stored, but that does not mean if you replace it with the word blue that it will change to blue. The variable has nothing to do with what color it is. The color comes from the RGB value. So, using BigFatTurkey instead of red would not make any difference. If you do not understand what I mean when I say variable, don't worry with that because we will learn all about them very soon!

Printing To The Screen:
Ah, the most exciting part of our program. We will now use the print command to print some text to the screen. Put this code underneath your last bit of code.


screen:print(200, 100, "Look! I made text appear!", red)
Let's break it down so you can understand. scree:print simply tells our program to print something to the screen. Next within the parentheses we have several values. These are called arguments, and each function can have different amounts of arguments as well as different kinds. In the print one we are using it calls for four arguments.
Here it is so you can see: screen:print( x, y, stringOfText, colorObject)
The first argument, x, tells the program how many pixels from the left of the screen to print the text.
The second, y, tells it how far from the top of the screen to print the text.
The third is where you type in the the string of text to be printed. Remember to always enclose it in quotes.
And the fourth...hey it's that red color object we created earlier! This tells the program to print the text using the color red, which we created. Keep in mind you must create the color BEFORE using it in a print statement.

Offscreen Buffer To Onscreen Buffer:
This next bit of code may sound confusing. But don't worry, even if you don't completely understand it, you wont be too bad off. Here it is. Put this below your last code, as usual.


screen.flip()
In a nutshell, everthing is drawn first offscreen, so we have to use this command to make it appear on the screen.

A Loop?:
Yep. Next we are going to create a program loop. What this does it repeat a section of code over and over until something makes it stop. In this case it's so our program won't end as soon as the text appears. Without this we would never see the text because the program would end too fast. Here's the code...I think you know where to put it by now.

Variables
In this tutorial we are going to learn how to use variables in your programs. Variables are very important and will surely become one of your best friends later on. You can think of variables as storage containers that will hold information for you that you can recall at anytime in your program.

Write a Simple Program That Uses Variables:
Now we are going to make a simple program that will put some variables to use.
Also, we will learn how to do simple arithmetic in Lua.
This time around we will be commenting each line of our code.
Let's start off once again by creating a color object, which we'll use to print our information to the screen. This time let's use the color green.


-- Green Color Object
green = Color.new(0, 255, 0)
Now, let's create our very first variable. This will be a variable used to store your birth year. Feel free to put your own birth year in place of 1981. In fact, I recommend it!


-- Store birth year in variable myBirthYear
myBirthYear = 1981
There! What we've done is take the number 1981 (or your birth year if you used it) and stored it in the variable which we named myBirthYear. We will later use this variable in our program.

Let's make another variable under this one now that will store the current year.


-- Store current year in currentYear
currentYear = 2006
Now, let's create one in a slightly different way under that one.


-- create an empty variable
myAge = nil
Notice this time we assigned the nil value to the variable. This simply means nothing is assigned to the variable yet. We will later store something in the variable.

OK, now we are going to create one last variable just to show that you can also store strings (text) into them as well as numbers. This is done by enclosing the text within quotes.


-- Store some text in a variable
someText = "My age is roughly "
Alright, I'm sure you've had it with creating variables, so let's use them now.
Here's what we're going to do with this program. We're gonna use our variables and some basic math to roughly calculate your age. So, go ahead and add this code to your program.


-- Subtract myBirthYear from currentYear and store in myAge
myAge = currentYear - myBirthYear
This will take the value stored in myBirthYear and subtract it from currentYear, and then store the answer in the myAge variable. Now myAge has been assigned a value!
Now, let's use the print command that we used in the last lesson to print our text variable to the screen.


-- Print our text variable to the screen
screen:print(10,100,someText,green)
The only thing we did different from the last time we used this (besides the color) is the fact that we are printing a variable's information instead of direct text. Note that no quotes are required to do this. So, this will print whatever is stored in someText onto the screen in green text at X-10 Y-100.
We are going to want to print the result of our age right beside this line so let's learn a simple new command. To print myAge to the screen right beside the text of someText we can use double periods (..)
This is called concatenation. So now, CHANGE the last bit of code you did in order to make it look like the code below.


-- Print our text variable and age to the screen
screen:print(10,100,someText .. myAge,green)
Finally, let's throw in the screen.flip() and a loop to finish off our program.


-- Buffer offscreen to onscreen
screen.flip()
-- Loop forever
while true do
screen.waitVblankStart()
end
Save your program and run it to see the result. It should look like the image below.
Image
By using these variables, we can change myBirthYear and the program will automatically calculate someone elses age. Without variables you would have to change multiple (sometimes THOUSANDS) of lines of code in some programs.

In this tutorial we only used subtraction. For this we simply used ( - ) just as you learned in school.
For addition you use +
To multiply you use *
To divide you use /





while true do
screen.waitVblankStart()
end

Sony PSP Lua Programming: Button Input
In this tutorial we are going to learn how to take button input for your PSP, and make a simple program that will display text to the screen when you press certain buttons. Without button input, there is no user interaction, which is well....quite boring. So we're going to go ahead and learn a little about it now. We will make use of the commands we learned in the earlier tutorials, including variables. We will slack off a little with comments in this tutorial, and introduce another method of keeping your code in order, by splitting it up in sections.

Make Use of Button Input:
Let's start by making a section that we will use for variables. Feel free to make your own design instead of the stars!

-- ******* Variables ********
Once again, we need our color object so that we can write to the screen. If you like, make several different color objects, each on their own line. You will be able to use them. But, I will leave that to you. I will only make one myself. (Learning to do things on your own early on is a plus)


green = Color.new(0,255,0)

Next, we are going to create some variables that will store text that will be printed when we press a button. This we tell what button you are pressing. We will only make half of the buttons we use with variables. The other half we will directly print out with the print command. Why? For one so you can practice your variable use, and two, to see that either way works fine for a program this small. We are going to be using ten buttons. These will be the directional buttons, the shape buttons, and the shoulder buttons.
We are also going to use the print command slightly different this time. When we print what button we're pressing to the screen we want the button to be in quotes and in order to do that we'll use single quotes to surround our string of text, instead of quotes. If we use the normal quotes then the program will think we are ending the string of text where our button word is.
Let's make our five variables (remember I said half).


upPressed = 'You are pressing the "UP" button'
downPressed = 'You are pressing the "DOWN" button'
leftPressed = 'You are pressing the "LEFT" button'
rightPressed = 'You are pressing the "RIGHT" button'
LPressed = 'You are pressing the "L" button'

Now that we've gotten that over with let's move on. Remember that loop thing that we keep using... and avoiding?! Well, it's time to learn a little more about it. Every game you make will have a main program loop. What this is, is a section of code that will repeat over and over and over and over until a certain condition is met, whatever that may be. Inside the loop there are sections of code that will be performed. Some of them will be performed every single time the program loops, some will check to see if the condition is right, and then choose whether or not to perform that piece of code. Let's start our loop.


-- *****Main Loop******
while true do
From this tutorial on we will start coding inside of the loop, which we haven't done yet. Let's put in our next line of code, which is something new. Clearing the screen.


screen:clear()
This command will clear the screen, erasing everything you've put there. Every time the loop repeats everything on the screen will be cleared. By the way, these loops run at speeds so fast you'll never know it's happening! Without doing this everything we print would get pasted on top of what we printed before, creating a big ugly blob.
Let's move on to something else new.


pad = Controls.read()
Put simply, this will read button input each time the program loops. Also, note that pad is a variable and that you could use any other name, such as buttons. pad seems to be the standard, so we'll use it.

Now it's time to learn your first conditional expression, the if statement. It's not as bad as it sounds, trust me. Also, this will introduce the button input command. Let's get it in our program, then I'll explain.


if pad:up() then
screen:print(100,100,upPressed,green)
end
What this is saying is "if the up button is pressed then print the text in the variable upPressed with the color green". This returns either true or false. Every if statement starts with the word "if", then gives something to check for. In this case, is up being pressed? Next, it has the word "then" followed by the code that will perform if the condition is true. Finally the statement always ends with the word "end". The terms are so easy you can read the statement and tell instantly what it's doing. This is a quick intro into this, and we will dive more into it later. Now, let's add the code for the other three directional buttons, and one shoulder button, L.


if pad:down() then
screen:print(100,100,downPressed,green)
end
if pad:left() then
screen:print(100,100,leftPressed,green)
end
if pad:right() then
screen:print(100,100,rightPressed,green)
end
if pad:l() then
screen:print(100,100,LPressed,green)
end
Now for those other five buttons. We will write the text directly in the print statement for these, just to practice different methods.


if pad:r() then
screen:print(100,100,'You are pressing the "R" button',green)
end
if pad:triangle() then
screen:print(100,100,'You are pressing the "TRIANGLE" button',green)
end
if pad:circle() then
screen:print(100,100,'You are pressing the "CIRCLE" button',green)
end
if pad:cross() then
screen:print(100,100,'You are pressing the "X" button',green)
end
if pad:square() then
screen:print(100,100,'You are pressing the "SQUARE" button',green)
end
Phew! Now let's finish up our loop. We need to flip the screen so that the offscreen buffer goes to onscreen. Note, the "end" is to end our "while loop".


screen.waitVblankStart()
screen.flip()
end

Run it and press some buttons to see what happens! Here's a screenshot of mine.
Image


Sony PSP Lua Programming: Tables (Arrays):
Tables in Lua are very much like variables. The main difference is that tables can be used to store multiple amounts of data, rather than just one item of data. You can think of this as a storage container with many "drawers" in it for storing different information. Any game you make in the future will most likely use several Tables. Using tables in Lua is basicly the same as using arrays in other programming languages. We are going to learn a few other things in this tutorial as well.

Write a Simple Program That Uses Tables:
Let's say we're making a little game that is going to have a total of 5 types of enemies, and 2 players. In order to do that we are going to have to give the program some information about those characters. What information about the players and enemies do you suppose we need?
I'm sure you can think of tons of ideas, but since you're just learning we're only going to keep it very simple. In order for our enemies to be killed they have to have health. So for one, we need to give the program the information to keep up with the enemy health. We will also use information for identifying the type of enemy we are using.
For our players we will need health as well. What else could we use? How about the type of weapon our player has!
That should be able to get us going for now.
We will now start the table learning. Please only add the code to your file when instructed to. In this tutorial I will make several references to code that you shouldn't use in your file.
Tables are defined in the following way:



tablename = { }

First is the name of the table (any name you like), followed by the equals sign, and then a left and right (open and close) curly bracket. This creates an empty table with no data inside. To assign data to the table you simply add it inside the brackets, separating each one by a comma. Here's an example:

myTable = { 12, 14, 16, 18, 20 }

Keep it mind this is basicly exactly the same as variable use. It just looks a little different. Now, how do we use this? Well, each section of data inside the table is indexed into an array element that we can call by using the name of the table with opening and closing square brackets to the right of it, with a number of the index inside. WHAT?! Let's look:

luckyNumber = myTable[1]

Here we assigned the value of the FIRST section of data (which is 12) in our table to the variable luckyNumber. Look back up at the table I made. Inside the curly brackets how many sections of data do we have? If you said five you are correct. The first was 12, second was 14, third was 16 and so on. We can reference that data very easily in the way I described above. The indexing starts at 1, unlike some languages which start at zero. So, here are all the table elements that we are able to use from this table.

myTable[1]
myTable[2]
myTable[3]
myTable[4]
myTable[5]

At this point I think you should try to write your own simple program using a table. Remember the first tutorial we did when we simply printed a line to the screen? Instead of variables create a table, and use the print command to print one element of your table. You could also make it print several or all elements with multiple print statements. But remember to change the Y value of the print command if you do, or else it will print that big blob we talked about earlier. You do not have to change the X value, as that value refers to horizontal position. The program will not automatically print to the next line, you have to tell it to. You will have to play with how many pixels down it needs to go to keep it from overlapping, or from being too much distance. Use the print command the same way you did with a variable, but instead with your table element : tablename[number].
Go ahead and try, I'll wait here I swear!

Alrighty, I hope you did well. I would also like to point out that you can create empty tables and later in your program assign values to them. Here's an example of creating an empty table, and then assigning values to different elements of the table.

myTable = { }
myTable[1] = "apple"
myTable[2] = "orange"
myTable[3] = "banana"

Notice you can use strings of text as well, instead of numbers, as long as you enclose them in quotation marks.

Next, we are going to get a little more complex with tables. You can add an extra dimension to refer to your table elements. This is sometimes referred to as dictionaries or types. This is very very useful in making your code organized and readable. Let's see an example. I'll make an empty table and then the next line will introduce this method.

shirt = { }
shirt[1] = { color = "blue", size = "small" }

Basicly what we did was create a table, and then in our element shirt[1] we created another table within our table. Now, let's say we wanted to use this in a program to get our shirt color and size. It would look like this:

shirt[1].color
shirt[1].size

If we used that in a print statement or in any other way the result of shirt[1].color would be blue and shirt[1].size would be small. It isn't so bad, just try not to think about it too much!

Now, on to our program. First, we are going to create a table to store our enemy information. This will hold the health of the enemies and the type of enemy. This is the first line of code (FINALLY!) in our program, so put it in our new empty script.lua file. First line is the old faithful color object. Feel free to use any color besides green.

green = Color.new(0, 255, 0)
Enemy = { }
Enemy[1] = { type = "gargoyle", health = 100 }
Enemy[2] = { type = "vampire", health = 100 }
Enemy[3] = { type = "goomba", health = 100 }
Enemy[4] = { type = "ghost", health = 100 }
Enemy[5] = { type = "zombie", health = 100 }

There. Now we have 5 enemy elements created that tell what the enemy is and its total health at the moment. On to our two players. Add this code next.


Player = { }
Player[1] = { weapon = "sword", health = 100 }
Player[2] = { weapon = "knife", health = 100 }

There we now have all we need for our example program. Note that in a real game with movement, the Player table would be the perfect place to store the player's position on the screen, and the enemies as well in the Enemy table. This example will not be moving any characters around so we will get to that part when the time comes. What we are going to do is print the player and enemy's info to the screen, and take away the enemy's health if we press the X button. We are only going to use one enemy and player 1 for this. Poor Player 2 will have to sit on the bench until a later tutorial, as well as the other enemies, since we will only be using Enemy 1.
Next, we are going to jump right into our game loop. Let's put in our button setup code also, which you should remember. Now, put this code in next.


while true do
pad = Controls.read()

Now, let's add the clear command to clear the screen each loop.

sreen:clear()

Now, we're going to print our players health and weapon to the screen each loop.

screen:print(5,10,"Player 1 Health: " .. Player[1].health,green)
screen:print(5,20,"Player 1 Weapon: " .. Player[1].weapon,green)

In case you're lost, in our first print statement we are printing at X coordinate 5, which is 5 pixels from the left edge of the screen, and Y coordinate 10 which is 10 pixels from the top of the screen. The PSP screen is 480 pixels wide and 272 pixels in height. Then we have the string "Player 1 Health: " which will simply print that string to the screen. Then we concatenated (remember that?) our table element Player[1].health to that string so that it will print right beside it. Do you know what is stored in Player[1].health? You should! Lastly, we have our color which we've used several times before. The second statement uses the same method but prints different info about our character a little lower on the screen, under our first line.
Now on the other side of the screen let's print our enemy info. Put this code in.

screen:print(250,10,"Enemy Health: " .. Enemy[1].health,green)
screen:print(250,20,"Enemy Type: " .. Enemy[1].type,green)

Next, we are going to use the button input command that we learned to detect if we are pressing the X button, and if we are then we are going to subtract 5 points of health away from the enemy. Let's look at it. Add it in to your code.

if pad:cross() then
Enemy[1].health = Enemy[1].health - 5
end

This is saying that if X is pressed then take 5 points away from our Enemy[1].health element.

Finally, let's buffer, flip and end our loop. Add this code now.


screen.waitVblankStart()
screen.flip()
end


Now save it and run it to try it out, and then come right back here!
Whoa what was that! The enemy's health goes down WAY too fast, and it can go into the negative numbers! We can't use this in a game! This shows you just how fast a loop performs. We can fix this, by making the health only go down when we press X, and not while it's held down.

First of all near the top of your code before your tables add this line in. Under or above your color variable will do fine.


oldpad = Controls.read()

Now in the line that is "if pad:cross() then" change it to this:

if pad:cross() and oldpad:cross() ~= pad:cross() then

...and finally, right after your screen.flip() and before "end" add this line in:

oldpad = pad

I won't confuse you with details for now. Put simply this code makes sure you're not pushing the same button that you were the last time the loop performed, and if you are then our "if" statement will not perform. ~= means not equal to. We will learn about operators soon. Save it. Run it and test it.
Well all is fine except that it can still go negative. Speak of the devil. We are going to learn another operator here.




On our line that reads "if pad:cross() and oldpad:cross() ~= pad:cross() then" change it to this:

if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[1].health > 0 then

We added in Enemy[1].health > 0. > means greater than, which you may know already. So what this whole line is saying now is if the X button is pressed, AND we are not holding the same button as in the last loop, AND the enemy's health is greater than zero then (decrease health by 5). Note that ALL of these conditions have to be true in order for this to go through. Save it and run it, and now all should work fine. The enemy's health cannot go below zero.


Sony PSP Lua Programming: Expressions:
Expressions have been inching their way into our programs, so now we're going to go in to detail and learn about them. Some that we have seen so far are the "if" and ">" statements. In the end we will have a simple program to make use of these expressions. This program will be very much like our last program, except with more depth. Start up a new file, but don't add in the code unless you're told to, as in the last tutorial.

Putting Expressions To Use:
First we have the arithmetic expressions which are very simple. These are very simple so I won't detail these too much. We can add, subtract... etc with these. Here's an example.

x = 3 + 5 -- Addition
y = 3 - 1 -- Subtraction
a = 4 * 5 -- Multiplication
b = 10 / 2 -- Division
c = 2 ^ 8 -- Power of

Not so bad eh? Keep in mind the things I teach you in these tutorials are to get you going with the basics. I will not introduce every single possible command. As you learn how to use what I give you, you will be able to look up information and apply it on your own for the things I don't teach here.

Our next set of expressions will be the relational expressions. These will be highly used in your programming for comparing data. These return either true or false (known as boolean values). Let me list them for you.


== (Equal to)
~= (Not equal to)
< (Less than)
> (Greater than)
<= (Less than or equal to)
>= (Greater than or equal to)

We can use these to check for all kinds of useful information. For instance, if one of our enemy's health is zero, shouldn't he die? Or how about checking to see whether we have enough money to buy that new sword! Now, it would be kind of hard to use these completely by themselves. Most times they will be used with our next new set of expressions.

My favorite first, the "if" statement. This checks to see if some condition is true, and if it is then it will perform a section of code. We can also add to it so that if the condition is not true it will do something else. A simple "if" expression is written like this:


if <some condition> then
<perform some code>
end


Now a real world example. Let's say we have a program, and in that program we have two variables, myCash and itemCost. myCash is the amount of money we have and itemCost is the price of the item we want to buy. In a game we would have to check to see "if" we have enough money to buy this item. If we do then we will subtract the amount from our money and print a bought message to the screen. If we don't have enough then we will print a message to the screen saying there isn't enough money to buy it. It could look something like this.


myCash = 253
itemCost = 100

if myCash > itemCost then
myCash = myCash - itemCost
screen:print(100,100,"Item Bought",blue)
else
screen:print(100,100,"Not enough money",blue)
end


Let's analyze it. First, we have our variables which tell how much money we have, as well as how much the item cost.
Then, we have our if expression. This boils down to "if 253 > 100 then". It's asking if the value in variable myCash is greater than the value in the variable itemCost. If so ...
Then our next line will take the value of itemCost and subtract it from the value of myCash. in other words 253-100, and then store the answer in myCash. Then we print "Item Bought" to the screen with the next line.
On the next line we have "else" which is the part of the code that will perform in case myCash is NOT greater than itemCost, and if it isn't in this case it will print "Not enough money" to the screen.
Finally, always end the expression with "end".
In the above example, we do have enough money to buy the item. Therefore, the "else" section of code will not perform.
A lot of times you will not need to use else at all, and at times you may need more than one else. In this case you will use "elseif". Here's an example:


myNumber = 4

if myNumber == 1 then
screen:print(100,100,"Your lucky number is 1",blue)
elseif myNumber == 2 then
screen:print(100,100,"Your lucky number is 2",blue)
elseif myNumber == 3 then
screen:print(100,100,"Your lucky number is 3",blue)
else
screen:print(100,100,"Your number isn't very lucky!",blue)
end
This checks to see if myNumber is equal to 1, 2, or 3. If it is then it will print "Your lucky number is (number)". But if myNumber is not equal to 1, 2, or 3 then it will print "Your number isn't very lucky". Note that in this example this could be simplified down as small as our last example with only an else, and no elseifs by saying "if myNumber > 0 and myNumber < 4 then".
Coming up next we will learn about the "and" keyword and some others.

Logical operators can be used to compare more than one thing, as I mentioned above. We are going to learn two of these, "and" and "or". There is also a "not".

Let's say you are making a Role Playing game, maybe something like Diablo. The player of your game is about to try to equip a Dragon Slayer Sword. You want the player to have a level 20 chaacter, and also be a Warrior class character in order to let them equip this item.
At the top of our program we could have an array that holds the information, such as:


Player = { }
Player[1] = { level = 15, class = "warrior", weapon = "knife" }
Then later on our code to check if the player can equip this item could look like this:


if Player[1].level >= 20 and Player[1].class == "warrior" then
Player[1].weapon = "Dragon Slayer"
end
The first line checks to see if Player's level is greater than or equal to 20, and if the Player's class is the warrior class. If BOTH are true then Player's weapon will be set to the Dragon Slayer. If only one is true, this results to false, and therefore the weapon will not change. In this case our class is indeed the warrior's class, but as you can see our level is only 15, which is not greater than or equal to 20. Our player cannot use this weapon in the example. You are not restricted to use only one "and", for example you could use this in a program:



if hat == "blue" and shirt == "red" and age > 15 and state ~= "Florida" then
screen:print(100,100,"You are accepted!",yellow)
end
Using "or" is exactly the same except that only ONE condition has to be true in order for it to pass as true. For example:



myCar = "Mustang"

if myCar == "Corvette" or myCar == "Mustang" then
screen:print(10,20,"Nice car!",green)
end
In the example it checks to see if myCar is equal to Corvette or if myCar is equal to Mustang. If either one of these is true, then it will print "Nice Car!" to the screen. myCar is not equal to Corvette, but it is equal to Mustang, therefore this passes as true.

OK, now we're going to put this stuff in action. What we're going to do is take our program we made from the last tutorial and edit it with some things we have learned here. So open up your file if you still have it, and if not don't panic, you can download mine Here

In the last tutorial we made the enemy's health decrease by five points each time we pressed the X button. In this tutorial we are going to add some expressions to make the program bring up another enemy when the current one dies. We will also have to check for when there are no more enemies left.

The first thing we're going to do is add in a variable to tell us what the current enemy we're fighting is. We will assign a number to this variable. If you'll notice, in our Enemy array we have five enemies indexed by numbers 1 through 5. We will refer to those enemies with those numbers. Add this variable underneath the green color variable at the top of the code:




currentEnemy = 1
Now we are going to add some code to check if the current enemy's health is zero, and if so we will increase the currentEnemy variable by 1, but only if the currentEnemy number is not over 5, our last enemy. Above your if pad:cross() line add this code:



if Enemy[currentEnemy].health == 0 and currentEnemy <= 4 then
currentEnemy = currentEnemy + 1
end
Notice here we are using our currentEnemy variable instead of a number in our array Enemy array. This way we set the currentEnemy variable to the correct enemy, and anywhere in our code that uses the Enemy array, we can use currentEnemy instead of having to check for each individual enemy (Enemy[1] Enemy[2] etc...). This makes the code more automated. The currentEnemy variable will not go past 5 with the "<= 4" check. That being said, we have some lines we need to change in our code. Find these lines:


screen:print(250,10,"Enemy Health: " .. Enemy[1].health,green)
screen:print(250,20,"Enemy Type: " .. Enemy[1].type,green)
Change these lines to:


screen:print(250,10,"Enemy Health: " .. Enemy[currentEnemy].health,green)
screen:print(250,20,"Enemy Type: " .. Enemy[currentEnemy].type,green)

Now as the enemy changes, it will automatically print the health and enemy type of the correct enemy. We also need to change these two lines:



if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[1].health > 0 then
Enemy[1].health = Enemy[1].health - 5
Change them to:


if pad:cross() and oldpad:cross() ~= pad:cross() and Enemy[currentEnemy].health > 0 then
Enemy[currentEnemy].health = Enemy[currentEnemy].health - 5
To end it we are going to add a bit of code to print to the screen "All enemies are dead" if all five have been killed. Place this code in your main loop underneath the screen:print lines that print the enemy health and type.



if currentEnemy == 5 and Enemy[currentEnemy].health == 0 then
screen:print(50,100,"All enemies are dead",green)
end
This code says that if our current enemy is number 5 and it's health is equal to zero then print that all enemies are dead. Save your code and run it. Press X until one enemy dies. Then the next enemy will come up, followed by the next, until all 5 have been killed.

I hope this has helped you get a start on learning some expressions.


Sony PSP Lua Programming: Images:
So far all of our programs have been text only applications. I think by getting your feet wet with basic programming first it will make everything else a bit easier to take in. In this tutorial I will introduce using images, and some commands you can use for getting information about images.
As for what we are going to make? Well, we will make a program that will actually start to look like a game. It won't do anything flashy or exciting, but will serve the purpose of this tutorial, images. There are a lot more image commands available than the ones we will learn here. We will learn more of these in later tutorials. Feel free to look them up on your own in the luaplayer documentation.
Our finished product will include a moveable character that can move around the screen, but will not be able to walk past the edges of the screen.

Using Images In Lua:
The first thing you should do is save the images below to the folder you're working in. These pictures are just simple samples and it is very much OK to use your own. LuaPlayer can load PNG and JPEG images. For the most part, I would always use PNG over JPEG, especially when you need to use transparency. Now save these iamges:
Click Here To Download Images


Unzip those to the folder you're working in. You should have three images:
player.png
grass.png
flower.png
Now, once again, for the first part of the tutorial just follow along, and we will later start our code.
Loading Images:
In order to use an image in lua you must first load it into your program, into a variable (or table). You can do this at the beginning of your program, or later on depending on when the image is needed. We will pre-load our images near the top of the code when we start a bit later.
Here is an example of loading an image:


grass = Image.load("grass.png")

This will load the image file "grass.png" into the variable "grass". In order for this image to load it would have to be in our main project folder with our lua script file. If you had the image in a subfolder such as "Images" then you would use "Images/grass.png" instead of "grass.png".<br>
Be sure that you use the exact case in text as shown. Capitalize the "I" in image, and make the "l" in load lowercase. Very easy to load an image huh?!
Display Images:
To display an image to the screen really isn't any harder than loading one. Here's the full command:

screen:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])

There is a lot of information to fill in there! You will not always need all of those arguments, and you can completely omit the ones in square brackets if you don't need them. Now let's explain.
The code starts with screen:blit which is the command that says paste this image to the screen.
Now, inside the parentheses the fun begins.
x and y are the same as with the print command. This will be where on the screen the image will be pasted.
Image source will be the image to be pasted. For example, from above we loaded an image called grass, so we could use grass for our image source.
[sourcex, sourcey, width, height] is optional. This is used for loading a section of an image from a large image. A tilesheet is the perfect example. You may have a single image with several dozen tiles on it. With this code you paste one little section of that image. sourcex and sourcey are the x and y coordinates of the image where the section of the tile image starts. Not the whole image, but the smaller one inside the image.
width and height is the width and height of the piece of image you're taking from the main image. The last part of the command is the alpha argument. This is used to make transparency in images. True will make them transparent (which means the background will be see through with no color) and false will display the image as it is originally.
We will not be using all of these arguments in this tutorial.
Getting Image Size:
Getting the size of the images you have loaded can sometimes be very useful. There are two commands we can use for this, to get the width and height of an image. Here they are:

image:width()
image:height()

To use these you replace the word image with the image you want to get the width or height for. For example, to get the width and height of our grass image we would use:

grass:width()
grass:height()

Let's Make Something:
Let's go ahead and get started on our program.
The very first thing we're going to do is load our images into our program. Start up a new file and enter this code:


grass = Image.load("grass.png")
player = Image.load("player.png")
flower = Image.load("flower.png")
There. We have loaded our three images into our program.

Now, we're going to put those image size commands to use. Put in the following code, then I will explain. I'd also like to note that you will do yourself much more good actually typing code out instead of copying and pasting it. You will memorize the commands much better this way. Anyway, put this in:


screenwidth = 480 - player:width()
screenheight = 272 - player:width()
What point is this? Well, here's what we are using this for.
This bit of code will help us stop the player when it reaches the edge of the screen, when going left to right (horizontally).
We know that 480 is the width of the PSP's screen. But if we make the boundary of the screen at 480, then our character will go offscreen by 32 pixels, since our character is 32 pixels wide.
player:width() is the width of the player image, which is 32 pixels. This amount is subtracted from the screen width and height to stop the image at the edge of the screen.

Next, we are going to create a table to store our player character's information. The only information we will need for this example program will be the player's x and y position on the screen. Enter in this code:


Player = { }
Player[1] = { x = 200, y = 50 }
This will store our player's x and y position on the screen. We will start our player at x position 200, and y position 50.

Now, let's start our main loop. Enter this code:


while true do
pad = Controls.read()
screen:clear()
Now, in our next section of code I will introduce a new looping command. This is the "for" loop. Let me give you an example of this to show you how it works. Do NOT use this in your code. This sample could print 5 players weapons to the screen by using only one small loop.


for a = 1,5 do
screen:print(10, 10, Player[a].weapon, green)
end

To use the for loop you will give a temporary variable a starting value and an ending value.
In the above we said "for a = 1,5 do"
This is creating a loop that will give the variable "a" a starting value of 1, and an ending value of 5. You can think of this line as saying "a is equal to 1 through 5".
Then inside the loop we are printing the player's weapon to the screen.
The last line has the "end" statement which must be used to end a loop.
Now, this loop will repeat over and over until the ending value of "a" is met, and then the loop will terminate. The first time the loop performs "a" will equal 1. The next time "a" will be 2, then 3, then 4, and finally 5. This would quickly print the weapons of players 1 through 5 to the screen. Although, to really do this you would need to change the screen coordinates of the print command so that it doesn't all print in one spot. But this shows the use of the command. You are also free to use "if" statements within the "for" loops if needed.

We will use this method to tile our grass image across the entire screen. Put in the code below and I will explain. Also, keep in mind that to make a more complex game with scrolling and such, using a tile engine will be a much better approach, but for now we don't need it.


for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end

This has a "for" loop within another "for" loop! This will paste the grass image across the entire screen. It will paste 15 images horizontally and 9 images vertically. Notice we start with zero instead of 1 so that the images get pasted at the very left edge of the screen.
Now, let's paste a few more images.


screen:blit(100,100,flower)
screen:blit(300,220,flower)
screen:blit(Player[1].x,Player[1].y,player)

This will simply paste two of the flower images to the screen, as well as our player. Shortly, when we use our movement keys we will change the player's coordinates in each loop if we're pressing the button. Using the above blit command our player's image will get automatically pasted to the correct area of the screen.

Now, let's add in those keys to detect if we're pressing the directional keys. Enter this code:


if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end

if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end

if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end

if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end

These codes will check to see if we're pressing up, down, left or right. Using the "and" statement we will also check to make sure we our not leaving the boundary of the screen. Since the very left of the screen and the very top of the screen is at the coordinate zero, we can simply see if our position is greater than zero.
For the others we use screenwidth for going right and screenheight for going down. We set up these variables earlier. If our position passes the "if" test then our player's x or y coordinates will be added or subtracted by 2. Each time the main loop runs it will paste our player image to the new position given to it.
Finally, let's end our loop. Use this code:


screen.waitVblankStart()
screen.flip()
end
Save your work and run it. Use the directional keys to move across the screen. You should not be allowed to go past the edge of the screen. Here's an image below of what you should see if all went well.
Image



Sony PSP Lua Programming: Functions
In this tutorial we are going to learn how to use functions. Creating a function is kind of like creating your own new command for lua. You can use functions for repeating sections of code, and call the function for use at any time. Functions are placed outside of your main loop. A good place for them is at the top of your code around your variable declarations.

Using Functions:
First, let's look at how a function is declared. Examine the code below:

function functionName()
(code to perform in function.
Multiple lines of code may be used.)
end

Now that you've seen how a function is created, let's look at an example function that will print a simple message to the screen each time it is called. Have a look!

function printMessage()
screen:print(100,100, "Functions are fun!")
end

Now, in order to print this message in a program we will have to make a call to the function, where ever we want to use it. For the above example using the following code will call the function and perform the code inside the function one time.

printMessage()

That's it!? Ummm.. yeah I'm afraid so! Using the code above will perform the code in the function we created earlier. "Functions are fun!" will print to the screen by calling printMessage().
As you start creating more complex programs or games you will want to use functions a lot. Using these functions calls inside your main loop instead of the actual code will extremely clean up the look of your code. Earlier I said functions are placed outside of your main loop, which is true. But, you are welcome to call them from within your main loop.

Functions may also be created to return a value. This is done by creating arguments in the parentheses of the function when creating it. Let's say for the fun of it we want to create a function that will add two numbers and return the result back to us. First we have to create the function. Look below:


function additUp(a, b)
sum = a + b
return sum
end

Notice this time inside the parentheses we placed the letters "a" and "b". These can be any letters or even words. They are variables to use inside this function, and they only exist inside the function. Since we are going to be adding two numbers we needed two variables to store them in. You may use more or less variables in your functions as long as you separate each with a comma.
Next inside the function we created a variable called "sum" and it will get assigned the value of the variables "a" and "b" added together. This will be clearer once you see how it is called.
Next, we have a command called return. This tells the function that we are returning a value from this function once we exit it. The value we are returning is the value of the variable "sum".
Finally, we end our function.
Now, let's examine how we could use this and explain a bit more. Look at this code:


screen:print(100,100,additUp(5,6), green)

This will print the result of our function to the screen. Notice we use actual numbers when calling the function. We used 5 and 6 for this example. This assigned the value 5 to "a" and the value 6 to "b". Now inside our function declaration that we made earlier, anytime "a" or "b" are used, those variables will be replaced by the numbers we have inserted. So in our function where is says "sum = a + b", it now resolves to "sum = 5 + 6". This will assign the value of 11 to the "sum" variable and then return it to our print command, printing it to the screen.
We could also store the information in a variable if needed. This way we wouldn't have to use it right away if we didn't need it at that moment, or could reuse it over and over without having to recalculate the whole function. Look below:


myTotal = additUp(5,6)

This will store the returned value of our function into the variable myTotal. myTotal will equal 11.
Let's look at the program we made in the last tutorial. It looked something like this:


grass = Image.load("grass.png")
player = Image.load("player.png")
flower = Image.load("flower.png")

screenwidth = 480 - player:width()
screenheight = 272 - player:width()

Player = { }
Player[1] = { x = 200, y = 50 }

while true do
pad = Controls.read()
screen:clear()

for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end

screen:blit(100,100,flower)
screen:blit(300,220,flower)

screen:blit(Player[1].x,Player[1].y,player)

if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end

if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end

if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end

if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end

screen.waitVblankStart()
screen.flip()
end

We could make some functions to clean up our main loop, in order to see what goes on more clearly. We could put all of the directional checks inside a function. We could also put the screen blitting into a function. Neither of these will require a return value. Look at the code below to see how you could use functions in this:

grass = Image.load("grass.png")
player = Image.load("player.png")
flower = Image.load("flower.png")

screenwidth = 480 - player:width()
screenheight = 272 - player:width()

Player = { }
Player[1] = { x = 200, y = 50 }

-- Function to check player movements
function playerMovement()
pad = Controls.read()
if pad:left() and Player[1].x > 0 then
Player[1].x = Player[1].x - 2
end

if pad:right() and Player[1].x < screenwidth then
Player[1].x = Player[1].x + 2
end

if pad:up() and Player[1].y > 0 then
Player[1].y = Player[1].y - 2
end

if pad:down() and Player[1].y < screenheight then
Player[1].y = Player[1].y + 2
end
end

-- Function to paste images to screen
function pasteImages()
for a = 0, 14 do
for b = 0,8 do
screen:blit(32 * a, 32 * b, grass)
end
end

screen:blit(100,100,flower)
screen:blit(300,220,flower)

screen:blit(Player[1].x,Player[1].y,player)
end

-- Main Loop
while true do

screen:clear()

pasteImages()

playerMovement()

screen.waitVblankStart()
screen.flip()
end

By looking at this, you can see that our main loop has been cleaned up big time. All of the complicated detailed code is kept inside the function, and in our main loop we simply call it. You can also simply read the code straight down in your main loop and see what is going on. All of the cluttered mess within the loop from the previous code is gone, and moved to the top of our code.



Sony PSP Lua Programming: Reading and Writing of Files:
In this lesson we are going to learn how to read from files, as well as write to files. This can be very handy in making games. You can use this to pull chunks of code from other files, as well as save information to files such as high scores, game saves, player stats etc...
Let's get started!

Uses of Reading and Writing Files:
First, let's look at a very simple command called dofile.

This command will read code from another file and immediately execute it.

dofile("./test.lua")

The command is as simple as that. Note that the ./ does not mean the file is in a subdirectory. If the file was, we would use this:

dofile("./files/test.lua")

So, if our file test.lua contained this code:


playerx = 10
playery = 20
enemyx = 40
enemyy = 50


...then as soon as we called that file with the dofile command, those variables would get declared. You do not have to use lua files. txt files or any other are fine.

Reading A Single Line From a File:

Let's say you have a file that has multiple lines of text, and you want to read one line of text from that file, and print it to the screen.
For this we can use the io.open() command to open the file, then read from it.
This command has the syntax of io.open(filename, mode).
The mode we will use for this will be r, for read mode.
For reference here is a list of all modes available.

r - read mode
w - write mode (overwrites existing)
a - append mode (appends to existing)
b - binary mode
r+ - update mode (existing data preserved)
w+ - update mode (existing data erased)
a+ - append update mode (existing data preserved, append at end of file only)
The first thing we will do is open the file and store it in a variable. Look below.


file = io.open("testRead.txt", "r")



Now our file testRead.txt has been opened, and is ready for read mode.
Next, we will use the read() command to read a single line from the file into another variable.


ourline = file:read()
This will read the first line of our text file. The next time we use the read() command it will read the second line. Next, it would read the third line, and so on.
Notice that we use the name of our variable that our file is opened with along with this command.
There are also some arguments you can use with file.read().
You can put any of the below arguments inside the parentheses with quotation marks.

*n - reads a number and returns it. ex: file.read("*n")
*a - reads the entire file from the current position. ex: file.read("*a")
*l - (default) - reads the next line, returns nil on End of File (EOF). ex: file.read("*l")
number - returns a string with up to that many characters in it, or nil on EOF. ex: file.read(5)
Now that we've read our line, we need to close the file we opened, like so:


file:close()
Now, to print our file to the screen we would simply use this:


screen:print(10,10,ourline,white)
Reading All Lines:

To read all the lines in a file you could use the same technique with a for statement.
Look at the code below.


y = 10

file = io.open("testRead.txt","r")

for line in file:lines() do
y = y + 10
screen:print(100,y,line,white)
end

file:close()
This code sets up a starting y value to use for the printing, so that it will print each line at a different y on the screen.
We open our file the exact same way.
Then we come to the for statement. This line is saying for how ever many lines are in the file, do the following code. Our y gets added by 10 for each loop and is used in the printing command to print it below the next line.

Writing To Files (Overwrite):

Writing to files is done about the same way. Our first method here will overwrite anything previously written in that file. Here's the code:


file = io.open("testRead.txt","w")
file:write("hello")
file:close()

This time notice we used the w mode instead of r since we're writing, and not reading.
We use file:write() with the text we want written to the file in parentheses and quotes. You could also use a variable instead. If you use a variable do not use quotation marks. Here's an example.


file = io.open("testRead.txt","w")
myText = "Hello"
file:write(myText)
file:close()
Writing To Files (Append):

You can use append mode so that when you write text to a file it gets added to the bottom of the text that is already in that file, instead of deleting it all. This is done exactly the same as the above except that we use a mode, for append. Look below.


file = io.open("testRead.txt","a")
myText = "\nHello"
file:write(myText)
file:close()
Notice something else different? In the myText variable we added in \n inside the text string.
This command is a line break, and will cause the text to go to the next line when written to our file. It may show up in your file on the same line with a little square in between it, but technically it is a new line. This exact command is also used in C/C++.

Take what you've learned here and try to use it in a small program.
Our next tutorial we cover using sound, and will use the reading and writing commands we have learned here to make a small program.

Sony PSP Lua Programming: Sound and Music:
Now, it's time to add some sound to our projects. Every game needs sound, and here we will tackle just how to do it in luaplayer.

Let's get started!Applying Soundluaplayer can play the the following formats: UNI, IT, XM, S3M, MOD, MTM, STM, DSM, MED, FAR, ULT or 669 for music. WAV files can be used for sound.It is possible to convert MIDI files into the above mentioned formats.One program that can do this is Modplug Tracker. Also, keep in mind that luaplayer DOES NOT support mp3 files.
After we learn a few sound commands we will apply these with some things we learned previously to create a small program.

Let's take a look at our first command. This command will play a music file.

Music.playFile( string file, bool loop )

Now, where "string file" is you will use the name of your music file, such as "song.xm".
"bool loop" is where you will either put true or false. true will loop the song over and over, and false will only play through the song once. Here's an example of playing a song.

Music.playFile("mysong.mod", true)

Now, have a look at these commands. The following can be used after you have starting playing your music file.

Music.pause()
Music.stop()
Music.resume()

These are pretty much self explanatory.
Music.pause() will pause your song.
Music.stop() will stop your song.
Music.resume will resume your song if you have temporarily stopped it.

There is also a command we can use to test whether a song is playing or not. This will return either true or false. Take a look:


Music.playing()

Say we wanted to test if our song is playing, and if it is then print a message to the screen. We could do..


if Music.playing() == true then
screen:print(10,10,"Music is playing",white)
end

There's also a command to set the volume of the music file. In the parentheses simply place a number from 0 to 128. Here's the command.

Music.volume(Number)

Now, let's learn a bit about sound files for sound effects, particularly wav files. These are done slightly different than playing music files. Here's how to load a sound.

bonkSound = Sound.load("bonk.wav",false)

The wav file is loaded into a variable and later we use the variable to refer to the sound. We used false here so that it will not loop over and over. Remember using true will make it loop, if that's what you need.
Something very important about WAV files in luaplayer is that they must be mono and not stereo. You can check this by right clicking on the file and go to properties and then summary to see.

Let's learn a few more commands now. The next command will play the file. Use the name of the variable you used to load your sound. Like this:

bonkSound:play()

I do not recommend using this way to play the file however. This can lead to a common error which will mention something along the lines of "loop ingettable". Here's how I would play my file. The only thing you would need to change from this code is the bonkSound if you used a different variable.

local sound = bonkSound
voice = sound:play()

To stop the sound use:

voice:stop()

We can also use a command as we did with the music commands to see if the sound is playing. This command is:

voice:playing()

There are other sound and music commands for you to discover out there, but these are good enough to get you using sounds and music.

Let's Make Something:

Now, we are going to create a little program. This will start us off in a menu screen where we will be able to select a blue or black background. When X is pressed the program will move on to the next part with the background colored as we chose. In this part of the program it will display how many times the program has been executed. How? Well, each time we press X in the menu screen it will open up a file that we will create shortly, and write a number to the file. The program also reads the number from the file and stores it into a variable. If you completely exit the program and return to it later, it still will show how many times it has been ran, since it is stored in a file. So let's get busy.

First, I want you to create a normal txt file with notepad or whatever you may use. Inside the text file type in the number 0. Inside your file should look like this:

0

Save this file as counter.txt, just a normal text file.

Let's start our lua file now. First we will create a few color objects for us to use.

white = Color.new(255,255,255)
blue = Color.new(0,0,255)
black = Color.new(0,0,0)

Next, a few variables.

oldpad = Controls.read()
startcolor = black
gamestate = "menu"

oldpad will store the last button we pressed.
startcolor stores the color that we will use to start the second half of the program later on. We start with black.
gamestate is what we will use to see which function to use. We will make two functions. One will run the menu, and the other will run the rest of our program. Since we start at the menu that's our starting value for the variable.

Our next part deals wit
<<

Surenix

Brew Guru
Brew Guru

Posts: 2923

Joined: July 01 2005

Location: Canada

Thanks given: 0

Thanks received: 0

Post Fri Apr 21, 2006 7:05 pm

Wow... big tutorial, thanks a lot bro.
<<

bronxbomber92

Experienced Brewer
Experienced Brewer

Posts: 105

Joined: February 19 2006

Location: middle of nowhere, New York

Thanks given: 0

Thanks received: 0

Post Fri Apr 21, 2006 7:28 pm

dude these r the tuts i showed you! wheres the credit???? these tuts were made by pspmillionare from pspupdates! i have to give credit where credit id due! but not bad for postig thme here.
Image
Image

Image
<<

jtwright

User avatar

Brewery Master
Brewery Master

Posts: 1189

Joined: January 06 2006

Location: In the realms of hell <:OD

Thanks given: 0

Thanks received: 0

Post Fri Apr 21, 2006 7:36 pm

i knew i for got something :oops: credit gose to pspmillionair
<<

Mailas

Post Mon Apr 24, 2006 7:32 pm

Anyways how do you test run it on your PC?
I tried to test run mine but it wont run on my pc. I saved it as script.cmd and it didnt run! I saved it as script.lua and it didn't run!
How do I test run it on my PC?
<<

bronxbomber92

Experienced Brewer
Experienced Brewer

Posts: 105

Joined: February 19 2006

Location: middle of nowhere, New York

Thanks given: 0

Thanks received: 0

Post Tue Apr 25, 2006 1:40 pm

MailasG wrote:Anyways how do you test run it on your PC?
I tried to test run mine but it wont run on my pc. I saved it as script.cmd and it didnt run! I saved it as script.lua and it didn't run!
How do I test run it on my PC?
lol, u create a blamk file then name it script.cmd, then u open a new file and start coding it and save that as script.lua. so when u wanna test ur game or watever u put the script.cmd in the luplaey folder and the script.lua in the luaplayer folder. then double click script.cmd and that should read ur game/app :D hope that helped!
Image
Image

Image
<<

Mailas

Post Tue Apr 25, 2006 3:24 pm

Yea haha I figured it out before you posted but atleast SOMEONE had the courage to answer it.
Thanks anyways.

EDIT:
Hey I got another question. How would you go on doing something like if you press the a button on the keyboard of your computer, the variable: ship1 goes left. And if you press the space button, it shoots a variable called bullet going in a directio of left.
How would you put this in lua code? What direction would both the ship1 variable and bullet variable go if you press a for the ship, and space for the bullet?
<<

bronxbomber92

Experienced Brewer
Experienced Brewer

Posts: 105

Joined: February 19 2006

Location: middle of nowhere, New York

Thanks given: 0

Thanks received: 0

Post Tue Apr 25, 2006 4:18 pm

MailasG wrote:Yea haha I figured it out before you posted but atleast SOMEONE had the courage to answer it.
Thanks anyways.

EDIT:
Hey I got another question. How would you go on doing something like if you press the a button on the keyboard of your computer, the variable: ship1 goes left. And if you press the space button, it shoots a variable called bullet going in a directio of left.
How would you put this in lua code? What direction would both the ship1 variable and bullet variable go if you press a for the ship, and space for the bullet?
i'm not exactly sure but it would be sumtin like like...
if pad:a()then
<code telling shipOne varaible to go left>
end

thats how i think it would be setup, the exact code i dont know... try going to evilmana.com and going to tuts, then code snippets and that should help ya ;)
Image
Image

Image
<<

.Vault

User avatar

Brew Guru
Brew Guru

Posts: 3693

Joined: September 02 2005

Location: NJ

Thanks given: 0

Thanks received: 2 times

Post Tue Apr 25, 2006 4:20 pm

jtwright... what do u do when you are not writing tutorials?

Return to PSP Tutorials

Who is online

Users browsing this forum: No registered users and 9 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for blacklist.org.