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; on lua for windows, it doesnt report an error, but nothing pops up on the screen. Code: background = Image.load("Cursor/background.png") ...
-
04-16-2006, 06:29 PM #1651QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- The Migrant Fleet
- Beiträge
- 908
- Points
- 9.678
- Level
- 66
- Downloads
- 0
- Uploads
- 0
on lua for windows, it doesnt report an error, but nothing pops up on the screen.
Code:background = Image.load("Cursor/background.png") mouse = Image.load("Cursor/mouse1.png") blood = Image.load("Cursor/blood.png") enemy = Image.load("Cursor/enemy1.png") mousex = 100 mousey = 172 while true do screen:clear() end pad = Controls.read() screen:blit(0, 0, background, false) screen:blit(mousex, mousey, mouse) if pad:up() then mousey = mousey - 5 end if pad:down() then mousey = mousey + 5 end if pad:left() then mousex = mousex - 5 end if pad:right() then mousex = mousex + 5 end if pad:r() then if mousex == 135 and mousey == 151 then screen:blit(135, 151, blood) end screen.waitVblankStart() screen.flip() end
-
04-16-2006, 06:37 PM #1652Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
montrob: try this:
Code:background = Image.load("Cursor/background.png") mouse = Image.load("Cursor/mouse1.png") blood = Image.load("Cursor/blood.png") enemy = Image.load("Cursor/enemy1.png") mousex = 100 mousey = 172 while true do screen:clear() pad = Controls.read() screen:blit(0, 0, background, false) screen:blit(mousex, mousey, mouse) if pad:up() then mousey = mousey - 5 end if pad:down() then mousey = mousey + 5 end if pad:left() then mousex = mousex - 5 end if pad:right() then mousex = mousex + 5 end if pad:r() and mousex > 130 and mousex < 140 then if mousey > 146 and mousey < 156 then screen:blit(135, 151, blood) end end screen.waitVblankStart() screen.flip() end--------------------------------------------------------------------------------------
-
04-16-2006, 06:39 PM #1653Is in your zone.

- Registriert seit
- Oct 2005
- Ort
- Jacksonville, FL
- Beiträge
- 3.429
- Points
- 24.342
- Level
- 94
- Downloads
- 0
- Uploads
- 0
(at the very end of the code)

--XBL Gamertag: PhenoM904--
-
04-16-2006, 07:43 PM #1654QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
or just take out screen:clear() it just is constantly clearing the screen
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
-
04-17-2006, 11:22 AM #1655QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- The Migrant Fleet
- Beiträge
- 908
- Points
- 9.678
- Level
- 66
- Downloads
- 0
- Uploads
- 0
For my new game, WildSniper , i am going to have bullets shooting from the enemies guns. I need to know how to detect a collision when they moving bullet hits my aimer that is moving.
-
04-17-2006, 01:38 PM #1656Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von montrob
well if you have ur aimer x and y like theis:
and u have the bullets x and y like this:Code:aimerx = 100 amiery= 130
this u just do this:Code:enemyBulletx = 30 enemyBullety = 50
this means that if the bullet comes within 5 pixels of the aimer, then it will do what u want it to do.Code:if enemyBulletx > aimerrx - 5 and enemyBulletx < aimerx + 5 then if enemyBullety > aimerry - 5 and enemyBullety < aimery + 5 then -- the rest of ur code
hope i helped!! good luck!
EDIT- 600th post!! w00t!!!!!!!
--------------------------------------------------------------------------------------
-
04-17-2006, 02:12 PM #1657Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
Does anyone know how to check what the last number is in a table? For example, if I have LUA automatically make a table like this:
is there a way LUA can find the number of the last entry in that table, for example, folders[4] ? Thanks to anyone who can answer my question.Code:folders=System.listDirectory()
Zitat von Noriko
-
04-17-2006, 02:25 PM #1658Mushroom Man
- Registriert seit
- Sep 2005
- Ort
- UK
- Beiträge
- 318
- Points
- 7.283
- Level
- 56
- Downloads
- 0
- Uploads
- 0
Had a look on google, and I found this :)
So you would want folders.getn(t), and then I presume t will hold the number of entries.Code:We can find the size of a table using the standard table library function table.getn() (i.e. get number of elements) table.getn(t)
Source: http://lua-users.org/wiki/TablesTutorialGeändert von Psilocybeing (04-17-2006 um 02:28 PM Uhr)
-
04-17-2006, 02:30 PM #1659Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
Thank you very much! I checked the wiki and but never saw that part of it. Thanks again, Psilocybeing, now custom characters will be easy to implement in my game by just placing in the folder. :icon_smil
Zitat von Psilocybeing
Zitat von Noriko
-
04-17-2006, 02:48 PM #1660Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
One other question. Is there a way that I can quote a variable? Like say I wanted to concatenate a variable, but it needed quotes around it to work. For example:
doesn't work because the folder names don't have quotes around them.Code:folders=System.listDirectory() screen:blit(0,0,"images/"..folders[1].name.."/pic.png")
Because the table is created by LUA, I can't manually add quotes around each entry, so is there a way I could do this when blitting to the screen? Thanks again.
Zitat von Noriko
-
04-17-2006, 02:57 PM #1661Mushroom Man
- Registriert seit
- Sep 2005
- Ort
- UK
- Beiträge
- 318
- Points
- 7.283
- Level
- 56
- Downloads
- 0
- Uploads
- 0
It looks like in LUA the function lua_pushfstring works the same way that sprintf does in C, so you can construct your path variable before passing it to blit. I.e.
otherString = "and so is this"
lua_pushfstring(newString , "This is my string: %s", otherString)
newString = "This is my string: and so is this"
This is just pseudo code, as I've not used LUA before, just trying to be helpfull :)
-
04-17-2006, 02:59 PM #1662Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
Hmmm...I actually understand that lol. I'll try something like that right now and see if it works, thanks a lot.
Zitat von Psilocybeing
Zitat von Noriko
-
04-17-2006, 03:05 PM #1663Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
No go. It's telling me that lua_pushfstring is a nil value.
Zitat von Noriko
-
04-17-2006, 04:07 PM #1664
how do you get windows lua to report errors? whenever i have an error, the screen just pops up and closes real quick.
-
04-17-2006, 04:31 PM #1665Quality Haxing Since 1991
- Registriert seit
- Oct 2005
- Ort
- Pennsylvania, USA Fi
- Beiträge
- 6.206
- Points
- 29.255
- Level
- 99
- Downloads
- 0
- Uploads
- 0
One other question. Is there a way that I can quote a variable? Like say I wanted to concatenate a variable, but it needed quotes around it to work. For example:
doesn't work because the folder names don't have quotes around them.Code:folders=System.listDirectory() screen:blit(0,0,"images/"..folders[1].name.."/pic.png")
Because the table is created by LUA, I can't manually add quotes around each entry, so is there a way I could do this when blitting to the screen? Thanks again.
Zitat von Noriko
-
04-17-2006, 05:17 PM #1666QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
hello ever1 well if havent seen i've been working on a game: pspaintball and recently released v 0.1 so i want to implement wifi within the next few versions and i remeber a while back seeing sometin about lua wifi libary's now then heres my question:
A: fanjita got wifi for lua to work in 2.1+ correctly?
B:are there any tut's yet made for how to implement wifi into lua
C: if so where
D:anyway to check if it works or not as of i don't have a wifi connection spot
E: thats about it=-)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
-
04-17-2006, 05:21 PM #1667
- Registriert seit
- Apr 2006
- Beiträge
- 17
- Points
- 4.107
- Level
- 40
- Downloads
- 0
- Uploads
- 0
Send (open) "test.cmd" in a text editor. Add a 2nd line with the text "pause". Save file. It will look like this:
Zitat von ro0kie42
luaplayer index.lua
pauseGeändert von dragaron (04-17-2006 um 05:24 PM Uhr)
-
04-17-2006, 05:32 PM #1668
PSPhax09, that code *should* work, but maybe the first index value of the directory isnt what you think it is. I remember when I was making LUA OS and my card became corrupted. After that, the files in the directory were literally in a random order each time. Because of this, i almost gave up because my code didnt work for it anymore. But, yeah, I got it fixed.
Anyhoo, the first 2 index values are:
.
..
The . means current directory, the .. means back 1 directory. Also, check what folder you are trying to open. (maybe print(folders[3])).
Either that, or add a space like: .. folders[3] ..牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-17-2006, 05:40 PM #1669Simon Champion!
- Registriert seit
- Mar 2006
- Ort
- Calgary, Alberta, Ca
- Beiträge
- 537
- Points
- 11.489
- Level
- 70
- Downloads
- 0
- Uploads
- 0
how do you randomize something?
-
04-17-2006, 05:43 PM #1670QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- The Migrant Fleet
- Beiträge
- 908
- Points
- 9.678
- Level
- 66
- Downloads
- 0
- Uploads
- 0
Zitat von Greenskull
Code:number = math.random(1,4) -- ""number is the variable you want to randomize, 1 and 4 are the numbers you want the random number to be between"" if number >= 2 then.... -more code here-
-
04-17-2006, 05:45 PM #1671
thanks d00d
Zitat von dragaron
-
04-17-2006, 05:49 PM #1672<img src="images/smilies/psp.gif" border="0" alt="" title="" cl***="inlineimg" /> <img src="images/smilies/Punk.gif" border="0" alt="" title="" cl***=&

- Registriert seit
- Jun 2005
- Ort
- Canada
- Beiträge
- 1.944
- Points
- 11.105
- Level
- 69
- Downloads
- 0
- Uploads
- 0
and you have to add
Zitat von montrob
math.randomseed(os.time() )
at the beginning, outside the loop
-
04-17-2006, 05:53 PM #1673QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
have you guys just gone right pass my question??
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
-
04-17-2006, 06:04 PM #1674Simon Champion!
- Registriert seit
- Mar 2006
- Ort
- Calgary, Alberta, Ca
- Beiträge
- 537
- Points
- 11.489
- Level
- 70
- Downloads
- 0
- Uploads
- 0
ok how do i start the randomization?
-
04-17-2006, 07:01 PM #1675
math.randomseed(os.time() ) makes it so the numbers are TRULY random based on the time. If you didnt do this, every time you started luaplayer, the 'random' numbers generated would be the same. You call this at the begining of your program.
math.random(low,high) returns an integer between low and high. It's that simple.牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-17-2006, 07:44 PM #1676QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
or you can just define the high one and lua well auto set low to 1
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
-
04-17-2006, 08:17 PM #1677Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
my code:
Code:pad = Controls.read() dx = pad:analogX() dy = pad:analogY() if math.abs(dx) > 32 then cursorx = cursorx + dx / 64 height = height +1 end if math.abs(dy) > 32 then cursory = cursory + dy / 64 end
how can i make it so that if the analog stik goes down, height decreases by 1?right now, if you go up or down, the height increases.--------------------------------------------------------------------------------------
-
04-17-2006, 11:42 PM #1678
- Registriert seit
- Jan 2006
- Beiträge
- 7
- Points
- 4.172
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Ok, here goes...
I've been coding Lua for over three months now, and somewhere I got stuck. I'm trying to move multiple objects around my screen, using the same function. Something like a rack of balls on a pool table. Here it is:
This function moves the object in a given "angle" for "a" pixels, untill "speed / a" reaches zero.function moving()
a = speed / 500
if a >= 0 then
if ball.x <= 6 or ball.x >= 460 then
angle = pi - angle
end
if ball.y <= 5 or ball.y >= 252 then
angle = angle * (-1)
end
ball.x = ball.x + math.cos(angle) * a
ball.y = ball.y + math.sin(angle) * a
speed = speed - 10
end
screen:blit(ball.x,ball.y ,BallNumber,true)
end
I would like to enter some variables when running the function, like so:
Now comes my problem: if call this function inside my mainloop, it gets repeated over and over, ball.x and ball.y would get resetted every time. How could I get this to work?function moving(speed, angle, ball.x, ball.y, BallNumber)
-
04-17-2006, 11:50 PM #1679
you have to make a table where there are n balls. Then in that function make a for loop so that it happens for all the balls.
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
04-18-2006, 12:10 AM #1680
- Registriert seit
- Jan 2006
- Beiträge
- 7
- Points
- 4.172
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Hey Altair,
could you give me an example of how that table would look like?


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