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; Yea i took out a bunch of points and was gonna buy no pm flood limit then i remembered i ...
-
12-01-2006, 05:52 AM #4411QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Yea i took out a bunch of points and was gonna buy no pm flood limit then i remembered i get the discount for premium and 300k, so with the 26k i saved i stickied this and bumped the MDPR.
-
12-01-2006, 12:37 PM #4412Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Hello im making my game and im pretty much finished with area 1. I want my guy to be able to walk to the edge of the screen and then go to a new area but if i keep it in the same loop wouldnt it just load my area 1 background and stuff back onto the screen?? I heard people saying that break changes the control to a different loop so couldnt i do
while true do
-- bla bla this is area 1
if player.x == screen.x then
break
end
end
while true do
--now we are in area 2 ya ya bla bla
would that work?? im confused on how to make it load a level 2 or something? And what about sidescrolling how do i do that are there anymore tutorials besides evilmana?If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
12-01-2006, 12:58 PM #4413QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- London, United Kingdom
- Beiträge
- 131
- Points
- 4.812
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Im trying to complete a LUA script thats for the PSP thats able to remotely control foobar2000 though controlserver. Everything was going smoothly untill I started retreving tracklists.
Information sent gets split upon finding a "\n" for splitting lines and then retreving the data on those lines is done by finding a "|".
I just expect a number in the first field but sometimes the script jumps to a section in the line and adds that to the result...
For example: 6016016016016016016016016 01esk_-_excuses601601601
"601" is given to an inactive track on a playlist and "esk_-_excuses" happens to be the title of the track. But I specificly asked for the first field so I dont understand why the title is there. This tends to occur with large amount of data.
The socket gets polled for data all the time and data begins to get sorted when theres information.
The function that stringsplitsCode:if socket then incoming = socket:recv() if incoming ~= "" then values = splitString(incoming,"\n") for key, value in values do temp = splitString(value,"|")[1]
Code:function splitString(str, de) first = true parts = {} if de == ";" then str = string.gsub(str,";;","@£$&") end while true do s, e = string.find(str,de) if e then if not (first and string.sub(str,1,s-1) == "") then tmp = string.sub(str,1,s-1) if de == ";" then tmp = string.gsub(tmp,"@£$&",";;") end table.insert(parts,tmp) end str = string.sub(str,e+1) s = 1 first = false else tmp = string.sub(str,1) if de == ";" then tmp = string.gsub(tmp,"@£$&",";;") end table.insert(parts,tmp) break end end return parts end
-
12-01-2006, 01:43 PM #4414QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
how about this:
Zitat von GuitarGod1134
try that. its pretty simple.Code:blah = 1 -- this will be where the player currently is while true... ... if blah == 1 then make this area appear elseif blah == 2 then make this area appear end ... end
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-01-2006, 02:22 PM #4415Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
ya i was thinking about throwing a variable in thanks ill try that out.
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
12-01-2006, 09:57 PM #4416
question
ok, i would like to know if there is a function in lua that will get the integer part of an double (decimal). So if i had 48.65, I could convert this to just 48.
Hmmm, maybe i could just use like a rounding function...
is there any out there
idp being the number of decimals you want.Code:ok, i found this function math.round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end
i guess, this works fine, for me so nvm, i was just wondering if there was any function already incorporated into lua
-
12-01-2006, 10:10 PM #4417Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von emericaska8r
for your purpose, this should be fine:
that will mtake the decimal away. so 50.2 becomes 50, and 3.99 becomes 3.Code:math.floor(num)
--------------------------------------------------------------------------------------
-
12-02-2006, 04:54 AM #4418Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
can i do if statements inside of if statments??? im trying to make it so that when my creature goes to the edge of the screen he enters a new area and not a new level. Im not sure how to add this without making it have to read a new lua file with a new loop. someone help!!1 my source is posted a couple pages back if anyone bothered to read it. im trying to do what eminent said.
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
12-02-2006, 05:15 AM #4419QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
yes, you can put if statements in others. however, i think it would be better if, instead of making millions of 'if's, do this:
Zitat von GuitarGod1134
that'll test both conditions in one 'if' statement. and its not limited to testing just two conditions either. so it could even be:Code:if [whatever] and [whatever] then
Code:if [whatever] and [whatever] and [whatever] and [whatever] then
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 05:15 AM #4420Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Spoiler for My game:
How do I make it so that when he reaches the end othe screen he enters a new area but i dont want to exit my main loop??!?!?!?!?!?
EDIT: used spoiler because code is very long.If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
12-02-2006, 05:28 AM #4421QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
also, you might want to put an if statement that'll prevent 'currentarea' from reaching values other than the ones you want.Code:--the creatures table creature = {} creature[1] = { x = 10, y = 10 } --what area are u in??? currentarea = 0 --the width and height of screen screenwidth = 480 screenheight = 272 --new area if creature[1].x >= screenwidth then currentarea = currentarea + 1 creature[1].x = 10 -- sending this guy back to where he started off in the map, but it could be anywhere you want. elseif creature[1].x <= screenwidth - 479 then currentarea = currentarea - 1 end -- if put "creature[1].x <= screenwidth - 479 " so it could change -- even if the player went the other way. if currentarea == 0 then screen:blit(0, 0, area here) elseif currentarea == -1 then screen:blit(0, 0, another area here) elseif currentarea == 1 then screen:blit(0, 0, other area here)[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 05:36 AM #4422No longer a community member.
- Registriert seit
- Jun 2006
- Ort
- Nederland
- Beiträge
- 3
- Points
- 17.748
- Level
- 84
- Downloads
- 0
- Uploads
- 0
That should work ;)Code:--the creatures table creature = {} creature[1] = { x = 10, y = 10 } --what area are u in??? currentarea = 0 --the width and height of screen screenwidth = 480 screenheight = 272 --new area if creature[1].x >= screenwidth then currentarea = currentarea + 1 creature[1].x = 10 -- sending this guy back to where he started off in the map, but it could be anywhere you want. elseif creature[1].x <= screenwidth - 479 then currentarea = currentarea - 1 end -- if put "creature[1].x <= screenwidth - 479 " so it could change -- even if the player went the other way. if currentarea == 0 then screen:blit(0, 0, area here) elseif currentarea == -1 then screen:blit(0, 0, another area here) elseif currentarea == 1 then screen:blit(0, 0, other shiznit here)
-
12-02-2006, 05:41 AM #4423QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
lol
savagefreak solved the problem GG.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 06:05 AM #4424QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Are yu trying to make an engine where when you hit the edge of the screen you go to a new "area"? I've made a system for doing that and if you'd like you can take a look at it.
-
12-02-2006, 06:13 AM #4425QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
I need some help with my PPP game. (Ping Pong Powerups. It's my first, so...)
Controls for both players work, thanks to EminentJonFrost, and the loader have been fixed thanks to eldiablov.
Now i need ball movement. I have the sprite of the ball, or rather, the image.
So i need a little help on turning it into an object, and help how to make it move random, and collosion with the bat's.
Here is the script:
Help will be greatly apprisiated. (<-- Wrong spelled?)Code:white = Color.new(255, 255, 255) screen:print(136, 136, "Loading LUA Pong...", white) screen.flip() background = Image.load("Background.png") bat11 = Image.load("Bat1.png") bat21 = Image.load("Bat2.png") bat1 = { x = 20, y = 100 } bat2 = { x = 460, y = 100 } screen.waitVblankStart(60) while true do screen:clear() screen:blit(bat1.x, bat1.y, bat11, true) screen:blit(bat2.x, bat2.y, bat21, true) pad = Controls.read() if pad:down() then bat1.y = bat1.y +2 end if pad:up() then bat1.y = bat1.y -2 end if pad:cross() then bat2.y = bat2.y +2 end if pad:triangle() then bat2.y = bat2.y -2 end if pad:start() then break end screen:print(136, 136, "Welcome to the world of PPP.", white) screen.waitVblankStart() screen.flip() endMy PSP Projects:
___________________
None.
-
12-02-2006, 06:43 AM #4426Ponies and Unicorns
- Registriert seit
- Aug 2006
- Ort
- Pelennor Fields
- Beiträge
- 547
- Points
- 5.778
- Level
- 49
- Downloads
- 0
- Uploads
- 0
sure thanks.
Zitat von -TacticalPaper-
If you play WoW come find me on DOOMHAMMER (US) I am Human mage lvl 64 Atrana is the name (dont ask for runs!)
Gold donations are highly appreciated!
-
12-02-2006, 08:14 AM #4427QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
making the ball into an object is actually fairly easy, its same as making the bat into an object, which you have already done.
Zitat von gameo
since this is ping pong, we'll make the ball first appear in the middle of the screen.
what that has done is: give the ball coordinates and an image (basically).Code:ball = { x = 240, y = 146, image = Image.load("ball image") } -- this is the middle of the screen, but blitting an -- image here will make the ball seem a little lower and to the right. -- play with the numbers til you get what you want.
i cant really help you very much with random movement. i'm kinda working on that myself (i hope within a few weeks you'll all see why :) ). i could help with collision though.
this'll make it so that when the ball is at the same vertical point as the bat AND within the image's length (so its touching, which makes sense), it'll do whatever you code in place of "bounce away". also, you might want to do to the 'x' what i did to the 'y'. so that the ball collides on more than just the one point, unless your bat is a single pixel wide.Code:if ball.x == bat.x and ball.y >= bat.y and ball.y < [bats image length] then bounce away end
-= Double Post =-
quick question: what was the command to draw a rectangle? the psdevwiki site is down...Geändert von EminentJonFrost (12-02-2006 um 08:14 AM Uhr) Grund: Automerged Doublepost
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 08:17 AM #4428QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
screen.fillRect(x,y,w,h)
or
screen.drawLine(sx,sy,ex, ey) four times
-
12-02-2006, 08:23 AM #4429QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
hmm...so there isnt an actual command for it..oh well. Thanks!:)
Zitat von -TacticalPaper-
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 08:26 AM #4430QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Well screen.fillRect() is, but it fills in the rectangle/square as well.
-
12-02-2006, 08:30 AM #4431QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
yea, i know, i just need to draw the border of a rectangle. kinda like a frame for a health bar. well, actually, it'll do. i'll just put another rectangle over it in the background's color. problem solved!
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 08:32 AM #4432QJ Gamer Bronze
- Registriert seit
- Sep 2006
- Ort
- Denmark
- Beiträge
- 664
- Points
- 9.316
- Level
- 64
- Downloads
- 0
- Uploads
- 0
Error: index.lua 27: unexpected symbol near [
Press start to restart.
Hmm?
Here is the modified script:
white = Color.new(255, 255, 255)
screen
rint(136, 136, "Loading LUA Pong...", white)
screen.flip()
background = Image.load("Background.pn g")
bat11 = Image.load("Bat1.png")
bat21 = Image.load("Bat2.png")
bat1 = { x = 20, y = 100 }
bat2 = { x = 460, y = 100 }
ball = { x = 240, y = 146, image = Image.load("Ball.png") }
screen.waitVblankStart(60 )
while true do
screen:clear()
screen:blit(bat1.x, bat1.y, bat11, true)
screen:blit(bat2.x, bat2.y, bat21, true)
pad = Controls.read()
if ball.x == bat.x and ball.y >= bat.y and ball.x < [16] then
bounce away
end
if pad:down() then
bat1.y = bat1.y +2
end
if pad:up() then
bat1.y = bat1.y -2
end
if pad:cross() then
bat2.y = bat2.y +2
end
if pad:triangle() then
bat2.y = bat2.y -2
end
if pad:start() then
break
end
screen
rint(136, 136, "Welcome to the world of PPP.", white)
screen.waitVblankStart()
screen.flip()
endMy PSP Projects:
___________________
None.
-
12-02-2006, 08:35 AM #4433QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Yea for the border you'll have to draw each line. Also since thatd make it draw 4 lines every loop, id put it on a buffer along with the rest of your non-changing objects.
-
12-02-2006, 08:51 AM #4434QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
wait, put it on a buffer? whats that?
Zitat von -TacticalPaper-

-= Double Post =-
remove the brackets. (i think thats what theyre called)
Zitat von gameo
Geändert von EminentJonFrost (12-02-2006 um 08:51 AM Uhr) Grund: Automerged Doublepost
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 09:31 AM #4435QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Ok do this:
Then for ALL your images and text and stuff that is NEVER changed at all, always stays in the same place, always says the same thing, do this:Code:buffer = Image.createEmpty(480,272)
etc until everything on the screen that never moves has been put onto the image "buffer"Code:buffer:blit(x,y,img) buffer:print(x,y,text,color)
Just treat buffer like screen and put stuff on it until you've got everything put on it, then do this:
That'll put EVERYTHING on the buffer onto the screen. That makes luaplayer blit 1 image rather than blit 5 images, print 4 bits of text, draw 3 lines, etc each loop. It'll make your code more efficient if used properly.Code:while true do blah blah blah screen:blit(0,0,buffer)
But remember, you still have to use screen:blit(x,y,img) for stuff that moves, like the main player or somethin.
-
12-02-2006, 09:56 AM #4436Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von -TacticalPaper-
thats uself for stuff like healthbar, ammo, and maybe levels. although, be careful not to put too much stuff on it, cause itll make it even slower. (cause it has to reference something from outside the loop.)--------------------------------------------------------------------------------------
-
12-02-2006, 11:25 AM #4437QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
oh, ok. buffer is good for stills and leave the rest normal. all right. i'll be sure to use it when i can. my problem with that though is that anything thats not part of the background pic moves. and well, the background is just one pic, would it be faster to put it to the buffer even though i have alot of other stuff moving?
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
12-02-2006, 11:25 AM #4438QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- 6ft. Down Underground........Oh and guess what my avatar is
- Beiträge
- 387
- Points
- 4.918
- Level
- 44
- Downloads
- 0
- Uploads
- 0
How do you compile lua into an EBOOT, ive been searching every were for that tut.....if somebody could point me to the right direction i would be very thankfull.
-
12-02-2006, 11:34 AM #4439QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
ok wait, i will give it to you
ok here it is:
http://www.mediafire.com/?8mwzrgg0dvg
it includes README.txt so u know what to do with it ;)
[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]
-
12-02-2006, 11:45 AM #4440QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- 6ft. Down Underground........Oh and guess what my avatar is
- Beiträge
- 387
- Points
- 4.918
- Level
- 44
- Downloads
- 0
- Uploads
- 0
ok thanks.....my next game will be an eboot so people wont have to screw with that stupid luaplayer
Zitat von myschoo
-= Double Post =-
I downloaded it but.....how do you edit it?Geändert von the undead (12-02-2006 um 11:45 AM Uhr) Grund: Automerged Doublepost


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