PSP3D Left Header
PSP3D Header Right
PSP3D Logo CraveOnline Logo
Help the PSP 3D community grow!
Vote for us below:


Vote on the PSP Top 200
PSP Top 200 - Games, Videos, Wallpapers, Files, Hacks, Homebrew

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!

Go Back PSP3D.com - Sony PlayStation Portable News, Homebrew, Hacks, Reviews, Videos, Mods, Forums > PSP Forums > Getting Started/Help/Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-11-2006, 09:27 AM
rikardo_92's Avatar
rikardo_92 rikardo_92 is offline
Senior Member
 
Join Date: Mar 2006
Location: Portugal
Age: 19
Posts: 359
Points: 4.73
Donate
Send a message via ICQ to rikardo_92 Send a message via AIM to rikardo_92 Send a message via ShopTapNham to rikardo_92 Send a message via Yahoo to rikardo_92
[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:

Quote:
while true do
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:

Quote:
pad = Controls.read()
We are assigning pad as Controls.read(), so pad is a variable.



Now you will print something to the screen!

Quote:
screenrint(185, 135, "YAY! This really works", green)
Now look at the code, i will explain...you always need to use screenrint 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:

Quote:
screen:blit(0, 0, psp3d)
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
screenrint(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, screenrint(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()

screenrint(185, 135, "YAY! This really works", green)

screen:blit(0, 0, psp3d)

if pad:cross() then
screenrint(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.
Reply With Quote
  #2 (permalink)  
Old 08-11-2006, 09:36 AM
Phant0m_Ph3wl's Avatar
Phant0m_Ph3wl Phant0m_Ph3wl is offline
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!!
__________________

Reply With Quote
  #3 (permalink)  
Old 08-11-2006, 10:07 AM
Drakhra's Avatar
Drakhra Drakhra is offline
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.
Reply With Quote
  #4 (permalink)  
Old 08-11-2006, 10:17 AM
rikardo_92's Avatar
rikardo_92 rikardo_92 is offline
Senior Member
 
Join Date: Mar 2006
Location: Portugal
Age: 19
Posts: 359
Points: 4.73
Donate
Send a message via ICQ to rikardo_92 Send a message via AIM to rikardo_92 Send a message via ShopTapNham to rikardo_92 Send a message via Yahoo to rikardo_92
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 :
__________________
Reply With Quote
  #5 (permalink)  
Old 08-11-2006, 10:18 AM
sikheadtom's Avatar
sikheadtom sikheadtom is offline
Is Da Best PSP3D Member
My Mood:
 
Join Date: Dec 2005
Location: England
Posts: 649
Points: 4.58
Donate
Send a message via AIM to sikheadtom Send a message via ShopTapNham to sikheadtom
I dont know if it was becuase ive allready know basic lua but i found that so easy!
__________________
SNES, PS1, PS2, PSP and PS3
Number of times reached 1000 posts: 3
Reply With Quote
  #6 (permalink)  
Old 08-11-2006, 10:21 AM
rikardo_92's Avatar
rikardo_92 rikardo_92 is offline
Senior Member
 
Join Date: Mar 2006
Location: Portugal
Age: 19
Posts: 359
Points: 4.73
Donate
Send a message via ICQ to rikardo_92 Send a message via AIM to rikardo_92 Send a message via ShopTapNham to rikardo_92 Send a message via Yahoo to rikardo_92
yep...lua is easy
__________________
Reply With Quote
  #7 (permalink)  
Old 08-11-2006, 10:22 AM
Drakhra's Avatar
Drakhra Drakhra is offline
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
Reply With Quote
  #8 (permalink)  
Old 08-11-2006, 10:23 AM
rikardo_92's Avatar
rikardo_92 rikardo_92 is offline
Senior Member
 
Join Date: Mar 2006
Location: Portugal
Age: 19
Posts: 359
Points: 4.73
Donate
Send a message via ICQ to rikardo_92 Send a message via AIM to rikardo_92 Send a message via ShopTapNham to rikardo_92 Send a message via Yahoo to rikardo_92
u have msn??? if yes...add me

ricardoc_92@hotmail.com
__________________
Reply With Quote
  #9 (permalink)  
Old 08-11-2006, 10:24 AM
Drakhra's Avatar
Drakhra Drakhra is offline
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!!!!

Reply With Quote
  #10 (permalink)  
Old 08-11-2006, 10:24 AM
rikardo_92's Avatar
rikardo_92 rikardo_92 is offline
Senior Member
 
Join Date: Mar 2006
Location: Portugal
Age: 19
Posts: 359
Points: 4.73
Donate
Send a message via ICQ to rikardo_92 Send a message via AIM to rikardo_92 Send a message via ShopTapNham to rikardo_92 Send a message via Yahoo to rikardo_92
no....u need to put screen.print (in the really is with : grr damn forums)
__________________
Reply With Quote
Reply

« I need Help putting Pong on my psp 2.80 | tiff help »



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.00
Points Per Thread: 15.00
Points Per Reply: 0.50

Similar Threads
Thread Thread Starter Forum Replies Last Post
[tutorial] how to make a userbar in photoshop [tutorial] Robkellas Getting Started/Help/Tutorials 6 08-10-2006 10:22 AM





Crave Partner Sites: CraveOnline.com | DVDFile.com | PSP3D.com | PS33D.com | NDS3D.com | X3603D.com | NWii3D.com | Hardware3D.com | ComingSoon.net | SuperHeroHype.com | RedBalcony.com | ActionTrip.com | CraveLyrics.com | Soundtrack.net | CraveFix.com | SpikedHumor.com | RPGamer.com | TattooNow.com | ImpactWrestling.com | SeekLyrics.com | PedalBMX.com | WildKO.com | vidKing.com | StrategyInformer.com | HHdb.com | RapLeagues.com | HipHop-Lyrics.com | Cravecocktails.com | ThePhatPhree.com | RideJudge.com | HottieSpots.com


Powered by Custom vB Version 6.0 for Crave Online Media, LLC.
Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. , Afnani Media, LLC., and PSP3D.com. All rights reserved.
LinkBacks Enabled by vBSEO 3.0.0 RC8
All times are GMT -4. The time now is 09:59 PM.