Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomePortalRegisterLatest imagesSearchLog in

 

 [Lua] Hello World Tutorial

Go down 
AuthorMessage
CarBoyCam
Admin
CarBoyCam


Number of posts : 32
Age : 32
Location : Suffolk, UK PSN ID: CarBoyCam
Registration date : 2007-12-09

[Lua] Hello World Tutorial Empty
PostSubject: [Lua] Hello World Tutorial   [Lua] Hello World Tutorial Icon_minitimeTue Dec 11, 2007 11:40 am

Here is the first Tutorial for Lua. This will help you print text and define colours in a simple Lua script.

First of all, I recommend Downloading the Lua DevKit R2 Final Beta. Once it's installed, create a new file. (Or if you haven't installed it, create a new .txt file in notepad).

To title up your Lua script, you would do the following:

Code:
-- Hello World coded in Lua for PSP
-- Created by *Your Name Here*
-- Created on *Insert Date Here*

The "--" tells the Lua PSP that the words following it, on the same line, are comments. ie. They are not code and should not be executed. In other words, they're ignored. You can use these to add helpful tips anywhere in your code.

Now we move onto the colours. We need to define colours for the PSP to use later on. Doing this will become second nature as you become more familiar with Lua. I will now define the colours White, Red and Blue:

Code:
-- Colours
white = Color.new(255,255,255)
red = Color.new(255,0,0)
blue = Color.new(0,0,255)
-- End of Colours

The part of the code before the "=" is the name of the colour. This can be pretty much anything you want. The "Color.new" bit tells the PSP that a new colour is being defined. Then the bit inside the brackets is the RGB (RedGreenBlue) values. (R,G,B). The numbers vary from 0 to 255, where 255 is the Maximum and 0 is the Minimum.

Next up, we are going to print text on the screen. Again, this is quite simple. Below is the code for printing "Hello World" on the screen:

Code:
while true do

screen:print(100,100,"Hello World",red)
screen.flip()
screen.waitVblankStart()

end

screen:print tells the PSP that some text is going to be printed onto the screen. The "100,100" is the X (Horizontal) Position and Y (Vertical) Positions of the text. (The PSP's screen is 480x272 by the way). The bit following that (in speech marks) is the text which is being printed. Then the bit after that is the colour. (Name of the chosen colour you define earlier).

"screen.flip()" displays the text on the screen, for you to see. Without that, you would see nothing! The "screen.waitVblankStart()" tells the PSP to Pause and do nothing. If that wasn't in there, you text would only appear for a split second.

The "while true do" starts your Main Loop, and "end" ends it. Your code will go between them.


Once you have done, save it as "index.lua", and run it with LuaPlayer for PSP.

I hope you have found this useful. Please tell me if there are any errors in the code.
Back to top Go down
http://teamue.cyberspeed.org/
 
[Lua] Hello World Tutorial
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
 :: PSP Programming Section :: Programming Tutorials-
Jump to: