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 you could do sometin like this: me = 5 you = 6 them = 7 nine = 9 screen:drawline(me,you,th ...
-
05-27-2006, 07:50 AM #2491QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
yes you could do sometin like this:
me = 5
you = 6
them = 7
nine = 9
screen:drawline(me,you,th em,nine,red)
they just use x0,y0,x1,y1 as examples you could call variables whatever you want it don't matter
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
05-27-2006, 07:52 AM #2492QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Thanks everybody!
-
05-27-2006, 11:45 AM #2493QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
drawing a curved line?
how about those old "y = x^2" (i think its like that...) formulas?
anyone whos used a graphing calculator should know what i mean. you can make the "y" be the position of the pixels, right?
and then make a "for" loop so that the pixels make a (curved) line.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-27-2006, 11:46 AM #2494QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
I'll try that. But I'm having trouble with this code:
Yes I'm trying to make a pong game, but the rectangles wont show up.Code:black = Color.new(0, 0, 0) white = Color.new(255, 255, 255) grey = Color.new(127,127,127) red = Color.new(255, 0, 0) green = Color.new(0, 255, 0) blue = Color.new(0, 0, 255) yellow = Color.new(255,255,0) purple = Color.new(120,0,120) pink = Color.new(255,0,255) orange = Color.new(255,110,0) width = 50 height = 100 x = 10 y = 136 x1 = 470 y1 = 136 screencolor = white paddlecolor = black while true do screen:clear(white) pad = Controls.read() if pad:up() then y = y + 2 screen.waitVblankStart(4) end if pad:down() then y = y - 2 screen.waitVblankStart(4) end if pad:cross() then y1 = y1 - 2 screen.waitVblankStart(4) end if pad:triangle() then y1 = y1 + 2 screen.waitVblankStart(4) end if y1 <= -1 then y1 = 0 end if y <= -1 then y = 0 end if y <= 273 then y = 272 end if y1 <= 273 then y1 = 272 end screen:fillRect(x,y,width,height,black) screen:fillRect(x1,y1,width,height,black) screen.waitVblankStart() screen.flip() end
-
05-27-2006, 12:01 PM #2495QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
try switching back the colors. (blocks are white, background is black.)
and leave the "screen:clear()" alone, so it doesnt mention a color.[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-27-2006, 12:07 PM #2496QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Meh, I took white out of screen:clear(), and changed the color of the paddles to white, and it didn't show up still. I guess I'll use pre-set images, or Image.createEmpty.
Zitat von EminentJonFrost
-
05-27-2006, 12:27 PM #2497QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
wait, isnt it supposed to be "drawRect" instead of "fillRect"?
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-27-2006, 01:04 PM #2498QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Whne I tried that it gave me that drawRect was a nil value.
Zitat von EminentJonFrost
-
05-27-2006, 01:26 PM #2499Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
three things:
Zitat von PSPduh
1. why do you have screen.waitVblankStart(4) after everytime you move??
2. the screen:fillRect is muuch too complicated for what you need. a simple Image.createEmpty command will work just as fine.
3. thats one big list of colors you got. ;)--------------------------------------------------------------------------------------
-
05-27-2006, 01:36 PM #2500QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
the screen.waitVblankStarts are so the effects of pressing a button dont accidently repeat more than what you want.
Zitat von Grimfate126
i agree with the amount of colors. thats alot. why do you have so many? if its so you dont have to remember them, then put this in your Favorites.
http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-27-2006, 02:24 PM #2501QJ Gamer Gold
- Registriert seit
- Mar 2006
- Ort
- LOLWUT
- Beiträge
- 2.625
- Points
- 18.627
- Level
- 86
- Downloads
- 0
- Uploads
- 0
I dont know why I have so many colors. I just like to have a lot to choose from.
-
05-27-2006, 03:30 PM #2502QJ Gamer Bronze
- Registriert seit
- Aug 2005
- Ort
- Plainfield, IL USA
- Beiträge
- 18
- Points
- 5.744
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Hey
I have a question. I'm using a sprite sheet for a game I'm making. I wanted to ask if anybody can tell me how you set a certain point on the sprite sheet into a variable? For example, as seen on EvilMana:
Well, I wanted to know if you can put the sourcex, sourcey, width, and height into a variable when you load an image instead of using the blit command. I think it will be much easier that way to do animation and such without loading a lot of image files.Code:screen:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])
Any help will be appreciated. Thanks.
ShockD
-
05-27-2006, 04:34 PM #2503
Shock D, if i understand you correctly, then this might answer your question.
You could put:
image = Image.load("image.png")
height = image:height()
width = image:width()
as for sourcex and sourcey, i'm not really even sure what they are/do.
-
05-27-2006, 05:43 PM #2504sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
wats wrong with this code?
Code:while true do screen:clear() screen:blit(0, 0, menu) screen.flip() screen.waitVblankStart(120) end pad = Controls.read() if pad:CROSS() then screen:clear() end i=1 while i<=17 do screen:clear() counter:start() screen:blit(0, 0, background) screen:print(5, 100, questions[i], black) screen:print(5, 200, answerOne[i], white) screen:print(5, 215, answerTwo[i], white) screen:print(5, 230, answerThree[i], white) screen:print(5, 245, answerFour[i], white) inputreceived=0 screen.flip() screen.waitVblankStart() while inputreceived==0 do pad = Controls.read() if pad:up() then screen.flip() if correctanswer[i]==1 then screen:print(5, 110, "You're Correct!", green) else screen:print(5, 110, "Sorry, incorrect.", red) i=0 end inputreceived=1 end if pad:right() then screen.flip() if correctanswer[i]==2 then screen:print(5, 110, "You're Correct!", green) else screen:print(5, 110, "Sorry, incorrect.", red) i=0 end inputreceived=1 end if pad:left() then screen.flip() if correctanswer[i]==3 then screen:print(5, 110, "You're Correct!", green) else screen:print(5, 110, "Sorry, incorrect.", red) i=0 end inputreceived=1 end if pad:down() then screen.flip() if correctanswer[i]==4 then screen:print(5, 110, "You're Correct!", green) else screen:print(5, 110, "Sorry, incorrect.", red) i=0 end inputreceived=1 end end i = i+1 screen.flip() screen.waitVblankStart(120) end while true do screen:clear() counter:stop() currentTime = counter:time() screen:print(10,10,"Your time is " .. currentTime,red) screen.flip() screen.waitVblankStart(240) end
-
05-27-2006, 05:45 PM #2505
io.open
im working right now on a load/save feature for my game, loading is easy but when it come to saving:
file = io.open("loadsave/posx.txt","w")
file:write("posx = ".. posx )
file:write()
file:close()
this will save "posx = 0" (example) on a file, yeah, but how could i save more then 1 value, mutli-lines.
-
05-27-2006, 06:05 PM #2506
bronxbomber92, i believe your code should read :
if pad:cross() the cross shouldn't be in caps.
-
05-27-2006, 06:06 PM #2507TheMarioKartersGuest
bronx, the cross shouldn't be caps!
EDIT: I was beat..
-
05-27-2006, 06:26 PM #2508
Yes, i actually beat someone :)
-
05-27-2006, 06:27 PM #2509QJ Gamer Bronze
- Registriert seit
- Aug 2005
- Ort
- Plainfield, IL USA
- Beiträge
- 18
- Points
- 5.744
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Thanks for the reply emericaska8r.
Zitat von emericaska8r
The sourcex and sourcey tells the program where to get the width and height from the image. For example, if you have 4 sprites on the sheet, for sourcex you would have to specify how many pixels to the right the 4th sprite is and same with sourcey. Eh... I hope you understood that. If not then oh well.
Well anyway, that is a good idea. I'm going to play with that for awhile.
Much thanks,
ShockD
Edit: Damn... this stuff is frustrating. When I load my game into the PSP, the background image becomes all distorted (the image is a jpg). It works fine with the windows LUA player. When I convert it into a .png it says error loading image. I set the correct path and extention all right.
Also, it's a bit laggy but I think I know why. If anyone has some pointers on getting rid of lag, that would be great.
Thanks again,
ShockDGeändert von ShockD (05-27-2006 um 09:34 PM Uhr)
-
05-28-2006, 05:01 AM #2510sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
i tried that in windows lua player both ways, but the main menu screen would appear but when i press "c" (which is cross on windows) nothing happens, so it doesnt go on to the rest of the code. any help with that? thanks
Zitat von emericaska8r
-
05-28-2006, 06:05 AM #2511QJ Gamer Bronze
- Registriert seit
- Aug 2005
- Ort
- Plainfield, IL USA
- Beiträge
- 18
- Points
- 5.744
- Level
- 48
- Downloads
- 0
- Uploads
- 0
@bronxbomber92
In your screen.waitVblankStart, why is there a 12, two spaces, then a zero? I'm just curious as to what that zero does. And also, shouldn't all of that code (the one outside the main loop with the Controls.read()) be in a function?
ShockD
-
05-28-2006, 06:13 AM #2512
the spaces are because of the formatting of the text of this forum. It should read screen.waitVblankStart(12 0). The 120 means it waits 120 cycles of the screen refreshing. So that means it waits 2 seconds, since the refreshing rate is 60 Hz.
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
05-28-2006, 06:13 AM #2513sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
theere isnt really two spaces, the forum did that...and i dont think the Controls.read() should be in a function. if u look lower in the code i have a controls.read() and that works their. so no, i don't think so
Zitat von ShockD
-
05-28-2006, 06:35 AM #2514QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
like this, agashka:
Code:file = io.open("loadsave/posx.txt","w") file:write("posx = ".. posx\n"posx2 = " ..posx2) file:close()[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-28-2006, 07:48 AM #2515QJ Gamer Bronze
- Registriert seit
- Aug 2005
- Ort
- Plainfield, IL USA
- Beiträge
- 18
- Points
- 5.744
- Level
- 48
- Downloads
- 0
- Uploads
- 0
Yeah that's what I was thinking too. Oh yeah, Altair, I saw your post in the ps2dev site and I was wondering if you could tell me how you used a 1000x1000 image without any distortion or anything?
Zitat von Altair
Thanks.
-
05-28-2006, 07:50 AM #2516Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von ShockD
its not possible to load images greater than 480x272 in luaplayer unless there is a version i dont know about. youll just have to make seperate images i guess.--------------------------------------------------------------------------------------
-
05-28-2006, 08:37 AM #2517Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
hi, i have an analog problem. here is my code:
when i move the analog nub right then player goes right, BUT when i move it left, the player STILL goes right. help.Code:function movePlayer() pad = Controls.read() dx = pad:analogX() if math.abs(dx) < -100 then Player[1].x = Player[1].x - 5 playerpic = 1 goingf = true elseif math.abs(dx) > 120 then Player[1].x=Player[1].x + 5 playerpic = 2 goingb = true end end
--------------------------------------------------------------------------------------
-
05-28-2006, 09:38 AM #2518QJ Gamer Bronze
- Registriert seit
- Aug 2005
- Ort
- Plainfield, IL USA
- Beiträge
- 18
- Points
- 5.744
- Level
- 48
- Downloads
- 0
- Uploads
- 0
It's not possible to load an image greater than 512x512. Yeah that's exactly what I did so thanks anyway.
Zitat von Grimfate126
ShockD
-
05-28-2006, 10:37 AM #2519QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
the absolute value of "dx" should not be able to be less than negative100.Code:function movePlayer() pad = Controls.read() dx = pad:analogX() if math.abs(dx) < -100 then Player[1].x = Player[1].x - 5 playerpic = 1 goingf = true elseif math.abs(dx) > 120 then Player[1].x=Player[1].x + 5 playerpic = 2 goingb = true end end
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
05-28-2006, 11:16 AM #2520Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von EminentJonFrost
so how would i fix it. sry, im a total n00b at analog controls. it would have been much easier if it was like:
but life aint fair. thx for the help!Code:if analog:right() then ... blah
--------------------------------------------------------------------------------------


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