PSP-Heaven Forum Index  
 FAQ  •  Search  •  Memberlist  •  Usergroups   •   fChat   •  Register  •  Profile  •  Log in to check your private messages  •  Log in
 Lua - Hello World! tutorial View next topic
View previous topic
Post new topicReply to topic
Author Message
Metal_kid
Is your Master


Joined: 15 Jul 2006
Posts: 26
Location: Phish Bowl

PostPosted: Tue Aug 01, 2006 10:47 pm Reply with quoteBack to top

Ive just finshed writign this tutuorial Tell me what you think if it need's improvments or if its fine the way it is. then ill put some finishing touches on it


Lua Coding

Ok, this tutorial will hopefully be simple and easy to follow. There is no point is having a tutorial if no one can follow it, now is there?

To get started you will need to get your hands on a copy of luaplayer for the PSP. This can be found at http://www.luaplayer.org and follow the direction there, for users on 2.1+ using GTA to load homebrew then go here and download it http://forums.qj.net/showthread.php?t=53524 . Once you have done this and made sure it’s working then continue on with this tutorial. One thing to note about Lua is that it is sensitive to capitals so be careful!

Your first hello world Script


First all you want to set your variables first, so what we are going to do now is make the colour white. Now, in your text editor (notepad is good for this) type the following and Notice the Capital:

Code:
White = Color.new(255, 255, 255)



If you wanted black you would put down Color.new(0, 0, 0). The Color.new( R, G, B) command works like this. It accepts 3 Attributes and they are the RGB values. Where R stands for red and G stands for green and (have you guessed it?) B stands for blue. Each of the values can go as high as 255 the reasons for this you don’t need to know, just don’t go over 255.

There is a command that has to go in before we do anything else I wont explain what it does as it is pretty much self explanatory. So here it is put his into your code:

Code:
screen:clear()



We are now going to print some text to the off-screen buffer using this command: Where is the X coordinate of where you want your text to start and Y is the Y coordinate of where you want your text to start. The text you want printed to the screen goes within the quotation marks. And do you remember that color we set earlier in this tutorial? Well, this is where we use it. To use it you would type the exactly what you typed for the variable. So if you used Pinky-Blue above then you couldn’t type pinky-blue it would have to be Pinky-Blue. But in this tutorial we used the White variable.

screen:print(X, Y, “your text here”, color)


So now were are actually going to use this command and do something with it we will start by typing:

Code:
screen:print(10, 10, “Hello, World!”, White)



As mention before this has only been printed to the off-screen buffer and we need to “flip” it onto the screen and to do this we use this command:

Code:
Screen.flip()


And because this is a script it will loop until it reaches the end of the script so get this onto the screen for more than fraction of a second we have to tell this too loop through the script over and over. We do this by using this set of commands

while true do
screen.waitVblankStart(A)
end


A is the number of milliseconds it will loop fore before ending the script to get it too loop an infinite amount of time we leave this set to nothing but for instance say you wanted to it too loop for three seconds you would want to put a value of 180 ( 3 x 60 = 180 because there is 60 milliseconds in a second it’s 3 seconds times by 60 which give us the desired value of 180)
If your still following along then I would like you too put this in at the end of your script:


Code:
while true do
screen.waitVblankStart()
end


Ok so that’s you just finished your first program written in lua so what you now need to do is to is to save it. You will want to save it as Helloworld.lua and (assuming your using Notepad do the following) Click File then go to “Save As…” when the window appears in the Filename box put in Helloworld.lua and also in the save as type box change that to All files and click save. You have now been left with your lua script to actually run this plug your psp in to your computer via USB and then navigate to Ms0:PSPGAMELuaPlayerApplications and copy your lua file here.

Fire up your psp and run Lua Player by going to Game then Memory Stick and navigating to Lua Player. Once this has loaded Go down until you see your script(Helloworld.lua) and press “O” If you have successfully Done everything correctly you should now have the worlds “hello, World!” printed onto your screen!( to get out of this you must restart your psp to get out by pressing a button will be coverd in the next tutorial)

Now wasn’t that easy?


thanks guys!

Next tutorial will be Graphics and Buttons
View user's profileSend private messageMSN Messenger
D.T. Jesus
Senior Member


Joined: 18 Jun 2006
Posts: 3
Location: The City Beneath The Surface

PostPosted: Fri Aug 04, 2006 5:48 pm Reply with quoteBack to top

good job! keep it up Very Happy Very Happy
View user's profileSend private message
Display posts from previous:      
Post new topicReply to topic


 Jump to:   



View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum