Help the PSP 3D community grow! Vote for us below:


| | Getting Started/Help/Tutorials - Just bought your PSP and need some basic help using it or loading homebrew? |
Welcome to PSP3D.com - Sony PlayStation Portable News, Homebrew, Hacks, Reviews, Videos, Mods, Forums!
You are currently viewing our website as a guest, which gives you limited access to reply and interact to discussions and other members. By joining our free community, you will be able to post topics in the forums, communicate privately with other members, vote in polls, and access many other special features.
Registration is fast, simple, and absolutely free so join our community today!
|  | | 
08-11-2006, 09:27 AM
| | Senior Member | | Join Date: Mar 2006 Location: Portugal Age: 19
Posts: 359
Points: 4.73 Donate | | | [TUTORIAL] LUA: The Begginer Lesson I decided to make this tutorial because there is no tutorials in PSP3D about LUA coding and i don't have nothing to do right now....and i dont like PSP-PROGRAMMING one's.
In this tutorial you will learn some LUA basic functions like:
- Comments;
- Colors;
- Some Screen options (print text, blit an image);
- Usage of the PSP controls.
First open an new file on notepad and save it as index.lua in an new folder, then download an image, get it here and put the image in the same folder as the index.lua. To start coding you should put some information about your demo in the code: Quote:
-- My first LUA App
-- by (enter your name here)
-- in (enter the date here)
-- Tutorial by Rikardo_92
| You may have observated that the two -- are used to write comments, in that way the LUA player will ignore those lines of code. Now we are going to define the colors: Quote:
white = Color.new(255, 255, 255)
green = Color.new(0, 255, 0)
| Look at this part of the code...as you can see the word's white and green are variables and we assign some functions to those variables in order to makes the code easyer to wrote.
Now the Color.new(255, 255, 255), you always need to use this and about the numbers, i suggest that you use Paint to find what colors you want, this is the RGB (Red, Green, Blue). You will need to use the image later so you need to load it: Quote: |
psp3d = Image.load("3d.png")
| To the code work we need to have an main loop: Well this is a bit confuse for LUA begginers so i will not explain in the future you will learn more about the main loop, just add this for now. To use the controls later we should active they first: We are assigning pad as Controls.read(), so pad is a variable. Now you will print something to the screen! Quote:
screen rint(185, 135, "YAY! This really works", green)
| Now look at the code, i will explain...you always need to use screen rint to wrote to the screen. Now the 185, 135 are the coordinates that the text will be displayed, now the other follow stuff is the text (you always need to put some "" and the last wrod, green is the variable that we assigned before as the color green. The follow part will show you how to blit an image to the screen, if you didn't get the image, you can get it here
Now add this line to your code: Im going to explain this, first screen:blit is what you do to the screen, "0, 0" are the coordinates where the image will be displayed and psp3d is the variable that we assign before as the image. Remember when we active the controls earlier? Well right now we are going to use them. Quote:
if pad:cross() then
screen rint(80, 262, "Tutorial by rikardo_92, credits to PSP3D", white)
end
| Now the explanation, if pad:cross() means if the X button is pressed then do the function assigned, screen rint(80, 262, "Tutorial by rikardo_92, credits to PSP3D", white) is our assigned function and we always need end to finish the controls usage. And add this to your code: Quote:
if pad:start() then
break
end
| This means that if START button is pressed then it closes the app (the break function). Now to finish your app, you will need some functions: Quote:
screen.waitVblankStart()
screen.flip()
end
| The screen.waitVblankStart() is used to make that your stuff printed on the screen keep there and not goes, screen.flip() is an weird function, because is used to change the stuff to print from the offscreen buffer to the onscreen buffer and the end closes the our main loop, the while true do.
You just finished your first LUA app, i hope this tutorial helps a lot of people  , now is your code should looks like: Quote:
-- My first LUA App
-- by (enter your name here)
-- in (enter the date here)
-- Tutorial by Rikardo_92
white = Color.new(255, 255, 255)
green = Color.new(0, 255, 0)
psp3d = Image.load("3d.png")
while true do
pad = Controls.read()
screen rint(185, 135, "YAY! This really works", green)
screen:blit(0, 0, psp3d)
if pad:cross() then
screen rint(80, 262, "Tutorial by rikardo_92, credits to PSP3D", white)
end
if pad:start() then
break
end
screen.waitVblankStart()
screen.flip()
end
| To test it, download the latest PSP LUA Player, here.
or the latest Windows LUA Player, here.
Download the index file here.
EDIT: Sorry about the  when this is showed change to screen:*print (in place of the * is a p)
EDIT 2: I wroted this code with my mind and in 10 minutes so i don't tested it....but when i was testing earlier ago i found some problems...but now fixed 
Last edited by rikardo_92 : 08-11-2006 at 11:04 AM.
| 
08-11-2006, 09:36 AM
| | Senior Member
My Mood: | | Join Date: Aug 2006 Age: 19
Posts: 108
Points: 55.39 Donate | | | Good Tutorial!! i´m will try this right now!! | 
08-11-2006, 10:07 AM
| | Senior Member | | Join Date: Dec 2005
Posts: 526
Points: 9.86 Donate | | | i tried this and it didnt work so i copied the end thing you sed it shud look like and i got "error: index.lua:14: attempt to call global 'screenprint' (a nil value)
Error: no script file found."
EDIT: yes, i did change the smile thing to : p (no space)
__________________ SEE IF YOU CAN GET YOUR NAME NOTICED HERE!!!!
Last edited by Drakhra : 08-11-2006 at 10:11 AM.
| 
08-11-2006, 10:17 AM
| | Senior Member | | Join Date: Mar 2006 Location: Portugal Age: 19
Posts: 359
Points: 4.73 Donate | | | if this get this error: "error: index.lua:14: attempt to call global 'screenprint' (a nil value)
Error: no script file found."
this means that this is wrong....you should write screen.print in place of the . put an : | 
08-11-2006, 10:18 AM
| | Is Da Best PSP3D Member
My Mood: | | Join Date: Dec 2005 Location: England
Posts: 649
Points: 4.58 Donate | | | I dont know if it was becuase ive allready know basic lua but i found that so easy! | 
08-11-2006, 10:21 AM
| | Senior Member | | Join Date: Mar 2006 Location: Portugal Age: 19
Posts: 359
Points: 4.73 Donate | | | yep...lua is easy | 
08-11-2006, 10:22 AM
| | Senior Member | | Join Date: Dec 2005
Posts: 526
Points: 9.86 Donate | | yea, ok, now help me plz 
Doubleposted Message Below:
so put screen"."print not screen":"print
__________________ SEE IF YOU CAN GET YOUR NAME NOTICED HERE!!!!
Last edited by Drakhra : 08-11-2006 at 10:22 AM.
Reason: Doublepost Preventer
| 
08-11-2006, 10:23 AM
| | Senior Member | | Join Date: Mar 2006 Location: Portugal Age: 19
Posts: 359
Points: 4.73 Donate | | u have msn??? if yes...add me ricardoc_92@hotmail.com | 
08-11-2006, 10:24 AM
| | Senior Member | | Join Date: Dec 2005
Posts: 526
Points: 9.86 Donate | | | sorry people but i do the program and i get a flashing screen with the pic and the green writing but nothing happens when i click "x"
__________________ SEE IF YOU CAN GET YOUR NAME NOTICED HERE!!!! | 
08-11-2006, 10:24 AM
| | Senior Member | | Join Date: Mar 2006 Location: Portugal Age: 19
Posts: 359
Points: 4.73 Donate | | | no....u need to put screen.print (in the really is with : grr damn forums) | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off Points Per Thread View: 0.00 Points Per Thread: 15.00 Points Per Reply: 0.50 | | | | |