PDA

View Full Version : Lua Coding



LilSwish722
November 18th, 2006, 16:20
I am starting to learn how to be a LUA Coder. I was wondering if anybody had some incredibly in-depth tutorials and the tools that I need to be a Coder. I would love to give back to the homebrew scene, so I would appreciate anyones help.

gunntims0103
November 18th, 2006, 16:34
firstly get familliar with the lua coding lunguage, I suggest reading this on-line book of lua coding find it here (http://www.lua.org/pil/).

once you do that read the reference book to stay famillair with the lua find that here (http://www.lua.org/manual/5.1/)

after that then get familliar with the psp lua version and its codes find that here (http://www.evilmana.com/tutorials/lua_tutorial_list.php)

once thats done your ready to do a quick tutorial find that here (http://wiki.ps2dev.org/psp:lua_player:tutorial)

then your about ready

splodger15
November 18th, 2006, 16:43
Also have a look here
http://www.evilmana.com/tutorials/lua_tutorial_list.php

LilSwish722
November 18th, 2006, 16:57
i tried evil mania and did pretty good until the button input thing then i would run it and it would say smething about it cant find 's' and then it would continue to run and shut off...now thats all it does.

"EDIT"--haha i relized why it automatically shuts down...i left out the
luaplayer script.lua
pause

line lol...but i would still like some help...especially from an experienced coder lol

but dont you find it ironic that i once said lua isnt that good and now im wanting to be a lua coder...odd huh lol.
Thanks for your help guys

gunntims0103
November 18th, 2006, 16:57
i tried evil mania and did pretty good until the button input thing then i would run it and it would say smething about it cant find 's' and then it would continue to run and shut off...now thats all it does.

well what were you trying to do create a game, app???

LilSwish722
November 18th, 2006, 16:59
im not entirely sure what im making. its on evilmana.com and im at the tables part of the tutorial. i understand most of it though

splodger15
November 18th, 2006, 17:18
You need to have an idea to create

LilSwish722
November 18th, 2006, 17:27
i do have an idea, but im still not entirely sure how to code and stuff. so until i learn all the terms and codes and stuff like that i cant put my idea into works. thats where i need ur guys help

splodger15
November 18th, 2006, 17:30
First of all make sure your idea is basic and what bits do you need help on

LilSwish722
November 18th, 2006, 17:37
lol my idea is pretty basic at this point it time. its just a beginning program and i need help on the WHOLE thing. like what codes to use, how to use them, and what they do, and where to put them.

P.S. I'm not a noob to homebrew, just coding :-)

splodger15
November 18th, 2006, 17:40
Whats your idea i'll get you started

LilSwish722
November 18th, 2006, 17:43
ok...well i was thinking of just making a simple app, like a temperature conversion program or a graphing program for alegebra because i need stuff like that for my homework and i think it would save kids from having to spend 100 bucks on a graphing calculator. whichever you think is better to start of with

splodger15
November 18th, 2006, 17:45
Ok first lets just get started with something even more basic

we will just have something like making something move on the screen so find a image you will like as the background

Make sure it has this
width = 480
height = 272

LilSwish722
November 18th, 2006, 17:50
uh...ok. so this means like find a pic that has those demensions. does it matter what it is

splodger15
November 18th, 2006, 17:54
we will just use this as the background , we also need a player

http://www.psp-hacks.com/psp-backgrounds/a8c7006f7fef30d37887601ab3fd07fb/NUNCHAKU_RENDER.BMP

We will use the car as a player

Now are you ready to begin

LilSwish722
November 18th, 2006, 18:01
opk sry to sound kinda stupid but i got confused with what u just said. im not sure what u mean by player. because i have luaplayer for the comp that i got off of a link at evilmana.com and that link im assuming shouldve sent me to a site to get the pic u have attached but it just sends me to psphacks.com like the very main page

splodger15
November 18th, 2006, 18:04
I have uploaded background here ,install lua player on your psp

We will use this as the background and the car as a player to move around on the screen

Now are you ready to start

LilSwish722
November 18th, 2006, 19:04
ok sry to take so long. I dont have my psp with me but i have the PSPE and i cant get it to run]properly, if u could help me get it working, then i guess we can continue with the coding things lol

gunntims0103
November 18th, 2006, 19:06
ok sry to take so long. I dont have my psp with me but i have the PSPE and i cant get it to run]properly, if u could help me get it working, then i guess we can continue with the coding things lol

why dont you download luaplayer windows so you can use lua on your computer, It makes it easier to test your code and make fixes. Its all around better;)

splodger15
November 18th, 2006, 19:17
First of all we will start with this

----------------------------------------------------------------
Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
weapon=Image.load("images/weapon.PNG")
background=weapon
car1=Image.load("images/car1.PNG")
player1=car1

------------------------------------------------------------------
Put that in your script at the top

basically this is the images we will be using and where would like the car to be on the screen

Dont copy and paste it in , type it in you learn more about it that way

LilSwish722
November 18th, 2006, 19:19
ok what do i do after this

splodger15
November 18th, 2006, 19:26
We will add some controls now enter this
-----------------------------------------------------------------
This moves the car up and down
-----------------------------------------------------------------

if pad:up() then
character = car1
player.y = player.y - 2
end

if pad:down() then
character = car1
player.y = player.y + 2
end

-----------------------------------------------------------------
This moves the car left and right
-----------------------------------------------------------------
if pad:left() then
character = car1
player.x = player.x - 2
end

if pad:right() then
character = car1
player.x = player.x + 2
end

------------------------------------------------------------------
Enter that in to your code

LilSwish722
November 18th, 2006, 19:30
ok its in my code now...what next

splodger15
November 18th, 2006, 19:34
Now save as script.lua

And run it

LilSwish722
November 18th, 2006, 19:39
it says error: script.lua:7: Image.load: Error loading image.

splodger15
November 18th, 2006, 19:46
aahhhhh you have your first error do you have both of the images i posted here

This is the error here

---------------------------------------------------------------------------------------------------

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
road=Image.load("images/weapon.PNG")
background=weapon
car1=Image.load("images/car1.PNG")
player1=car1


What you need to do is remove the word images on both of them just remove the word images nothing else

LilSwish722
November 18th, 2006, 19:50
yea i noticed that but it still says i have an error on line seven. this is what i have in my script

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
weapon=Image.load("weapon.PNG")
background=weapon
car1=Image.load("car1.PNG")
player1=car1

splodger15
November 18th, 2006, 19:54
do you have both of the images i posted on this site
save them as PNG

Save the background as weapon.PNG

and the car as car1.PNG

LilSwish722
November 18th, 2006, 20:03
ok i got that to work...now when i run it it tells me
errors: script.lua:12: attempt to index global 'pad' (a nil value)

for me line 12 is
player.y = player.y - 2

splodger15
November 18th, 2006, 20:09
Post your whole script here

LilSwish722
November 18th, 2006, 20:12
this is my whole script
------------------------------------------------

-- My First Lua Program
-- Author: YoungProdigy
Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
weapon=Image.load("weapon.PNG")
background=weapon
car1=Image.load("car1.PNG")
player1=car1

if pad:up() then
character=car1
player.y = player.y - 2
end

if pad:down() then
character = car1
player.y = player.y + 2
end

if pad:left() then
character = car1
player.x = player.x - 2
end

if pad:right() then
character = car1
player.x = player.x + 2
end

splodger15
November 18th, 2006, 20:16
-- My First Lua Program
-- Author: YoungProdigy

Room_width = 480
Room_height = 272
player1x = 15
player1y = 136
weapon=Image.load("weapon.PNG")
background=weapon
car1=Image.load("car1.PNG")
player1=car1

pad = Controls.read()

if pad:up() then
character=car1
player.y = player.y - 2
end

if pad:down() then
character = car1
player.y = player.y + 2
end

if pad:left() then
character = car1
player.x = player.x - 2
end

if pad:right() then
character = car1
player.x = player.x + 2
end

------------------------------------------------------------------

Give it a try now

as you may of noticed i added
pad = Controls.read()

yaustar
November 18th, 2006, 20:25
I hope both of you realise that code won't display anything on the screen.

LilSwish722
November 18th, 2006, 20:46
ok i added exactly what you have there and run it but i still have another error.

error: script.lua:13: calling 'blit' on bad self (number expected, got nil)

splodger15
November 18th, 2006, 21:04
Lil swish try this i have uploaded it for you

Here's the new code
-----------------------------------------------------------------

-- My First Lua Program
-- Author: YoungProdigy

Room_width = 480
Room_height = 272
player1x =15
player1y =136
background =Image.load ("weapon.PNG")
player1=Image.load("car1.PNG")

function checkcontrols()
pad = Controls.read()
if pad:start() then
exitgame = 1
end
if pad:right() then
player1x = player1x +2
end
if pad:left() then
player1x = player1x -2
end
if pad:up() then
player1y = player1y - 2
end
if pad:down() then
player1y = player1y +2
end
end
function drawall()
screen:blit (0,0,background)
screen:blit(player1x,player1y,player1)
screen.waitVblankStart()
screen.flip()

end

while true do

checkcontrols()
drawall()
if exitgame ==1 then
break
end
end

LilSwish722
November 18th, 2006, 21:27
ok so after i have this...how would i go about making another app or program

splodger15
November 18th, 2006, 21:28
Depends On what you want doing

If i was you i would stick to basic lua programs to start with