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; no prob. im glad it worked! And i just made a really hard version of my crappy game. Now the ...
-
02-10-2006, 09:01 AM #511
no prob. im glad it worked!
And i just made a really hard version of my crappy game. Now the target moves randomly with a random speed, haha. This is very difficult, but also pretty fun. I'll just post it here so everybody can learn from the code, or have a little fun, lol.
Later Altair
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-10-2006, 06:18 PM #512QJ Gamer Bronze
- Registriert seit
- Oct 2005
- Ort
- Alabama
- Beiträge
- 272
- Points
- 5.975
- Level
- 50
- Downloads
- 0
- Uploads
- 0
If you use random numbers be sure to seed it, or you will get the exact same numbers every time you run your program... one good way to seed is put this at the top of your program somewhere
Code:math.randomseed(os.time())
My lua tutorials for PSP - www.evilmana.com/tutorials
PSP Lua CodeBase - Add your own code examples to the codebase! - www.evilmana.com/tutorials/codebase/
-
02-11-2006, 04:46 AM #513
Yeah read something about that. But it's not true with my 'game'. It's not showing any repetition as far as i can see. Everytime i restart it, the movement is different and its really hard to anticipate it.
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-15-2006, 08:06 AM #514Developer

- Registriert seit
- Oct 2005
- Ort
- Boston, MA
- Beiträge
- 1.389
- Points
- 14.378
- Level
- 77
- Downloads
- 0
- Uploads
- 0
Can Someone tell me whats wrong with this:
--Garage PSP Menu Test
--By Vaza
--Loading Images
Navtop = Image.load("bartop.png")
BG = Image.load("bg.png")
Car1 = Image.load("car1.png")
Comingsoon = Image.load("Comingsoon.pn g")
Car2 = Image.load("car2.png")
--Variables
carnumber = 1
--Read Control Input
pad = Controls.read()
--Main loop
while true do
screen:blit(0, 0, BG, false)
screen:blit(0, 0, Navtop)
screen.flip()
if pad:left() then
carnumber = carnumber - 1
end
if pad:right() then
carnumber = carnumber + 1
end
if carnumber = 3 then
carnumber = carnumber - 2
end
if carnumber = 1 then
screen:blit(336, 8, Car1)
end
if carnumber = 2 then
screen:blit(336, 8, Car2)
end
if pad:cross() then
screen:blit(0, 0, Comingsoon)
end
end
-
02-15-2006, 09:24 AM #515100% Pure Awesome

- Registriert seit
- Jan 2006
- Beiträge
- 508
- Points
- 6.164
- Level
- 51
- Downloads
- 0
- Uploads
- 0
-
02-15-2006, 09:52 AM #51611th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
Navtop = Image.load("Themes/Bar.png")
Zitat von Vaza
BG = Image.load("BGs/BG.png")
Car1 = Image.load("Carsq/car1.png")
Comingsoon = Image.load("Comingsoon.pn g")
Car2 = Image.load("Carsq/car_1.png")
--Variables
carnumber=1
--Read Control Input
pad = Controls.read()
--Main loop
while true do
screen:blit(0, 0, BG, false)
screen:blit(0, 0, Navtop)
screen.flip()
if pad:left() then
carnumber = carnumber - 1
end
if pad:right() then
carnumber = carnumber + 1
end
if carnumber == 3 then
carnumber = carnumber - 2
end
if carnumber == 1 then
screen:blit(336, 8, Car1)
end
if carnumber == 2 then
screen:blit(336, 8, Car2)
end
if pad:cross() then
screen:blit(0, 0, Comingsoon)
end
end
All Done
I Guess i shouldve tweeked it for you
but i cant at the moment
FAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
02-15-2006, 09:56 AM #517Developer

- Registriert seit
- Oct 2005
- Ort
- Boston, MA
- Beiträge
- 1.389
- Points
- 14.378
- Level
- 77
- Downloads
- 0
- Uploads
- 0
thx mate.
Zitat von c5cha7
-
02-15-2006, 10:03 AM #51811th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
K, After all i did say when i had the
Zitat von Vaza
time i would help :) . But at the moment i am
learning C+ so i might not be at much help
.
Anyway good luck :Jump:FAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
02-15-2006, 10:07 AM #519Developer

- Registriert seit
- Oct 2005
- Ort
- Boston, MA
- Beiträge
- 1.389
- Points
- 14.378
- Level
- 77
- Downloads
- 0
- Uploads
- 0
i get the error then expected near = on luaplayer windows
-
02-15-2006, 06:21 PM #520QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 375
- Points
- 5.631
- Level
- 48
- Downloads
- 0
- Uploads
- 0
ok after taking a little break from coding but now im back at it working on the pole creation part but i haver a problem(again)
everything in the if part is good but the poles dont createCode:if np==0 and rc==0 and math.random(0, 1)==0 then screen:blit(x1-ps, y1, Obj) y1=200 rc=0 np=1 else end if np==0 and rc==0 and math.random(0, 1)==1 then screen:blit(x1-ps, y1, Obj) y1=178 rc=0 np=1 else end
-
02-15-2006, 06:25 PM #521words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
lol, I wonder what game your making?
Zitat von Vaza

...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
02-16-2006, 07:26 AM #522Developer

- Registriert seit
- Oct 2005
- Ort
- Boston, MA
- Beiträge
- 1.389
- Points
- 14.378
- Level
- 77
- Downloads
- 0
- Uploads
- 0
yer, im making garages menu system, so im a coder and the creator, can somebody please tell me what the code is to put in the time?
Zitat von SG57
-
02-17-2006, 11:20 AM #52311th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
Try this code then :icon_wink
Zitat von Vaza
Navtop = Image.load("Themes/Bar.png")
BG = Image.load("BGs/BG.png")
Car1 = Image.load("Carsq/car1.png")
Comingsoon = Image.load("Comingsoon.pn g")
Car2 = Image.load("Carsq/car_1.png")
--Variables
carnumber=1
--Read Control Input
pad = Controls.read()
--Main loop
while true do
screen:blit(0, 0, BG, false)
screen:blit(0, 0, Navtop)
screen.flip()
if pad:left() then
carnumber=carnumber - 1
end
if pad:right() then
carnumber=carnumber + 1
end
if carnumber==3 then
carnumber=carnumber - 2
end
if carnumber==1 then
screen:blit(336, 8, Car1)
end
if carnumber==2 then
screen:blit(336, 8, Car2)
end
if pad:cross() then
screen:blit(0, 0, Comingsoon)
end
end
That might work :mrgreen: .
And about the clock function, i think you can find it here
http://wiki.ps2dev.org/psp:lua_player:functionsFAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
02-18-2006, 05:35 PM #524
wow crazy thread, so much info in one place
ok I have this working
But what i want is instead of having my dot stop totaly when it hits a red pixel, I want it to be block by the red pixels and be able to continu around itred = Color.new(255, 0, 0)
dot = Image.load("DATA/dot.png")
bgC = Image.load("DATA/bg col2.png")
x0 = 0 ; y0 = 0 ; x1 = 0 ; y1 = 0
while true do
screen:clear()
pad = Controls.read()
dx = pad:analogX()
if math.abs(dx) > 32 then
x0 = x0 + dx / 64
end
dy = pad:analogY()
if math.abs(dy) > 32 then
y0 = y0 + dy / 64
end
if bgC
ixel(x1, y1) == red then
x1 = x1 ; y1 = y1 else
x1 = x0 ; y1 = y0
end
screen:blit(0, 0, bgC)
screen:blit(x1, y1, dot)
screen.waitVblankStart()
screen.flip()
if pad:start() then break end
end
anybody as an idea how I could do this?
-
02-19-2006, 04:32 AM #525
First of all, what happens is that if a pixel is red, then x1 is always x1. The same goes for y1. So it will never move again unless you code it differently.
Secondly, how do you want it to continue around it? Like 'feel' the edges and then move along them?LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-19-2006, 04:35 PM #526
Zitat von Altair
Exactly what you just discribed, I change my x1, y1 to x0 and y0 when checking the pixel color, and now it continues doesn't get stock, but it kind of teleport the other side of the zone like it was doing the movement and then when it's not on red pixels appears at that position, I'm new at lua and programming so it doesn't always to clear to me
but what you discribe is what I wanna do feel the edge (been looking for those words)Geändert von arlutik (02-19-2006 um 06:18 PM Uhr)
-
02-20-2006, 04:12 AM #527
Ok to make it stop moving and also stay on that place (the x and y coordinates) you just say that if the pixel is red, the x and y coordinates stay thesame.
The feeling is a little harder. The thing you have to do is check if the pixels around it are also red. So something like:If you want it to go the shortest route, then i don't know how to do that. Maybe you can implement a learning thing?Code:if x1 + 1 == red then ...
I hope this is clear enough. Its hard to explain in short. I don't want to just give you the code :P, besides i haven't tried the feeling part myself, but i can imagine.
AltairGeändert von Altair (02-20-2006 um 11:46 AM Uhr)
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-20-2006, 12:30 PM #528
thanx mate, I'm sure it's gona help alote
thanx for not giving me the code otherwise I wouldn't learn, Lua is all bout undestanding what is going on
thanx again, I love lua
-
02-21-2006, 02:39 AM #529
yeah i like it too. And i also like to help other LUA coders (well those are the only coders i can help i guess, unless its HTML or JavaScript).
If something is unclear or you want to know something else i'll try to help you out. Good luck with it!LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-21-2006, 04:34 AM #530QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 375
- Points
- 5.631
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Right now im making a game based on a mini game from an older xbox game(this is gona be 2-d of coarse) but i ran into a problem with a random pole generator. im going to use laurin's collision detection so i dont need a variable for each pole but thats where i run into the problem. i want the speed the pipes are moving to be subtracted from the x value(making it move left) but i dont want to have to predefine all the x values for every pipe. i was wondering how i would do this? so basicly i would have the y value all preset but i just need to have the x value keep subtracting another variable.
-
02-21-2006, 09:20 AM #531
im sorry but i dont think i understand you completely.
The pole generator you're talking about, is that pole as in pole-coordinates, or as in just a pole (a stick)? And what exactly is your problem with it?
And for the moving left of the pipes: do you mean that you want to use one variable for the speed for all the pipes? Maybe you can use a table. See the LUA wiki tutorial for that, or PSPMillionare's tutorial on tables. If all the pipes are move the same and at the same time, then you can just use one variable.
I hope i understood you correctly, othwerwise you have to explain it a little better, maybe then i can help.
AltairLUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-21-2006, 02:30 PM #532QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 375
- Points
- 5.631
- Level
- 48
- Downloads
- 0
- Uploads
- 0
the poles are sticks(actualy a circle cause its looking from a side). they are all going to be moving at the same speed but when one reaches the left screen im gona move it back to the right side. im going to have it pick a random number to determin if its a higher pole or a lower pole(hieght wise). the problem is their going to be at different x positions. I want it to subtract the speed from its own x variable without having to creat a whole new variable for each.
heres a little drawing to help show what the poles are gojng to be
+ is a pole = is a space
===+=====+==+====+====+
=+====+=======+====+===
so i want to make somthing that randomly picks if its on top or bottom
-
02-21-2006, 04:07 PM #533
Then you have to go with a table i think. Th ething is i almost know all the commands i think (i went through the list a couple of times to search for the ones i needed), but i haven't used them all. I know tables are really handy though.
I think you should do something like this.
Make a table where all the x variables of all the poles are in say "xvar". Then you can just say "xvar = xvar - xspeed".
So that would make:this is for 10 poles and i create random x-coordinates for them. If you want them to have fixed x-coordinates then you can do that ofcourse.Code:xvar = {} while n<10 do xvar[n] = math.random(0,100) n=n+1 end
To make them all move the same, you can use:where xspeed is the speed (duh!).Code:xvar = xvar - xspeed
Im not sure if you can just say xvar - 1 though. Just try it and see if it works. If it works then the rest should be easy.LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-21-2006, 10:44 PM #534
What is the code for the port for the headphone extension?
-
02-22-2006, 02:33 AM #535
ok that one i dont know :P. Hmm im not sure if thats possible through LUA, i dont think so. I dont know of anyone who has used it in a LUA app.
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-22-2006, 02:36 AM #536
BTW Is your game gonna be some sort of Frogger?
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-22-2006, 04:13 AM #537QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 375
- Points
- 5.631
- Level
- 48
- Downloads
- 0
- Uploads
- 0
its from a game called fusion frenzy. it was a game full of mini games for the xbox early on in its life. also thanks for the help. ill try this out when i get back from school.
-
02-23-2006, 06:02 PM #538QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- Grand Line
- Beiträge
- 5.996
- Points
- 40.380
- Level
- 100
- Downloads
- 0
- Uploads
- 0
basically im trying to make it say something like if you punch once then extend the timer 1 to give the user some time to make another combo (by pressing square again) i might expand on this by making it like if you are to a certain point then you have to stop (to make it so you dont have unlimted combo) and make your character unable to move for a while.Code:if pad:square() then dir.ax = -3 state = Fight_l[W_FRAME] W_TIMER = W_FRAME + 1 if W_TIMER == 0 then end If W_FRAME = 0 then W_TIMER -1 end lastdir = "left" end end
[CENTER][IMG]http://img130.imageshack.us/img130/1640/acefcbanner2wo9.gif[/IMG]
[SIZE=1][B]I'm soo hot[/B][/SIZE]
[/CENTER]
[SIZE=2][CENTER][/SIZE][/CENTER]
[center]Sorry. No Advertising[/center]
-
02-23-2006, 07:43 PM #539Psp Dev

- Registriert seit
- Jun 2005
- Ort
- Nebraska
- Beiträge
- 228
- Points
- 5.664
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Lua help
Code:--Movement if pad:up() and pad:up() ~= oldpad:up() then XLMove = 0 YLMove = -1 timer = 0 LastSet = 1 if position == 3 then gameover() end position = 4 end if pad:down() and pad:down() ~= oldpad:down() then XLMove = 0 YLMove = 1 timer = 0 LastSet = 2 if position == 4 then gameover() end position = 3 end if pad:right() and pad:right() ~= oldpad:right() then XLMove = 1 YLMove = 0 timer = 0 LastSet = 3 if position == 1 then gameover() end position = 2 end if pad:left() and pad:left() ~= oldpad:left() then XLMove = -1 YLMove = 0 timer = 0 LastSet = 4 if position == 2 then gameover() end position = 1 end if pad:triangle() and pad:triangle() ~= oldpad:triangle() then XRMove = 0 YRMove = -1 timer2 = 0 LastSet = 5 if position2 == 7 then gameover() end position2 = 8 end if pad:cross() and pad:cross() ~= oldpad:cross() then XRMove = 0 YRMove = 1 timer2 = 0 LastSet = 6 if position2 == 8 then gameover() end position2 = 7 end if pad:circle() and pad:circle() ~= oldpad:circle() then XRMove = 1 YRMove = 0 timer2 = 0 LastSet = 7 if position2 == 5 then gameover() end position2 = 6 end if pad:square() and pad:square() ~= oldpad:square() then XRMove = -1 YRMove = 0 timer2 = 0 LastSet = 8 if position2 == 6 then gameover() end position2 = 5 end -- UPDATE -- RightX = RightX + XRMove + XRMove + Interval RightY = RightY + YRMove + YRMove + Interval PixelRX = RightX PixelRY = RightY LeftX = LeftX + XLMove + XLMove + Interval LeftY = LeftY + YLMove + YLMove + Interval PixelLX = LeftX PixelLY = LeftY Score = Score + 1 + Interval if RightX > 468 or RightY > 260 or RightX < 0 or RightY < 0 then LastSet = 13 gameover() end if LeftX > 468 or LeftY > 260 or LeftX < 0 or LeftY < 0 then LastSet = 10 gameover() end gamebackground:fillRect(PixelRX + 1, PixelRY + 1, 9, 9, red) gamebackground:fillRect(PixelLX + 1, PixelLY + 1, 9, 9, blue) Color1 = gamebackground:pixel(PixelRX , PixelRY) Color2 = gamebackground:pixel(PixelRX+11, PixelRY) Color3 = gamebackground:pixel(PixelRX, PixelRY+11) Color4 = gamebackground:pixel(PixelRX+11, PixelRY+11) Color5 = gamebackground:pixel(PixelLX, PixelLY) Color6 = gamebackground:pixel(PixelLX+11, PixelLY) Color7 = gamebackground:pixel(PixelLX, PixelLY+11) Color8 = gamebackground:pixel(PixelLX+11, PixelLY+11) timer2 = timer2 + 0.1 -- create a delay if timer2 >= 0.7 then if Color5 == red or Color5 == blue or Color6 == red or Color6 == blue or Color7 == red or Color7 == blue or Color8 == red or Color8 == blue then LastSet = 9 gameover() end end timer = timer + 0.1 -- create a delay if timer >= 0.7 then if Color1 == red or Color1 == blue or Color2 == red or Color2 == blue or Color3 == red or Color3 == blue or Color4 == red or Color4 == blue then LastSet = 12 gameover() end end
It works but when you change direction it goes to gameover. I cant figure it out.
-
02-24-2006, 07:38 AM #540
MikePiP, one thing thats wrong in your code is this:
it has to beCode:if pad:up() and pad:up() ~= oldpad:up() then
where you store pad in oldpad at the end of the loop, like thisCode:if pad:up() and pad ~= oldpad then
Maybe there are other things wrong but thats the most obvious one. Try and see if it works now.Code:oldpad=pad
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]


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