Team XSaturn's Forum Site
 
HomeHome  ­GalleryGallery  ­FAQFAQ  ­SearchSearch  ­MemberlistMemberlist  ­UsergroupsUsergroups  ­RegisterRegister  ­Log inLog in  
Post new topic   Reply to topicShare | 
 

 Lua tutorial 2

View previous topic View next topic Go down 
AuthorMessage
PSProgramer
Admin


Posts: 19
Join date: 2008-07-16

PostSubject: Lua tutorial 2   Mon Aug 25, 2008 11:53 pm

Please make sure you have gone through lua tutorial 1 before begining this tutorial. You can find it in these same forums.

Your first Program

Alright open up your favorite text editor, to start coding. First thing you want to do is make a comment stating what the program is for. Comments are text that you put in, that lua won't read. It's really good for labeling you scripts, and dividing it up, to make it easier to read. To make a comment add -- before a line, like this:
Code:
-- This is a comment, anything on this line will not be read by lua.

a comment will one work for that single line. So at the top of your script put:
Code:
--Hello World Script
--your name

You can have as many comments as you like, and are great for organizing code, and for others who look at your code. Next thing you want to add in your script are colors. Colors are mostly used for printing text, and creating images. For now we will just be using it for text. So to add a color add this line to your script:
Code:
white = Color.new(255,255,255)

Make sure you capitalize Color, as lua will not read it correctly, because lua is case sensitive. now the numbers, are needed to define the color, as lua uses RGB coloring. What RGB coloring is, is the creation of a color or shade using a certain amount of the colors, Red, Green, and Blue. So to create different colors you would change those numbers, for example black = Color.new(0,0,0). Ok. once you define the colors we want. Then we are going to want to start the acctual coding. So next type in:
Code:
while true do

what this does is start the action part of the code. Lua will now follow any commands after this line. This is required in most scripts, and will be required in all of the scripts that we will be making in this tutorial series. Next you are going to put:
Code:
screen:clear()

what this does, is clear the screen to black. This isn't always required, but should be put in for this script. ok, now we want to put our text on the screen. To do that, type in:
Code:
screen:print(10,20,"Hello World", white)

Alright, I'll go through this peice by peice. the screen:print is the command used to print any text on the screen. after that we have the number's 10, and 20. what those are, are the x and y on the screen where you will print your text. so if you changed those to 240, 135, then it would print in the center of the screen. Right now they will print in the top left corner. Ok, now you have the "Hello World" part. This is just telling lua what you want to print to the screen. This could be anything you want, but make sure you have quotation marks around it. lastly you have the word white, just tells lua what color the text should be, this is why we added the Color up above. Ok, now we need to close the program. So type:
Code:
screen.flip()

all this does, is flip the screen over, so we can see our text on the screen. this is needed in all lua scripts. then type:
Code:
screen.waitVblankStart()

This makes it so the script won't just open then close extremly fast. And then lastly type:
Code:
end

this ends you script, and lua will not read anything beyond this point. There you go, you have completed your first program, save it as hello.lua, and run it in luaplayer windows, or luaplayer psp. And it will run. I hope you enjoy. Check in next time for tutorials, on tables, and variables.

_________________
Back to top Go down
View user profile http://teamxsaturn.forumotion.net
 

Lua tutorial 2

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
Team XSaturn :: Tutorials :: Tutorials-
Post new topic   Reply to topic