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; O gawd more questions. I have the analog working fine, but all the person does it move to the right ...
-
04-17-2007, 08:58 AM #6871QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
O gawd more questions.
I have the analog working fine, but all the person does it move to the right and down. How do I make left and up.
Heres my code.
while true do
pad = Controls.read()
ax = pad:analogX()
if math.abs(ax) > 32 then
x = x + 3
end
if math.abs(ax) <-32 then
x = x - 3
end
ay = pad:analogY()
if math.abs(ay) > 32 then
y = y + 3
end
if math.abs(ay) <-32 then
y = y - 3
end
I added the negative codes to see if they would work. It didn't.
-
04-17-2007, 09:01 AM #6872QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
there should be a pad:analogY() also
-
04-17-2007, 09:12 AM #6873QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
while true do
pad = Controls.read()
ax = pad:analogX()
if math.abs(ax) > 32 then
x = x + 3
end
if math.abs(ax) <-32 then
x = x - 3
end
while true do
pad = Controls.read()
ax = pad:analogX()
if math.abs(ax) > 32 then
x = x + 3
end
if math.abs(ax) <-32 then
x = x - 3
end
ay = pad:analogY()
if math.abs(ay) > 32 then
y = y + 3
end
if math.abs(ay) <-32 then
y = y - 3
end
I do have one.
I just want to be able to move up and left.
-
04-17-2007, 09:17 AM #6874Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
ther is no way math.abs(ax) <-32 is going to be true
math.abs() returns the absolute value of the number meaning if it is -50 it will return 50.
-= Double Post =-
Collectgarbage forces lua to free memory that is flagged as unused. Lua does this periodically, but sometimes when you are unloading a bunch of graphics, you want to have lua do it immediately. ie
Zitat von Urameshi
Code:function unloadimages() image1 = null image2 = null image3 = null collectgarbage() end
Geändert von KleptoOne (04-17-2007 um 09:23 AM Uhr) Grund: Automerged Doublepost
-
04-17-2007, 09:25 AM #6875QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
blargh im so stuck
like when something collides in my game then i want one of them to like become inactive and disappear, so that the game doesnt restart
-
04-17-2007, 09:28 AM #6876QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
ahh I understand.
Zitat von KleptoOne
The thing I was following didn't explain what these things meant. It just told me to do them -.-
I got it working now. I have an arrow pointer thingy from the computer onto my little program thing.
-
04-17-2007, 10:21 AM #6877QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
so create universal function for that ;) with collectgarbage() ;)
Zitat von Urameshi
[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-17-2007, 10:35 AM #6878Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
you shouldn't have to use collect garbage for that purpose, say it was an enemy, why unload it when you kill it, what if you wanted to use another one of those enemies later on? I guess it depends on your game.
Zitat von myschoo
Easiest way to handle your situation is to hold all your enemies in a table, and when a collision occurs, remove that table element. To add more enemies, add it to the end of the table.
It should be a very simple process.
-
04-17-2007, 11:27 AM #6879Monster Masher
- Registriert seit
- Jun 2006
- Ort
- Behind you...
- Beiträge
- 265
- Points
- 5.084
- Level
- 45
- Downloads
- 0
- Uploads
- 0
I get an error that in the collision if "attempt to index field "?" null value". There is a asteroidmed array, en_2 is equal to 1, there are several bullets, no_bull is the amount of bullets, there is an asteroidmed[1] and it has x and y coordinates, same as the bullet. However i see no difference with this code and my other one:Code:function MedCol() for y=1,en_2 do for u=1,no_bull do if asteroidmed[y].x+24>bullet[u].x and asteroidmed[y].x<bullet[u].x+6 and asteroidmed[y].y+24>bullet[u].y and asteroidmed[y].y<bullet[u].y+6 then score=score+20 asteroidsm[en_3+1]={x=asteroidmed[y].x, y=asteroidmed[y].y, width=32, height=32, vspeed=(math.random(0,1))-(math.random(0,2)), hspeed=(math.random(0,1))-(math.random(0,2))} en_3=en_3+1 asteroidmed[y].x=489346983 bullet[u].x=-99999999999 end end end end
Apart from the names. any help?!Code:function Collision() for f=1,en_1 do for g=1, no_bull do if asteroid[f].x+32>bullet[g].x and asteroid[f].x<bullet[g].x+6 and asteroid[f].y+32>bullet[g].y and asteroid[f].y<bullet[g].y+6 then score=score+20 asteroid[en_2+1]={x=asteroid[f].x, y=asteroid[f].y, width=32, height=32, vspeed=(math.random(0,1))-(math.random(0,2)), hspeed=(math.random(0,1))-(math.random(0,2))} en_2=en_2+1 asteroid[f].x=489346983 bullet[g].x=-99999999999 end end end end
-
04-17-2007, 12:23 PM #6880QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
New problemm. I want to make it so whenever I click X within a certain perimeter it will do the USB thing. That works. Next I would like to make it so clicking there again it will disable. Theres my problem.
Heres what I have so far:
That works fine. When I click there USB starts up. I don't know how to make a deactivate though. Heres what I tried.Code:sl = pad:cross() if x>20 and x<70 and y > 20 and y < 70 and sl then System.usbDiskModeActivate() end
pad and v are already set earlier. Nothing I'm trying is working. Help please?Code:sl = pad:cross() if x>20 and x<70 and y > 20 and y < 70 and sl and v = 1 then System.usbDiskModeActivate() v = v + 1 end if x>20 and x<70 and y > 20 and y < 70 and sl and v = 1 then System.usbDiskModeActivate() v = v - 1 end
-
04-17-2007, 12:53 PM #6881
do:
Code:v = 0 sl = pad:cross() if x>20 and x<70 and y > 20 and y < 70 and sl and v = 0 then System.usbDiskModeActivate() v = 1 end if x>20 and x<70 and y > 20 and y < 70 and sl and v = 1 then System.usbDiskModeDeactivate() -- not sure what it is for deactivate though. this may be right i dunno v = 0 end
-
04-17-2007, 01:01 PM #6882QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Still doesn't work. I tried that once but copied it wrong. I just added a different activation point for it.
-
04-17-2007, 01:02 PM #6883
Thats right..
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-17-2007, 01:10 PM #6884QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
o.o Are you sure? I tried multiple times. D=
-
04-17-2007, 01:12 PM #6885Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Look at the rest of his code, the conditions of your if's are flawed.
Zitat von yumCOOKIEZZ
-
04-17-2007, 01:22 PM #6886QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Copied right from my code
if x>20 and x<70 and y > 20 and y < 70 and sl and v=0 then
System.usbDiskModeActivat e()
v=1
screen:blit(380, yy, usb, true)
screen.flip()
end
if x>90 and x<140 and y>20 and y<70 and sl and v=1 then
System.usbDiskModeDeactiv ate()
screen:blit(380, yy, offusb, true)
screen.flip()
v=0
end
Error: Program.LUA:47: 'then' expected near '='
Line 47 is the first line I posted. Removing the v=0 part makes it work.
-= Double Post =-
Another question...(sorry for so many questions)
Can I write a file in a separate LUA file, and tell the main one to open this one.
This would help me keep organized between my codes. I basically want a second frame typed thing.Geändert von yumCOOKIEZZ (04-17-2007 um 01:38 PM Uhr) Grund: Automerged Doublepost
-
04-17-2007, 02:08 PM #6887Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
v==0 is required
Zitat von yumCOOKIEZZ
in an if statement your are checking if two values are equal, this is done by ==
to set one value equal to another, you use =
as for the other item, research the dofile() command.
-
04-17-2007, 02:10 PM #6888
But make sure you dont call it much. Having an external file is great, but it shouldnt be called much. What I do is use external files to define functions, so each file only gets ran once at startup (a lot of people make files that do stuff like display "GAME OVER", someone even had a file ran every loop that checked for collision...very bad)
Zitat von KleptoOne
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-17-2007, 02:15 PM #6889
Hey guys i am trying to get the battery percent to print to the screen so i am creating a function for it. her is what i have so far:
function power()
power = System.powerGetBatteryLif ePercent()
Now when i try to print it to the screen i get an error so i am obviousley missing something. I tryed a few things but they did not work either.
Thanks Bob Hoil
-
04-17-2007, 02:19 PM #6890
...why...
Zitat von Bob Hoil
do this...
screen:print(x,y, System.powerGetBatteryLif ePercent())牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-17-2007, 02:38 PM #6891QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
I only plan on using it to open seperate windows for my program. N0t every window but the bigger ones with more coding that will get confusing.
Zitat von Yonathan_Jantis
Thanks for the help once again =D
-
04-17-2007, 04:32 PM #6892QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
how do you remove the table element?
Zitat von KleptoOne
-
04-17-2007, 04:37 PM #6893QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
http://lua-users.org/wiki/TableLibraryTutorial
Zitat von Urameshi
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
04-17-2007, 04:41 PM #6894QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
:Jump: thanks thanks thanks:Jump: , that was a good read and very informative
Zitat von yaustar
-
04-17-2007, 04:45 PM #6895
Yeah... http://lua-users.org/wiki/TutorialDirectory I keep giving out this link everywhere, yet no one seems to want to read it, instead they just ask everyone else.
Zitat von Urameshi
牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-17-2007, 04:50 PM #6896QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Is there a list of codes and stuff for LUA that would help me with my PSP. I looked but couldn't find anything and after a while you people will probably get annoyed with my constant errors.
-= Double Post =-
if x>20 and x<70 and y > 20 and y < 70 and sl and v == 0 then
System.usbDiskModeActivat e()
v = 1
end
if x>20 and x<70 and y > 20 and y < 70 and sl and v == 1 then
System.usbDiskModeDeactiv ate()
v = 0
end
Arh. Heres exactly what I have. When I go into my program and click within those boundaries, nothing happens.Geändert von yumCOOKIEZZ (04-17-2007 um 04:54 PM Uhr) Grund: Automerged Doublepost
-
04-17-2007, 05:03 PM #6897QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
I never seen you give that out
Zitat von Yonathan_Jantis
-
04-17-2007, 05:26 PM #6898
Zitat von yumCOOKIEZZ
Even when the preceding reply was the answer.
Zitat von Yonathan_Jantis
I rest my case.牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-17-2007, 05:28 PM #6899
Thanks Yonathan for the help i got it to work.
-
04-17-2007, 06:33 PM #6900QJ Gamer Blue
- Registriert seit
- Apr 2007
- Beiträge
- 81
- Points
- 3.525
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Oh sorry. I didn't refresh the page >.<


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