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; Zitat von SG57 TP - Have you considered using a OO approach to your programming? Nothing's wrong with what you ...
-
04-26-2007, 07:32 PM #7111QJ Gamer Silver

- Registriert seit
- Oct 2005
- Ort
- ~* Confidential *~
- Beiträge
- 839
- Points
- 20.361
- Level
- 90
- Downloads
- 0
- Uploads
- 0
youresam: For something as simple as a filebrowser, implementing OOP would be both useless and a waste of time.
Zitat von SG57
Did this for youresam, for reasons that you have to ask him yourself.

"Every team needs an idealistic person (whether they are a noob or a pro), my team doesn't have one cus im the idealistic founder."-me
Anime/Manga and Fanfiction is my inspiration!
Creator of:
- PSPSDK makefile creator - Lua Prompt - Animated Sprite Class\Library for Lua - Gmax2PSP -
-
04-26-2007, 08:29 PM #7112words 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, relay this to youresam:
When did i tell him to make a filebrowser OO? your implying just because the quetsion he answered, when really, it was an 'in-general' type of thing, as I believe OO programming is 'better' then any other type (given the project is suitable for it).
...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
-
04-26-2007, 08:36 PM #7113QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
he said:
youresam: OOP is a better programming style, but only for certain things. Simple things dont need OOP, and it should be avoided, whereas most other things, OOP is a good thing. And learn the rule of the square bracket.
-
04-26-2007, 08:38 PM #7114QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- Grand Line
- Beiträge
- 5.996
- Points
- 40.380
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Holy crap, I actually understand the code now that I'm almost done with Java class. I need to start developing again. Jeez.
[CENTER][IMG]http://img130.imageshack.us/img130/1640/acefcbanner2wo9.gif[/IMG]
[SIZE=1][B]I'm soo hot[/B][/SIZE]
[/CENTER]
[SIZE=2][CENTER][/SIZE][/CENTER]
[center]Sorry. No Advertising[/center]
-
04-27-2007, 12:07 AM #7115words 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
Best of luck, however, i recommend using C as, from what i hear, Java has heavy (a lot of) syntax that must be followed, so it wouldnt be that difficult using C knowing you must follow some strict syntax (all from what i hear, is Java closer to Lua or C?)

...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
-
04-27-2007, 12:16 AM #7116
Java is closer to C,
As the guys who created JAVA based JAVA's Syntax on C-ish style.
-
04-27-2007, 03:07 AM #7117QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
OO is a great design flow to follow and it is good to get into it early. Whether or not it is a large project, it is always good to keep an OO approach to things.
Before youresam gets another person to flame me, yes, this is opinon based.
-
04-27-2007, 05:54 AM #7118words 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
Either use OO programming all the time, or none of the time... You cant get experience and improve by object orienting only projects you feel are big enough for it.
PSPJunkie - i think you mean 'bias'...
...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
-
04-27-2007, 07:22 AM #7119
Zitat von SG57
Zitat von LMelior
goodd thaks you all guys, i will be testhig this stuff as sson as in have some more free time and a pc thks
Zitat von Merick
-
04-27-2007, 12:43 PM #7120QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- London, United Kingdom
- Beiträge
- 131
- Points
- 4.812
- Level
- 44
- Downloads
- 0
- Uploads
- 0
By using gsub, how can I extract only the file name from the path?
Example
C:\somepath\somefile.tmp
Results in "somefile"
Cant get my head around the patterns.
-
04-27-2007, 12:59 PM #7121Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
k , this will be probebly horrible LUACode:filepath = "C:\somepath\somefile.tmp"; for loop = 0 , sizeof(filepath) do if(filepath[loop] == '\') then currentPosition = 0; end else if filepath[loop] == '.' then currentPosition = -1; end else if currentPosition != -1 then filename[currentPosition] = filepath[loop]; currentPosition++; end end
-
04-27-2007, 01:11 PM #7122QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- London, United Kingdom
- Beiträge
- 131
- Points
- 4.812
- Level
- 44
- Downloads
- 0
- Uploads
- 0
imageName = string.gsub(string.gsub(s tring.gsub(currentlyPlayi ng.values["Thumb"],"(.*\\)([^\\]+)$","%2"),";;",";"),".tb n","")
Thats what I got now
Except it relies on the file being a .tbn which is making things harder for me.
Too many string.gsubs IMO.
Thanks for the effort though...
-
04-27-2007, 02:23 PM #7123
I've got a partially working function for that using string.sub instead of gsub. It doesn't quite work though because I'm having trouble figuring out how to compare a character from the string to the \ . Anyway, what I have so far:
if you could figure out how to get this line to work:Code:function find_name(text) for i = text:len(), 1, -1 do if string.sub(text, i, i) == "." then local name_end = i-1 end if string.sub(text, i, i) == "\" then local name_start = i+1 end end return string.sub(text, name_start, name_end) end
if string.sub(text, i, i) == "\"
then with this:
filename = find_name(""C:\somepath\s omefile.tmp")
filename would be "somefile"
-
04-27-2007, 02:40 PM #7124QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- London, United Kingdom
- Beiträge
- 131
- Points
- 4.812
- Level
- 44
- Downloads
- 0
- Uploads
- 0
In lua "\\" means "\"
You cant use "\"
That should workCode:if string.sub(text, i, i) == "\\"
I'll give it a go...
Thanks!
-
04-27-2007, 02:52 PM #7125
well, I tried to use "\\" but that didn't work either. now that I think about it, it's probably because the text string with the file path only has single \'s in it, so lua probably skips over it. If you change all the \ over to / it will work, however I don't know how that will effect the rest of your program
anyway, I looked at my code again and re-wrote it a little:
Code:function find_name(text) for i = 1, text:len() do if string.sub(text, i, i) == "\\" then name_start = i+1 elseif string.sub(text, i, i) == "." then name_end = i-1 end end return string.sub(text, name_start, name_end) end
-
04-27-2007, 03:07 PM #7126QJ Gamer Green
- Registriert seit
- Dec 2006
- Ort
- main();
- Beiträge
- 1.071
- Points
- 11.300
- Level
- 70
- Downloads
- 0
- Uploads
- 0
What language is that?
Zitat von hallo007
-
04-27-2007, 03:11 PM #7127QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- London, United Kingdom
- Beiträge
- 131
- Points
- 4.812
- Level
- 44
- Downloads
- 0
- Uploads
- 0
Certainly isn't lua
-= Double Post =-
Got itCode:imageName = string.gsub(string.gsub(currentlyPlaying.values["Thumb"],"(.*\\)([^\\]+)$","%2"),"%.[^%.]*$","")
Geändert von trex6662k5 (04-27-2007 um 03:23 PM Uhr) Grund: Automerged Doublepost
-
04-27-2007, 03:29 PM #7128
lol, and I just figured it out with my function too
if you use double square brackets [[]] instead of "", then lua will not parse the escape sequences in the text:
Code:filepath = [[C:\somepath\somefile.tmp]] white=Color.new(255,255,255) function find_name(text) for i = 1, text:len() do if string.sub(text, i, i) == [[\]] then name_start = i+1 elseif string.sub(text, i, i) == "." then name_end = i-1 end end return string.sub(text, name_start, name_end) end filename = find_name(filepath) screen:clear() screen:print(10,10, filename, white) screen:flip() pad = Controls.read() while not pad:cross() do pad = Controls.read() end
-
04-27-2007, 03:45 PM #7129QJ Gamer Blue
- Registriert seit
- Sep 2006
- Ort
- London, United Kingdom
- Beiträge
- 131
- Points
- 4.812
- Level
- 44
- Downloads
- 0
- Uploads
- 0
I'll keep that in mind
-
04-28-2007, 05:34 PM #7130QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
i kno i am doing something wrong, gives me an error ( i am a nooob at LUA)
EDITPHP-Code:--Load images into a table
Images = {
Image.load("images/background.jpg"),
Image.load("epic.png"),
Image.load("img_3.png"),
Image.load("img_4.png"),
Image.load("img_5.png"),
Image.load("img_6.png"),
Image.load("img_7.png")
}
currentImageToDisplay = 1;
while true do
screen:clear()
pad = Controls.read()
if pad:r() and currentImageToDisplay < table.getn(Images) then
currentImageToDisplay = currentImageToDisplay + 1;
end
if pad:l() and currentImageToDisplay > 0 then
currentImageToDisplay = currentImageToDisplay - 1;
end
screen:blit(0, 0, Images[background]);
screen.waitVblankStart()
screen.flip()
end
ok i can get the images to load but when i try to go back to an image it saysPHP-Code:--Load images into a table
Images = {
Image.load("images/background.jpg"),
Image.load("images/epic.png"),
}
currentImageToDisplay = 1;
while true do
screen:clear()
pad = Controls.read()
if pad:r() and currentImageToDisplay < table.getn(Images) then
currentImageToDisplay = currentImageToDisplay + 1;
end
if pad:l() and currentImageToDisplay > 0 then
currentImageToDisplay = currentImageToDisplay - 1;
end
screen:blit(0, 0, Images[currentImageToDisplay]);
screen.waitVblankStart()
screen.flip()
end
index.lua :22: bad argument #2 to /blit/ (image expected, got nil)
Error: no script file foundGeändert von cruisx (04-28-2007 um 05:53 PM Uhr)
-
04-28-2007, 05:59 PM #7131
in lua, tables start at 1, so here:
if pad:l() and currentImageToDisplay > 0
you need to change the 0 to a 1
-
04-28-2007, 06:14 PM #7132QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
i have one question, when i try to redefine Player.x and Player.y, how come when i run the game Player's moves are limited but not only that but the Player moves in like a invisible box, and then it just resets back to the middle of the invisible box
-
04-28-2007, 06:50 PM #7133QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
really sorry for the doubble post but i have a prob
when i try to run it, it skips rlly fast from pic 1 to pic 2. The pics in between load for like 0.1 secconds lol. can someone pls help =)Code:--Load images into a table Images = { Image.load("images/background.jpg"), Image.load("images/epic.png"), Image.load("images/test2.jpg"), Image.load("images/work2.jpg") } currentImageToDisplay = 1; while true do screen:clear() pad = Controls.read() if pad:r() and currentImageToDisplay < table.getn(Images) then currentImageToDisplay = currentImageToDisplay + 1; end if pad:l() and currentImageToDisplay > 1 then currentImageToDisplay = currentImageToDisplay - 1; end screen:blit(0, 0, Images[currentImageToDisplay]); screen.waitVblankStart() screen.flip() end
-
04-28-2007, 06:50 PM #7134
Urameshi: can't be sure without seeing the code, but to me it sounds like instead of adding the analog x,y to the screen position you are using the analog position as the actual screen position
cruisx: right after you flip the screen, add this line: "oldpad = pad"
then, add this to your if statments: "and pad ~= oldpad"
-
04-28-2007, 06:52 PM #7135QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
there ya go
Zitat von Merick
Code:white=Color.new(255,255,255) ball=Image.load("./Images/ball.png") Sball=Image.load("./Images/Spike Ball.png") square=Image.load("./Images/10x10.jpg") bigSquare=Image.load("./Images/30x30.jpg") stick=Image.load("./Images/190x23.jpg") lvl=Image.load("./Images/backgrounds/silkwave black.png") menu=Image.load("./Images/menu.png") next=Image.load("./Images/next level.png") stick2=Image.load("./Images/23x190.png") ball:width() ball:height() screenwidth=480-ball:width() screenheight=272-ball:width() Player={x=40,y=25,w=40,h=40,img=ball,oldimg=Sball} Enemy={x=0,y=0,w=30,h=30,img=bigSquare,} Square={x=0,y=0,w=10,h=10,img=square} Stick={x=0,y=0,w=190,h=23,img=stick} Stick2={x=0,y=0,w=23,h=190,img=stick2} enemylist = {} enemylist[1] = Stick1 enemylist[2] = Stick2 --------------------------------------------------------------------------functions function menu1() pad=Controls.read() screen:blit(0,0,menu) if pad:cross() then level1() end end ------------------------------------------------------lvl1 function level1() while true do screen:clear() Enemy.x=100 Enemy.y=100 if collision(Player,Enemy) then screen:blit(0,0,next) screen.flip() screen.waitVblankStart(90) level2() end movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen.waitVblankStart() screen.flip() end end ---------------------------------------------------lvl2 function level2() while true do screen:clear() Enemy.x=300 Enemy.y=50 if collision(Player,Enemy) then screen:blit(0,0,next) screen.flip() screen.waitVblankStart(90) level3() end movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen.waitVblankStart() screen.flip() end end ---------------------------------------------------lvl3 function level3() nbc=0 ncc=2 while true do screen:clear() Enemy.x=400 Enemy.y=50 Stick.x=117 Stick.y=234 Stick2.x=230 Stick2.y=0 if collision(Player,Enemy) then screen:blit(0,0,next) screen.flip() screen.waitVblankStart(90) level4() end movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen:blit(Stick.x,Stick.y,Stick.img) screen:blit(Stick2.x,Stick2.y,Stick2.img) screen.waitVblankStart() screen.flip() end end -------------------------------------------------------------------------level4 function level4() run=false nbc=0 ncc=1 while true do screen:clear() Enemy.x=40 Enemy.y=50 Stick.x=117 Stick.y=234 Stick2.x=230 Stick2.y=0 Square.x=470 Square.y=45 if collision(Player,Stick2) and Player.img==Player.oldimg then nbc=nbc-1 else if collision(Player,Stick2) then nbc=nbc+1 end end if nbc>ncc then dofile("br.lua") end if collision(Player,Square) then Player.img = Player.oldimg end if collision(Player,Enemy) then screen:blit(0,0,next) screen.flip() screen.waitVblankStart(90) level5() end screen:blit(Stick2.x,Stick2.y,Stick2.img) movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen:blit(Stick.x,Stick.y,Stick.img) screen:blit(Square.x,Square.y,Square.img) screen.waitVblankStart() screen.flip() end end ----------------------------------------------------------------------Level 5 function level5() run=false nbc=0 ncc=1 while true do screen:clear() Enemy.x=378 Enemy.y=49 Stick.x=384 Stick.y=79 Stick2.x=280 Stick2.y=90 Square.x=22 Square.y=236 Player.x=14 Player.y=17 if collision(Player,Stick2) and Player.img==Player.oldimg then nbc=nbc-1 else if collision(Player,Stick2) then nbc=nbc+1 end end if nbc>ncc then dofile("br.lua") end if collision(Player,Square) then Player.img = Player.oldimg end screen:blit(Stick2.x,Stick2.y,Stick2.img) movePlayer() screen:blit(0,0,lvl,true) screen:blit(Player.x,Player.y,Player.img) screen:blit(Enemy.x,Enemy.y,Enemy.img) screen:blit(Stick.x,Stick.y,Stick.img) screen:blit(Square.x,Square.y,Square.img) screen.waitVblankStart() screen.flip() end end --------------------------------------------------------------------------Other Function function collision(ob1_,ob2_) if (ob1_.x + ob1_.w > ob2_.x) and (ob1_.x < ob2_.x + ob2_.w) and (ob1_.y + ob1_.h > ob2_.y) and (ob1_.y < ob2_.y + ob2_.h) then return true else return false end end function movePlayer() pad=Controls.read() if pad:right() and Player.x < screenwidth then Player.x=Player.x + 5 end if pad:left() and Player.x>0 then Player.x=Player.x - 5 end if pad:down() and Player.x < screenheight then Player.y=Player.y + 5 end if pad:up() and Player.y>0 then Player.y=Player.y - 5 else if not pad:up() then Player.y=Player.y + 8 end end end falling=false ------------------------------------------------------------------------Main loop while true do screen:clear() menu1() screen.waitVblankStart() screen.flip() end
-
04-28-2007, 07:05 PM #7136
first, at the beginning of your script you've got this:
ball:width()
ball:height()
there are no operations on these, so what are you trying to do there?
as for the movement problem, I can't really see anything that would cause the behavior you described
-
04-28-2007, 07:23 PM #7137QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
idk why those
ball:width()
ball:height()
are there either i just have alot of useless stuff in there
-
04-29-2007, 05:36 AM #7138
you can use an oldpad type thing:
Zitat von cruisx
here, if you hold cross, it will only execute the "do something" once. It waits for you to lift off the button, and press it again before it re-executes.Code:oldpad = Controls.read() while true do pad = Controls.read() if pad:cross() and oldpad:cross() ~= pad:cross() then --do something end oldpad = pad end
-= Double Post =-
@ Urameshi:
i think your problem is that you define your players x and y values in the main loop. Therefor once you move, you are just moved back once the loop restarts again.Geändert von emericaska8r (04-29-2007 um 05:38 AM Uhr) Grund: Automerged Doublepost
-
04-29-2007, 10:55 AM #7139QJ Gamer Gold
- Registriert seit
- Nov 2006
- Ort
- ...
- Beiträge
- 2.080
- Points
- 11.942
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thanks dude that worked
-
04-29-2007, 11:04 AM #7140
no problem


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