Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I started playing with Lua today, and decided to dive head first and attempt to make a game. The game ...
-
09-27-2006, 03:24 PM #3541
- Registriert seit
- Sep 2006
- Beiträge
- 18
- Points
- 3.800
- Level
- 38
- Downloads
- 0
- Uploads
- 0
I started playing with Lua today, and decided to dive head first and attempt to make a game. The game will be a clone of an old arcade game called Tapper (has anyone heard of it?)
Basiclly, the game works like this: You are a bartender, and you have to keep the guests happy. You send drinks down the bar to the people who come in, and catch the empties they send back. If you miss an empty, or throw a full one to no body, you loose points.
I need to know how to randomly generate the guests that come in, how to get them out after they drink, and how to make them send back the drinks. That i feel is of the least importance right now.
More importantly, I was hoping someone had a collison and score keeping tutorial, because thats what I will really need help on. Thanks alot!
(...if anyone will want to hop on board and help make the game, your invited. [email protected])
-
09-27-2006, 05:10 PM #3542
To do something random you should first set the seed. Then just use the random number generator that comes with LUA.
collision is just checking if some x and y coords are the same.
With score keeping I assume you mean saving the score? if you search a bit you'll find its really not that hard. There are a lot of tuts that describe how to save something to a file. I know there's one at evilmana.com.LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
09-27-2006, 05:19 PM #3543I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
You can learn all of this from ProgramLua. There's a link in my signiture. Except for collisions. Got to evilmana.com for that.
Zitat von rybarnes

-
09-27-2006, 05:33 PM #3544sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
Yeah, or see my stickied list for lua snippets (it has animation and collision, which you most likely need ;))
-
09-27-2006, 07:39 PM #3545QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Alabama
- Beiträge
- 142
- Points
- 4.241
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Also, check out the code in Snake, which came with Lua. It has random generation and saving (single and multiple line). I couldn't understand saving at all until I looked at a real game's code.
For animation help, you could try Grimfate126's animation library:
http://forums.qj.net/f-psp-developme...y-2-68855.html
And take things slow. Make sure you understand and can demonstrate what you've learned before you continue to something else. If you rush yourself, you'll get discouraged and quit.
-
09-28-2006, 09:06 AM #3546QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
can anyone help me with that battery part???
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
09-28-2006, 12:08 PM #3547QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Illinois
- Beiträge
- 897
- Points
- 8.215
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I need help
whenever i do this code i have to hold x to keep the file open and i want it to stay there right when i press x.
Code:if pad:cross() and current == 1 then dofile("nameentry.lua") end
-
09-28-2006, 12:23 PM #3548sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
That should work ;)Code:dofile_state = 0 if pad:cross() then dofile_state = 1 end if dofile_state = 1 then dofile("nameentry.lua") end
-
09-28-2006, 12:42 PM #3549QJ Gamer Green
- Registriert seit
- Oct 2005
- Ort
- Illinois
- Beiträge
- 897
- Points
- 8.215
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Thanks it finally works.
-
09-28-2006, 06:42 PM #3550QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Alabama
- Beiträge
- 142
- Points
- 4.241
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Cwirsing, you might understand it now, but if you don't:
You don't have to use dofile_state
You could use anything as the variable. The reason why your code didn't work right is because it was only active if 'pad:cross'. Since 'pad' isn't always 'cross', it would be inactive most of the time.
With Bronx's code, it (by 'it', I mean: dofile("nameentry.lua")) is only active if dofile_state equals 1. Every time you press cross, dofile_state becomes 1 (no matter what it used to be), and since there is no code to turn dofile_state into anything else, it'll stay like that, and dofile("nameentry.lua") will stay active.
If you add this:
Then every time 'pad' is 'circle', dofile_state will turn into 0, and dofile("nameentry.lua") will stop happening.Code:if pad:circle() then dofile_state = 0 end
I can't think of any, but if you can find a lua program that has that battery display code, look at the source, and do a search for the code you're confused about.
Zitat von myschoo
Geändert von Aphonia (09-28-2006 um 06:53 PM Uhr)
-
09-29-2006, 04:31 AM #3551QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ok thx ;)
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
10-01-2006, 06:20 AM #3552QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
another question... is it possible to make eboot.pbp from LUA code???????
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
10-01-2006, 06:32 AM #3553Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von myschoo
yes, theres a guide somewhere. serach for it. BUT, the problem is, you can see the code half-way down the eboot.--------------------------------------------------------------------------------------
-
10-01-2006, 07:20 AM #3554QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Alabama
- Beiträge
- 142
- Points
- 4.241
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I've never messed with making an eboot, but I think you can take an existing lua eboot, strip the game code from the middle, and replace it with your own.
-
10-01-2006, 08:21 AM #3555QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
yeh i was searching, i will do again...:)
Zitat von Grimfate126
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
10-01-2006, 12:55 PM #3556
Hi im having probleme to proply blit my image by using table here is the table code but i get the following error attempt to compare number whit nil on line 55 whic is mark in the CODE][/CODE]
Code:-- call player sprites as Tables PlayerDir="right" PlayerAnim = {} PlayerAnim[1] = {} --standing right PlayerAnim[1][1] = Image.load("Player/Stand/StandR-1.png") PlayerAnim[1][2] = Image.load("Player/Stand/StandR-2.png") PlayerAnim[1][3] = Image.load("Player/Stand/StandR-3.png") PlayerAnim[1][4] = Image.load("Player/Stand/StandL-2.png") PlayerAnim[1][5] = Image.load("Player/Stand/StandL-1.png") PlayerAnim[2] = {} --standing left PlayerAnim[2][1] = Image.load("Player/Stand/StandL-1.png") PlayerAnim[2][2] = Image.load("Player/Stand/StandL-2.png") PlayerAnim[2][3] = Image.load("Player/Stand/StandL-3.png") PlayerAnim[2][4] = Image.load("Player/Stand/StandL-2.png") PlayerAnim[2][5] = Image.load("Player/Stand/StandL-1.png") PlayerAnim[3] = {} --running right PlayerAnim[3][1] = Image.load("Player/Run/RunR-1.png") PlayerAnim[3][2] = Image.load("Player/Run/RunR-2.png") PlayerAnim[3][3] = Image.load("Player/Run/RunR-3.png") PlayerAnim[3][4] = Image.load("Player/Run/RunR-4.png") PlayerAnim[3][5] = Image.load("Player/Run/RunR-5.png") PlayerAnim[4] = {} --running left PlayerAnim[4][1] = Image.load("Player/Run/RunL-1.png") PlayerAnim[4][2] = Image.load("Player/Run/RunL-2.png") PlayerAnim[4][3] = Image.load("Player/Run/RunL-3.png") PlayerAnim[4][4] = Image.load("Player/Run/RunL-4.png") PlayerAnim[4][5] = Image.load("Player/Run/RunL-5.png") while not Controls.read():start() do pad= Controls.read() if currimgstate > 5 then <--------This is line 55 where i get the error currimgstate=1 else currimgstate=currimgstate+1 end if pad:right() then state=3 --running right PlayerDir="right" elseif pad:left() then state=4 --running left PlayerDir="left" else if PlayerDir=="right" then state=1 --standing still facing right elseif PlayerDir=="left" then state=2 --standing still facing left end end screen:blit(PlayerX, PlayerY, PlayerAnim[state][currimgstate]) endFree Prizes at Prizerebel Join us!
I already got 11 Gifts. Ask me for details or proof.
-
10-01-2006, 01:03 PM #3557Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von ZereoX
have you declared currimgstate?
or, just use animation lib 1, since you dont have sprite sheets.--------------------------------------------------------------------------------------
-
10-01-2006, 01:30 PM #3558NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
..nvm ill come back later with a better question then pretty much asking you how to make an entire game lol >.<
-lost n00b porgrammer ;)Geändert von iamcanadian (10-01-2006 um 01:44 PM Uhr)
[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-01-2006, 01:44 PM #3559Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
pool is probably not the best thing to start with. you need to calculate angles, hit powers, sin, cosin, tan, all that,
Zitat von iamcanadian
--------------------------------------------------------------------------------------
-
10-01-2006, 01:57 PM #3560QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Exactly, pool would requre more time doing calculations than it would to code it. I'm in geometry this year and it's freakin me out how long of a time people spend to demonstrate a simple geometric property.
-
10-01-2006, 02:48 PM #3561NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
didtent think of that lol good pointbut im not shure what to start with? any ideas on something easy but cool :P lol becuse i thought pool would be easy but i was wrong
Zitat von TacticalPenguin
-= Double Post =-
ok ive got an idea what if i made a driveing game for the background say i had a track or something but how would i make it so if the car goes off track you lost per say?Geändert von iamcanadian (10-01-2006 um 02:48 PM Uhr) Grund: Automerged Doublepost
[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-01-2006, 03:11 PM #3562I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
How would I use the analog stick to move? I've tried looking at other examples, but I couldn't figure it out.

-
10-01-2006, 03:38 PM #3563QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Ok, i just got done with my first lua thing ever, but it wont work......
*cries*
Could somebody take a look at the script for me and see whats wrong?
Its attached.
Edit: nvm, heres the code:
And the 7 extra kb is the picture that it loads, which is 480x272 in resolution and is named background.jpgCode:blue = Color.new(0, 0, 255) screen:print(0, 0, "Loading: 30%", blue) screen.flip() screen.waitVblankStart(120) screen:clear screen:print(0, 0, "Loading: 70%", blue) screen.flip() screen.waitVblankStart(120) screen:clear screen:print(0,0, "Loading Complete", blue) screen.flip screen.waitVblankStart(120) screen:clear background = Image.load("background.jpg") screen:print(0, 0, "Tux says hello!", blue) screen.flip() screen.waitVblankStart(240) screen:clear background = Image.load("background.jpg") screen:print(0, 0, "Tux says goodbye!", blue) screen.flip() screen.waitVblankStart(180) while true do screen.waitVblankStart() endGeändert von TacticalPenguin (10-14-2006 um 08:14 PM Uhr)
-
10-01-2006, 03:55 PM #3564NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
thats what i have so far not much it works on the computer but not on my psp :S andi dont know how to set bounderies so it cant just drive off the track. and i need to create an ecceleration button insted of just useing the d-pad. and a brake button but for now i need to know hoto do too things bounderies and make it work on my psp???
Code:track = Image.load("track.png") car = Image.load("car.png") screenwidth = 480 - player:width() screenheight = 272 - player:width() car = { } car[1] = { x = 200, y = 50 } while true do pad = Controls.read() screen:clear() for a = 0, 14 do for b = 0,8 do screen:blit(0,0,track) end end screen:blit(car[1].x,car[1].y,car) if pad:left() and car[1].x > 0 then Player[1].x = car[1].x - 2 end if pad:right() and car[1].x < screenwidth then car[1].x = car[1].x + 2 end if pad:up() and car[1].y > 0 then car[1].y = car[1].y - 2 end if pad:down() and car[1].y < screenheight then car[1].y = car[1].y + 2 end screen.waitVblankStart() screen.flip() end[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-01-2006, 04:41 PM #3565Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
It's pretty nice because since it returns an integer, you don't have to do an if statement (in the simplest case, at least).
Zitat von ARza
You'll have to mess with the signs a bit to get it right, but that takes care of movement in almost all directions.Code:player.x=player.x+math.floor(pad:analogX()/32) player.y=player.y-math.floor(pad:analogY()/32)
@ Tactical Penguin and iamcanadian:
Post errors.
-
10-01-2006, 04:42 PM #3566QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Post error? I can see my post fine......
-
10-01-2006, 04:46 PM #3567NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
post error?? whats that and how do i fix it
[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-01-2006, 04:49 PM #3568Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von TacticalPenguin
ROFL!!! :ROFL: :ROFL: he means, post what error you get when you run the script.
-= Double Post =-
same as above.
Zitat von iamcanadian
Geändert von Grimfate126 (10-01-2006 um 04:49 PM Uhr) Grund: Automerged Doublepost
--------------------------------------------------------------------------------------
-
10-01-2006, 04:53 PM #3569QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Oh, ok. It says:
Error: index.lua :6: function arguments expected near 'scree'
Press start to restart
-
10-01-2006, 04:55 PM #3570NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
oh haha i feel dumb now
lol
heres the error:
Error: DRIVEING.LUA:4: Image.load Error loading image. lmao i think i can fix it now :P i read it before but i dident read the whole thing now i feel dumber :P[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum