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; how would i go about stopping the timer on a specific time? (5 Min. or 10Min.) Sorry for all the ...
-
08-17-2008, 04:44 PM #9271QJ Gamer Green
- Registriert seit
- Nov 2007
- Beiträge
- 6
- Points
- 2.866
- Level
- 32
- Downloads
- 0
- Uploads
- 0
how would i go about stopping the timer on a specific time? (5 Min. or 10Min.)
Sorry for all the questions ^^
Code:TIMER: screen:clear() System.usbDiskModeActivate() red = Color.new(255, 0, 0) grey = Color.new(94, 97, 111) screen:print(13, 5, "Press L-Trigger to ARM BOMB and R-Trigger to DISARM BOMB.", grey) screen:flip() Timer = Timer.new(0) while true do screen.waitVblankStart(5) pad = Controls.read() if pad:l() then Timer:reset() Timer:start() while true do pad = Controls.read() screen:clear() screen:print(13, 5, "Press L-Trigger to ARM BOMB and R-Trigger to DISARM BOMB.", grey) screen:print(220, 133, tostring(math.floor(Timer:time()/1000/60) .. ":" .. math.floor((Timer:time()/1000/60-math.floor(Timer:time()/1000/60))*60) .. ":" .. string.sub(tostring(math.floor(Timer:time()/10)), -2)), red) screen:flip() if pad:r() then Timer:stop() break end end elseif pad:start() then dofile("script.lua") end end
Geändert von psporpcp (08-17-2008 um 08:45 PM Uhr)
-
08-17-2008, 09:45 PM #9272QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
See http://wiki.ps2dev.org/psp:lua_playe...lisecond_timer
Timer:time()
-
08-18-2008, 04:58 AM #9273Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Is there a way to draw a Square grid to the screen using lua(NO IMAGES)??
-
08-18-2008, 05:31 AM #9274words 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
dan - is there a drawLine function in Lua?
With those parameters set that'll draw a green 10x10 grid in the center of the screen with each grid square being 10x10 as well. Modular programming ftw...Code:SQUARE_SIZE = 10 -- how many pixels per grid square GRID_WIDTH = 10 -- how many squares across GRID_HEIGHT = 10 -- how many squares down GRID_COLOR = Color.new(0,255,0) -- color of the grid lines GRID_OFFSET_X = 240 - SQUARE_SIZE * GRID_WIDTH / 2 -- offset the grid on the X axis by this many pixels GRID_OFFSET_Y = 136 - SQUARE_SIZE * GRID_HEIGHT / 2 -- " " " " " Y " " " " " function drawGrid(target) for y = 0, GRID_HEIGHT do for x = 0, GRID_WIDTH do -- draws lines from the top of the grid to the bottom going across target:drawLine(x * SQUARE_SIZE + GRID_OFFSET_X, GRID_OFFSET_Y, x * SQUARE_SIZE + GRID_OFFSET_X, SQUARE_SIZE * GRID_HEIGHT + GRID_OFFSET_Y, GRID_COLOR) -- draws lines from the left of the grid to the right going down target:drawLine(GRID_OFFSET_X, y * SQUARE_SIZE + GRID_OFFSET_Y, SQUARE_SIZE * GRID_WIDTH + GRID_OFFSET_X, y * SQUARE_SIZE + GRID_OFFSET_Y, GRID_COLOR) end end end drawGrid(screen) screen.flip() while not Controls.read():cross() do end
...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
-
08-18-2008, 05:33 AM #9275QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Pff, beaten.
Code:WIDTH = 10 HEIGHT = 10 SPACING = 10 white = Color.new(255, 255, 255) for i = 0, WIDTH do screen:drawLine(i * SPACING, 0, i * SPACING, HEIGHT * SPACING, white) end for i = 0, HEGIHT do screen:drawLine(0, i * SPACING, WIDTH * SPACING, i * SPACING, white) end
-
08-18-2008, 06:09 AM #9276Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Thanks, damn forgot about drawLine.
-
08-18-2008, 08:01 AM #9277Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
i suggest drawing the lines to one singular Image.createEmpty() and then blitting that image to the screen it might speed it up slightly, rather than doing as show in the examples 20 loops and draw lines each time you go through the main while loop
from what i understand you meant no image files.------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
08-18-2008, 08:27 AM #9278QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
-
08-18-2008, 08:56 AM #9279QJ Gamer Green
- Registriert seit
- Jul 2008
- Ort
- In your pocket.
- Beiträge
- 192
- Points
- 5.875
- Level
- 49
- My Mood
-
- Downloads
- 0
- Uploads
- 0
I was wondering if this would work
Code:if pad:up() then Adhoc:send(up) endCode:pad = Adhoc:recv() if pad == up then Player.img = Player.img + speed endAIM: Digikid91 | PSN: Digikid13 | GaiaOnline: Digikid13
-
08-18-2008, 08:59 AM #9280QJ Gamer Blue
- Registriert seit
- Dec 2007
- Ort
- Netherlands
- Beiträge
- 148
- Points
- 5.672
- Level
- 48
- Downloads
- 0
- Uploads
- 0
i think u should send a string like "padButtonUp"
and if the received is that string do code.[SIZE="1"][color=#D1D1FF]______________________________________________________________[/color]
[i]Last edited by basfreak; 01-01-1990 at [color=#666686]12:00 PM[/color][/i].[/SIZE]
-
08-18-2008, 09:04 AM #9281Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Yeah, i did mean no images.So bliting images is slow?I knew it took up memory but slow?Blitting an image always seemed pretty fast to me.
-
08-18-2008, 09:27 AM #9282QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
You've OBVIOUSLY never made a CPU-intensive game.
-
08-18-2008, 09:58 AM #9283Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
08-18-2008, 10:14 AM #9284QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
For images, yes, one is faster than lots, but drawline is just....
a line.....
a line != an image
-
08-18-2008, 10:21 AM #9285QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
My assumption is that whatever drawline function you are using modifies the the pixels manually, using a line algorithm. If you have access to the GU, which you do, you are better off writing your own function that uses GU_LINES.
-
08-18-2008, 10:33 AM #9286QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Yes and that is certainly MUCH faster but you're forgetting that this person needed help making a grid and thus the GU would be a bit out of his current level.....
-
08-18-2008, 10:59 AM #9287QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Regardless, he should know there is a faster way so when he gains the experience, he can do it the right way.
-
08-18-2008, 02:24 PM #9288QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
Someone should just make a draw line function using the GU anyways so that drawing lines will be so much faster!
-
08-18-2008, 02:30 PM #9289QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Except there are a lot of different ways you would want to do it for different uses and a generic function would have to account for all of that and thus be rather slow in comparison to other unique uses
-
08-18-2008, 04:42 PM #9290words 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
Well, I suppose you could take my drawGrid function and convert it to use fillRect since the 'lines' are at pi/2, pi, 2/3*pi, 2pi and can be represented by a rectangle easily, plus it'd be faster then a drawLine...
fillScreenRect
drawLine:Code:void fillScreenRect(Color color, int x0, int y0, int width, int height) { if (!initialized) return; int skipX = PSP_LINE_SIZE - width; int x, y; Color* data = getVramDrawBuffer() + x0 + y0 * PSP_LINE_SIZE; for (y = 0; y < height; y++, data += skipX) { for (x = 0; x < width; x++, data++) *data = color; } }
Code:static void drawLine(int x0, int y0, int x1, int y1, int color, Color* destination, int width) { int dy = y1 - y0; int dx = x1 - x0; int stepx, stepy; if (dy < 0) { dy = -dy; stepy = -width; } else { stepy = width; } if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; } dy <<= 1; dx <<= 1; y0 *= width; y1 *= width; destination[x0+y0] = color; if (dx > dy) { int fraction = dy - (dx >> 1); while (x0 != x1) { if (fraction >= 0) { y0 += stepy; fraction -= dx; } x0 += stepx; fraction += dy; destination[x0+y0] = color; } } else { int fraction = dx - (dy >> 1); while (y0 != y1) { if (fraction >= 0) { x0 += stepx; fraction -= dy; } y0 += stepy; fraction += dx; destination[x0+y0] = color; } } }
...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
-
08-20-2008, 02:53 AM #9291QJ Gamer Bronze

- Registriert seit
- Dec 2007
- Ort
- B.F.
- Beiträge
- 328
- Points
- 7.257
- Level
- 56
- My Mood
-
- Downloads
- 1
- Uploads
- 0
Lua Bind Error Using Netlib
Got a Little trouble when using Yourseam's Netlib Library.
Its returns: error index lua (Line 52) : Bind Error
here is the 52th Line:
Code:serverSocket = Socket.createServerSocket(17852)
and the whole code:
Code:selec = 1 noms = "serveur 1" blanc = Color.new(255,255,255) noir = Color.new(0,0,0) ip = Wlan.getIP() fleche = Image.load("images/epee.png") fd = Image.load("images/co.png") fi = io.open("nom.txt" , "r") fdc = fi:read("*n") fi:close() oldpad = Controls.read() while true do screen:clear() pad = Controls.read() screen:blit(0,0,fd) dofile("netlib.lua") netlib_server = "66.25.53.65" netconnect() if selec == 0 then selec = 1 end if selec == 3 then selec = 2 end if selec == 1 then screen:blit(40,60,fleche) end if selec == 2 then screen:blit(162,181,fleche) end if pad:down() and oldpad:down() ~= pad:down() then selec = selec + 1 end if pad:up() and oldpad:up() ~= pad:up() then selec = selec - 1 end serverSocket = Socket.createServerSocket(17852) --Here is the Line of error if pad:cross() and oldpad:cross() ~= pad:cross() and selec == 1 then Socket.connect(netlib_server, 17852) if Socket:isConnected() == "true" then dofile("carte1-1.lua") end end if pad:cross() and oldpad:cross() ~= pad:cross() and selec == 2 then System.message("Voulez-vous quitter le jeu ?", 1) Bouton = System.buttonPressed(1) if Bouton == "Yes" then System.Quit() end end screen:print(400,0,ip,blanc) screen:print(85,77,noms,noir) screen.flip() screen.waitVblankStart() oldpad = pad end
-
08-20-2008, 03:05 AM #9292QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
You're loading netlib and then starting the connection every single loop. Those last three lines belong BEFORE your main loop.Code:while true do screen:clear() pad = Controls.read() screen:blit(0,0,fd) dofile("netlib.lua") netlib_server = "66.25.53.65" netconnect()
And then why are you creating a server socket in the first place for using netlib? No need to......
Also, you should indent your code and it would be a lot easier to read.
-
08-21-2008, 01:02 PM #9293QJ Gamer Green
- Registriert seit
- Jul 2008
- Ort
- In your pocket.
- Beiträge
- 192
- Points
- 5.875
- Level
- 49
- My Mood
-
- Downloads
- 0
- Uploads
- 0
How do you get luaplayer to check the music folder for an mp3 and play all of them one after another.
AIM: Digikid91 | PSN: Digikid13 | GaiaOnline: Digikid13
-
08-21-2008, 01:08 PM #9294QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Open the folder with listDirectory, loop through the list and play it if its a .mp3
-
08-21-2008, 03:11 PM #9295QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Usually, raping LuaPlayer with a large metal pipe will get it to do whatever you want. Just make sure it knows who its daddy is.
-
08-21-2008, 03:21 PM #9296QJ Gamer Green
- Registriert seit
- Jul 2008
- Ort
- In your pocket.
- Beiträge
- 192
- Points
- 5.875
- Level
- 49
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Can you post a code example thanks.
AIM: Digikid91 | PSN: Digikid13 | GaiaOnline: Digikid13
-
08-21-2008, 03:25 PM #9297QJ Gamer Green
- Registriert seit
- Jan 2008
- Beiträge
- 612
- Points
- 3.721
- Level
- 38
- Downloads
- 0
- Uploads
- 0
I made it as simple as it gets.
Open the directory and get a listing with System.listDirectory
Loop through the items with a for loop
Play each one
What more is there to it? Asking for code indicates incompetence and a copynpasting noob. Try to do it yourself and ask for help on EXACTLY what you can't figure out.
-
08-21-2008, 03:27 PM #9298QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
hahahahahahaUsually, raping LuaPlayer with a large metal pipe will get it to do whatever you want. Just make sure it knows who its daddy is.
lol thats halarious
-
08-21-2008, 03:38 PM #9299QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
On a serious note, I was looking through the docs, and found this function:
You should try that.Code:System.PlayAllMp3sInASpecificDirectoryOneAfterTheOther(dirname)
-
08-21-2008, 03:50 PM #9300QJ Gamer Blue
- Registriert seit
- Apr 2008
- Beiträge
- 497
- Points
- 4.268
- Level
- 41
- Downloads
- 0
- Uploads
- 0
lol


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