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; Yes the character moves. If you were to run the fiel the character would move but then you are supposed ...
-
03-31-2007, 05:40 PM #6481
Yes the character moves. If you were to run the fiel the character would move but then you are supposed to be able to hit triangle to shoot up square to shooot left and so on but when i hit one of those buttons i encounter that error i posted on the last page.
-
03-31-2007, 05:47 PM #6482QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
try this:
wait a sec i got another question about your codeCode:if pad:triangle() and BulletInfo[i].direction == "up" then BulletInfo[i].y = BulletInfo[i].y - 10 end end
you have BulletInfo[a] but every where else you put BulletInfo[i], maybe taht has something to do with your errorCode:BulletInfo[a] = { pic = bullet , firing = false, direction = "right", x = Player[1].x + 32, y = Player[1].y + 16 } end
-
03-31-2007, 06:02 PM #6483
Ok here is a code that acccesdenied helped me with that runs put does not shoot. Maybe we should start here then add to it and try to get it to shoot.
Code:green=Color.new(0,255,0) grass=Image.load("grass.png") player=Image.load("player.png") tree=Image.load("tree.png") bullet = Image.createEmpty(4,4) bullet:clear(green) screenwidth=480-player:width() screenheight=272-player:width() Player={} Player[1]={x=200, y=50} oldpad = Controls.read() currentBullet = 0 BulletInfo = {} for a = 1,800 do BulletInfo[a] = { pic = bullet , firing = false, direction = "right", x = Player[1].x + 32, y = Player[1].y + 16 } end function bulletSetup() if currentBullet < 800 then currentBullet = currentBullet + 1 else currentBullet = 1 end end function bulletFire() for i = 1,800 do if BulletInfo[i].firing == true then screen:blit(BulletInfo[i].x,BulletInfo[i].y,BulletInfo[i].pic) end if BulletInfo[i].x < 0 or BulletInfo[i].x > 480 or BulletInfo[i].y < 0 or BulletInfo[i].y > 272 then BulletInfo[i].firing = false end end end while true do pad=Controls.read() screen:clear() bulletSetup() for a=0, 14 do for b=0, 8 do screen:blit(32 * a, 32 * b, grass) end end screen:blit(100,100,tree) screen:blit(300,220,tree) screen:blit(87,46,tree) screen:blit(400,150,tree) screen:blit(Player[1].x,Player[1].y,player) if pad:left() and Player[1].x>0 then Player[1].x=Player[1].x-3 end if pad:right() and Player[1].x<screenwidth then Player[1].x=Player[1].x+3 end if pad:up() and Player[1].y>0 then Player[1].y=Player[1].y-3 end if pad:down() and Player[1].y<screenheight then Player[1].y=Player[1].y+3 end if pad:triangle() then if BulletInfo[i].direction == "up" then BulletInfo[i].y = BulletInfo[i].y - 10 end end if pad:circle() then if BulletInfo[i].direction == "right" then BulletInfo[i].x = BulletInfo[i].x + 10 end end if pad:cross() then if BulletInfo[i].direction == "down" then BulletInfo[i].y = BulletInfo[i].y + 10 end end if pad:square() then if BulletInfo[i].direction == "left" then BulletInfo[i].x = BulletInfo[i].x - 10 end end bulletFire() screen.waitVblankStart() screen.flip() end
-
03-31-2007, 06:03 PM #6484QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
? could you plz break that sentence up for me, there's no commas, and that threw me off
-
03-31-2007, 06:05 PM #6485
NVM hold on that code is not running right anymore.
Well that one gets the same error as the last one. To restat that sentence, that code is a code that AccessDenied helped me with. It did run but it does not seem to anymore. I hope i typed this one better.
And thanks for all the help by the way
-= Double Post =-
There i just tryed that code and it worked. But when i hit the button to shoot i get the error.Code:green=Color.new(0,255,0) grass=Image.load("grass.png") player=Image.load("player.png") tree=Image.load("tree.png") bullet = Image.createEmpty(4,4) bullet:clear(green) screenwidth=480-player:width() screenheight=272-player:width() Player={} Player[1]={x=200, y=50} oldpad = Controls.read() currentBullet = 0 BulletInfo = {} for a = 1,800 do BulletInfo[a] = { pic = bullet , firing = false, direction = "right", x = Player[1].x + 32, y = Player[1].y + 16 } end function bulletSetup() if currentBullet < 800 then currentBullet = currentBullet + 1 else currentBullet = 1 end end function bulletFire() for i = 1,800 do if BulletInfo[i].firing == true then screen:blit(BulletInfo[i].x,BulletInfo[i].y,BulletInfo[i].pic) end if BulletInfo[i].x < 0 or BulletInfo[i].x > 480 or BulletInfo[i].y < 0 or BulletInfo[i].y > 272 then BulletInfo[i].firing = false end end end while true do pad=Controls.read() screen:clear() bulletSetup() for a=0, 14 do for b=0, 8 do screen:blit(32 * a, 32 * b, grass) end end screen:blit(100,100,tree) screen:blit(300,220,tree) screen:blit(87,46,tree) screen:blit(400,150,tree) screen:blit(Player[1].x,Player[1].y,player) if pad:left() and Player[1].x>0 then Player[1].x=Player[1].x-3 end if pad:right() and Player[1].x<screenwidth then Player[1].x=Player[1].x+3 end if pad:up() and Player[1].y>0 then Player[1].y=Player[1].y-3 end if pad:down() and Player[1].y<screenheight then Player[1].y=Player[1].y+3 end if pad:triangle() then if BulletInfo[i].direction == "up" then BulletInfo[i].y = BulletInfo[i].y - 10 end end if pad:circle() then if BulletInfo[i].direction == "right" then BulletInfo[i].x = BulletInfo[i].x + 10 end end if pad:cross() then if BulletInfo[i].direction == "down" then BulletInfo[i].y = BulletInfo[i].y + 10 end end if pad:square() then if BulletInfo[i].direction == "left" then BulletInfo[i].x = BulletInfo[i].x - 10 end end bulletFire() screen.waitVblankStart() screen.flip() endGeändert von Bob Hoil (03-31-2007 um 06:08 PM Uhr) Grund: Automerged Doublepost
-
03-31-2007, 06:09 PM #6486QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
well you still have that BulletInfo[a] did it work when you changed the [a] to [i]?
-
03-31-2007, 06:15 PM #6487
i got a table error
-= Double Post =-
When i put a instead of iGeändert von Bob Hoil (03-31-2007 um 06:15 PM Uhr) Grund: Automerged Doublepost
-
03-31-2007, 07:21 PM #6488
Zitat von Urameshi
...
Zitat von Bob Hoil
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-01-2007, 01:36 AM #6489
hi,
i just started with lua, so im a complete noob. i did some of the tutorials and they were quite helpfull, and now im just making small, pointless games to get better at it. my question is, if my sprite would only be black on a white background, do i get any advanteges, eg the game running smoother, if i "wrote" the sprite in lua, so its not a picture/image?
2nd question: i got the free sprites on evilmana.com, but they still have white around them and if i would use it , it would still be in a white square, so u wont see the background or the floor, can that white be made invisible or just "deleted" ?
-
04-01-2007, 01:43 AM #6490QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
1st question:
i think if you just create Image.createEmpty(32,32) it will be faster then making 32x32 picture in paint
2nd q:
those are gifs, so they should have invisible bg...[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]
-
04-01-2007, 01:49 AM #6491
if i had no images in a game at all, how much better would it run? and is it worth the effort?
Geändert von nUke_moose (04-01-2007 um 02:38 AM Uhr)
-
04-01-2007, 10:08 AM #6492
- Registriert seit
- Sep 2006
- Beiträge
- 484
- Points
- 8.718
- Level
- 62
- Downloads
- 0
- Uploads
- 0
I have a couple lua questions:
1) Can you rotate images in lua. If so how?
2) Can you zoom into images? If so how?
3) Can you blit images from a sprite sheet? if so how?
Ex:
aaabbbccc
aaabbbccc
dddeeeffff
dddeeeffff
dddeeeffff
gggggggg
So how would I only blit the 'e' section of the image.
Thx in advance
-
04-01-2007, 10:39 AM #6493
Hey guys i need some help with my code. I am combining tutorials to make a small game to help me learn lua. This is my code but when i try to shoot i get a nil value error. Can anyone help me out here. I changed it a little from the last code i posted a while back but still get the same error.
Code:green=Color.new(0,255,0) grass=Image.load("grass.png") player=Image.load("player.png") tree=Image.load("tree.png") bullet = Image.createEmpty(4,4) bullet:clear(green) screenwidth=480-player:width() screenheight=272-player:width() Player={} Player[1]={x=200, y=50} oldpad = Controls.read() currentBullet = 0 BulletInfo = {} for a = 1,800 do BulletInfo[a] = { pic = bullet , firing = false, direction = "right", x = Player[1].x + 32, y = Player[1].y + 16 } end function bulletSetup() if currentBullet < 800 then currentBullet = currentBullet + 1 else currentBullet = 1 end if direction == "left" then BulletInfo[currentBullet].x = Player[1].x BulletInfo[currentBullet].y = Player[1].y + 16 end if direction == "right" then BulletInfo[currentBullet].x = Player[1].x + 32 BulletInfo[currentBullet].y = Player[1].y + 16 end if direction == "up" then BulletInfo[currentBullet].x = Player[1].x + 16 BulletInfo[currentBullet].y = Player[1].y end if direction == "down" then BulletInfo[currentBullet].x = Player[1].x + 16 BulletInfo[currentBullet].y = Player[1].y + 32 end BulletInfo[currentBullet].direction = direction BulletInfo[currentBullet].firing = true end function bulletFire() for i = 1,800 do if BulletInfo[i].firing == true then screen:blit(BulletInfo[i].x,BulletInfo[i].y,BulletInfo[i].pic) end if BulletInfo[i].x < 0 or BulletInfo[i].x > 480 or BulletInfo[i].y < 0 or BulletInfo[i].y > 272 then BulletInfo[i].firing = false end end end while true do pad=Controls.read() screen:clear() bulletSetup() for a=0, 14 do for b=0, 8 do screen:blit(32 * a, 32 * b, grass) end end screen:blit(100,100,tree) screen:blit(300,220,tree) screen:blit(87,46,tree) screen:blit(400,150,tree) screen:blit(Player[1].x,Player[1].y,player) if pad:left() and Player[1].x>0 then Player[1].x=Player[1].x-3 end if pad:right() and Player[1].x<screenwidth then Player[1].x=Player[1].x+3 end if pad:up() and Player[1].y>0 then Player[1].y=Player[1].y-3 end if pad:down() and Player[1].y<screenheight then Player[1].y=Player[1].y+3 end if pad:triangle() and BulletInfo[i].direction == "up" then bulletFire() BulletInfo[i].y = BulletInfo[i].y - 10 end if pad:circle() and BulletInfo[i].direction == "right" then bulletFire() BulletInfo[i].x = BulletInfo[i].x + 10 end if pad:cross() and BulletInfo[i].direction == "down" then bulletFire() BulletInfo[i].y = BulletInfo[i].y + 10 end if pad:square() and BulletInfo[i].direction == "left" then bulletFire() BulletInfo[i].x = BulletInfo[i].x - 10 end screen.waitVblankStart() screen.flip() end
-
04-01-2007, 12:08 PM #6494QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
@pspfreak
ex:
1st line: Sasuke is the spritesheetCode:Sasuke=Image.load(where ever the file is) r1=Image.createEmpty(66,45) r1:blit(0,0,Sasuke,0,3,66,45)
2nd line: r1 is the name and Image.createEmpty is making a blank image the size of 66,45
3rd line: r1 is the name and you blit it from 0,0 which is the size of the whole sprite sheet
and Sasuke is the sprite sheet
the 0,3 is where it is on the sprite sheet and 66,45 is the size
now all you have to do is basically put it like that but sub in your own info
-
04-01-2007, 01:27 PM #6495
while that does work, creating new images like that uses up memory. A better way to do it is to skip over the image create and just blit directly to the screen:
screen:blit(0,0,Sasuke,0, 3,66,45)
-
04-01-2007, 02:27 PM #6496
- Registriert seit
- Sep 2006
- Beiträge
- 484
- Points
- 8.718
- Level
- 62
- Downloads
- 0
- Uploads
- 0
cool thanks
EDIT:
what about rotating images?
-
04-01-2007, 06:22 PM #6497
there are a few different ways to do that (check the evilmana codebase for one of them)
however, doing it that way is slow, so in order to keep your program running smoothly you'd have to pre-render the rotated images, which again will eat up your free memory. The only other way to do it that I've found uses the 3d gu, and while using the 3d functions is fast, but that it doesn't work well when you try to combine it with regular 2d blits
-
04-02-2007, 03:30 AM #6498.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0
Damn why won't this work!
It's not detecting collision (no im not dumb i have the function) for some reason to do with the loop, and out of the loop it wont detect anywayCode:for i = 1,100 do coinx = i*x screen:blit(olx + coinx, oly, coinage[i]) coinage[i]:blit(0,0,coin) if collision(mariox, marioy, 47, 55, coinx, oly, 25, 25) then coinage[i]:clear() coins = coins + 1 end end
Please help!
-
04-02-2007, 01:07 PM #6499
maybe you need to use olx+coinx when you call the collision function?
-
04-02-2007, 03:57 PM #6500
heyyy hay there this is my fiorst post in this forum, well i was learning somthing about lua stuff here is a code for make a simple starfield by the way does any body know how to, a = a + 1 like a++ or a:+1 or a+=1
this is a common addition in some languages.. but i cant find how to do on lua
heres is my starfield code:
Code:System.usbDiskModeActivate() blanco = Color.new(255,255,255) width = 480 height = 272 offscreen = Image.createEmpty(width,height) maxstars = 200 maxzlevel = 5 time1 = 0 starfield = {} math.randomseed(os.time()) function createStar(i) starfield[i] = {} starfield[i].x = math.random(width-1) starfield[i].y = math.random(height-1) starfield[i].z = math.random(maxzlevel) grey = (255/maxzlevel)*starfield[i].z starfield[i].color = Color.new(grey,grey,grey) starfield[i].colorb = Color.new(grey*2,grey*2,grey*2) starfield[i].speed = starfield[i].z*0.5 end for i = 1, maxstars do createStar(i) end function drawstars() for i = 1, maxstars do if starfield[i].speed < 1 then zise = 1 else zise = starfield[i].speed end if math.mod(time1,math.random(100)) == 0 then offscreen:fillRect(starfield[i].x-starfield[i].speed/2,starfield[i].y-starfield[i].speed/2,zise,zise,starfield[i].colorb) else offscreen:fillRect(starfield[i].x-starfield[i].speed/2,starfield[i].y-starfield[i].speed/2,zise,zise,starfield[i].color) end --offscreen:print(starfield[i].x+5,starfield[i].y,starfield[i].z,starfield[i].color) starfield[i].y = starfield[i].y + starfield[i].speed if starfield[i].y > height-1 then starfield[i].y = 0 starfield[i].x = math.random(width-1) end end end while true do time1 = time1 + 1 screen:clear() offscreen:clear() drawstars() screen:blit(0,0,offscreen,false) screen.flip() screen:waitVblankStart() pad = Controls.read() if pad:start() then break end endGeändert von ahrimanes (04-03-2007 um 06:32 PM Uhr)
-
04-02-2007, 04:01 PM #6501lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Dont you have to fill in the width and height part first?Code:offscreen = Image.createEmpty(width,h eight)
-= Double Post =-
Also, a = a + 1
You can do that in Lua, Just do that
Code:a = 0 )blah blah) a = a + 1
Geändert von Anti-QJ (04-02-2007 um 04:03 PM Uhr) Grund: Automerged Doublepost
-
04-02-2007, 07:25 PM #6502Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
just a reminder people, PLEASE USE TAB. you're code is so messy i dont even want to look at it. (talking to everybody here)
--------------------------------------------------------------------------------------
-
04-02-2007, 07:28 PM #6503QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Lol, you are right. Agreed.
Zitat von Grimfate126
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
04-02-2007, 07:43 PM #6504
...he did. Shine put the values on the line right before it. Look next time.
Zitat von Anti-QJ
Zitat von Anti-QJ

wtf? He was asking how to do it differently! He already typed a = a + 1, but he was asking how to do a shortcut. Read next time. The answer is there is no other way.
I am begining to think that you are here simply to (A) Raise your post count and (B) confuse n00bs even more. Please stop.牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-02-2007, 08:39 PM #6505lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
(C) I misread. Bingo!
Zitat von youresam
-= Double Post =-
Wouldn't you just put,
Code:offscreen = Image.createEmpty(480, 272)
Geändert von Anti-QJ (04-02-2007 um 08:40 PM Uhr) Grund: Automerged Doublepost
-
04-02-2007, 09:01 PM #6506
No, actually learn lua before you come here and try to help. Image.createEmpty takes 2 number arguements, and he passed them through the variables width and height.
Zitat von Anti-QJ
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-02-2007, 09:17 PM #6507
As said by abe froeman: "Keep everything that happens away from the forums, away from the forums"
Zitat von Anti-QJ
kthx.牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-03-2007, 07:46 AM #6508
wwwtfff... i copyed my code fron my text editor, sooo why my "tabs" is not working here,, i tried to edit the post and see it have "tabs".... wyyyyyyyyyyy.......
by the way... im just using height, width, i feell bether whit them example scrcenter = {x = height/2, y = width/2}.
here is another interesting code.
hope this help to understand the rgb. of color,,, seyaaaaCode:while true do screen:clear() for x = 0, 255 do for y = 0 , 255 do screen:pixel(x,y,Color.new(x,y,128)) end end screen:flip() screen:waitVblankStart() pad = Controls.read() if pad:start() then break end end
haa b the way does any body knows how to read the item count of an array ? i mean somthing like......
a = {}
a[1].x = 10
a[2].x = 20
then i want to know how many itemss a got.. like count = a.itemcount() or count = a.listcount() then count should be 2 in this case.
???Geändert von ahrimanes (04-03-2007 um 06:30 PM Uhr)
-
04-03-2007, 12:20 PM #6509
wrap it in the [code] tag...
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-03-2007, 03:15 PM #6510
count = table.getn(a) will give you the number of entries in the table
Zitat von ahrimanes


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