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; I wonder if your image load portion needs fixed! Anyways, anyone ko whats wrong with my script?...
-
10-01-2006, 04:56 PM #3571QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
I wonder if your image load portion needs fixed! Anyways, anyone ko whats wrong with my script?
-
10-01-2006, 04:56 PM #3572Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von TacticalPenguin
you write screen clear like this:
it SHOULD be:Code:screen:clear
Code:screen:clear()
--------------------------------------------------------------------------------------
-
10-01-2006, 04:58 PM #3573QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
OH I FORGOT THE LITTLE PARENTHESES THINGIES!!!!!!!!!!!!!!!!! !!!!!!
Do I also need to do that on screen.flip?
-
10-01-2006, 05:05 PM #3574Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Yep.
Zitat von TacticalPenguin
It's nice that these problems are working themselves out. :) The error descriptions are quite good, aren't they?
-
10-01-2006, 05:11 PM #3575NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
lol now i feel more dumb i cant fix my image problem and it works fine on my computer so im confused
-= Double Post =-
never mind i figured it outGeändert von iamcanadian (10-01-2006 um 05:11 PM Uhr) Grund: Automerged Doublepost
[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-01-2006, 05:13 PM #3576QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Ok, it shows the text up to where it should display the background pic then it shows this:
Error: index.lua:14: Image.load: Error loading image.
Press start to restart
My code now is:
The pic is named background.jpg and is in the same directory as index.luaCode:blue = Color.new(0, 0, 255) screen:print(0, 0, "Loading: 30%", blue) screen.flip() screen.waitVblankStart(120) screen:clear() screen:print(0, 0, "Loading: 70%", blue) screen.flip() screen.waitVblankStart(120) screen:clear() screen:print(0,0, "Loading Complete", blue) screen.flip() screen.waitVblankStart(120) screen:clear() background = Image.load("background.jpg") screen:print(0, 0, "Tux says hello!", blue) screen.flip() screen.waitVblankStart(240) screen:clear() background = Image.load("background.jpg") screen:print(0, 0, "Tux says goodbye!", blue) screen.flip() screen.waitVblankStart(180) while true do screen.waitVblankStart() end
-
10-01-2006, 05:20 PM #3577NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
ok i have 2 new problems now
1. how do i make the car move faster and smoother (if you need to look at my code its in the last page
2.how do i make a button to return to the lua player[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-01-2006, 05:23 PM #3578
how can i do this:
if timerD > 120 and < 140 then characterL = Run_L[7] end
where "and" is writin i dont know what to put to do:
if timer D is > then 120 but < then 140
My part of code:
Code:if timerL == 140 then timerL = 0 end if timerL >= 120 < 140 then characterL = Run_L[7] end if timerL >= 100 < 120 then characterL = Run_L[6] end if timerL >= 80 < 100 then characterL = Run_L[5] end if timerL >= 60 < 80 then characterL = Run_L[4] end if timerL >= 40 < 60 then characterL = Run_L[3] end if timerL >= 20 < 40 then characterL = Run_L[2] end if timerL >= 0 < 20 then characterL = Run_L[1] end
Free Prizes at Prizerebel Join us!
I already got 11 Gifts. Ask me for details or proof.
-
10-01-2006, 05:54 PM #3579words 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
ZeroX, you must do:
But for all of them...Code:if timerL >= 0 and timerL < 20 then characterL = Run_L[1] 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
-
10-01-2006, 06:13 PM #3580
Tkz SG57 tomorow when im done jumping and shooting and maybe a part of the level collision il send you a demo.TKZ i whas to tired to find it out TKZ
Free Prizes at Prizerebel Join us!
I already got 11 Gifts. Ask me for details or proof.
-
10-01-2006, 06:18 PM #3581Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
@ Tactical Penguin
I never use jpegs, always pngs, and I've never had a problem. How big in pixels is background.jpg? Make sure the capitalization and spelling is correct. Also, you load it twice, which you obviously don't need to do.
@ iamcanadian
1. These kinds of problems are ones where you have to do trial and error, because there's hardly ever just one way to do things. Faster is easy, just make it move more pixels per loop. However, it generally makes the movement seem less smooth when you make it faster.
2. When the interpreter reaches the end of the code, it goes back to luaplayer. So all you have to do is "break" out of the main loop.
@ ZereoX
It is far more efficient to use elseif's when you are testing the same variable, because it only runs through the if statements until it finds a satisfied condition.
SG57 posted the easiest way since I started, so I'll post another way, which is probably less efficient time-wise, but it does condense the two conditions into one (I suppose that makes it more efficient space-wise):
and to use elseif's:Code:if math.abs(timerL-9.5) < 10 then characterL = Run_L[1] end
Code:if math.abs(timerL-9.5) < 10 then characterL = Run_L[1] elseif math.abs(timerL-29.5) < 10 then characterL = Run_L[2] end
-
10-01-2006, 06:20 PM #3582QJ Gamer Gold
- Registriert seit
- Aug 2006
- Beiträge
- 1.633
- Points
- 11.629
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Ok guys, I got mine all fixed! Thanks for the help!
-
10-01-2006, 07:12 PM #3583NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
ok i got the break code to work but my whole script is slow for some reason
[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-01-2006, 07:48 PM #3584
My works perfect thanks guys.
PS.Im participating in the Dream coding compo sponsor by DCemu also Zion's compo sponsor by him hope you vote for me when im done.
Cheers,ZereoXFree Prizes at Prizerebel Join us!
I already got 11 Gifts. Ask me for details or proof.
-
10-02-2006, 02:01 PM #3585I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
I did try that, but I keep getting some error that has nothing to do with those two lines. I put this in:
Zitat von LMelior
But I get some stupid error. Could somone maybe post a working example?Code:mx=mx+math.floor(pad:analogX()/32) my=my+math.floor(pad:analogY()/32)

-
10-02-2006, 03:18 PM #3586Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
This is from one of my projects; you should be able to tell what it does and why I did it this way. It works for me and it's not that different from what you posted, so I don't know what's wrong with your code.
Zitat von ARza
Code:-- Allow player to change map offset with analog if pad:analogX()<0 then mapoffset.x=mapoffset.x-math.floor(pad:analogX()^2/2500) elseif pad:analogX()>0 then mapoffset.x=mapoffset.x+math.floor(pad:analogX()^2/2500) end if pad:analogY()<0 then mapoffset.y=mapoffset.y-math.floor(pad:analogY()^2/2500) elseif pad:analogY()>0 then mapoffset.y=mapoffset.y+math.floor(pad:analogY()^2/2500) end
-
10-02-2006, 03:20 PM #3587Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von LMelior
sry for the n00bish question, but what DOES math.floor do??--------------------------------------------------------------------------------------
-
10-02-2006, 04:07 PM #3588Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Surely a pro in 2D Lua would know to check the Lua Reference Manual. ;) I'll give you a hint, you don't need a separate rounding function because math.floor(x + 0.5) does the exact same thing.
-
10-02-2006, 05:54 PM #3589Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von LMelior
i got burned... so let me guess, it removes the decimal off of any number?
and the reference is just too boring for me. sad how i know metatables, but not this..:Cry:--------------------------------------------------------------------------------------
-
10-02-2006, 06:10 PM #3590QJ Gamer Blue
- Registriert seit
- Jul 2006
- Ort
- Alabama
- Beiträge
- 142
- Points
- 4.241
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Yeah. It rounds down (or, returns the largest integer <= a specific number), and is antonymous with math.ceiling.it removes the decimal off of any number?
I usually don't check for things I don't know exist, either. It's just too bad you had to learn something so important on the streets.
-
10-02-2006, 06:21 PM #3591Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
i get it! floor - down, ceiling - up! corny, but it works!
Zitat von Aphonia
-= Double Post =-
Zitat von ARza
here is some code that *should* work. havent tested it, but it should.
Code:sentivity = 32 -- the higher you put this, the slower it will move-- mx = mx + (pad:analogX()/sentivity) my = my + (pad:analogX()/sentivity)
Geändert von Grimfate126 (10-02-2006 um 06:21 PM Uhr) Grund: Automerged Doublepost
--------------------------------------------------------------------------------------
-
10-03-2006, 09:32 AM #3592QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
hello i have 3 questions:
1. i found this timer on evilmana.com site:
its really good BUT...its TOO FAST! ... its moving maybe 50-100 numbers/second...Code:white = Color.new(255,255,255) counter = Timer.new() counter:start() while true do screen:clear() currentTime = counter:time() screen:print(10,10,"Counter Time: " .. currentTime,white) if currentTime < 1000 then screen:print(100,100,"Less than 1000",white) end if currentTime > 1000 and currentTime < 2000 then screen:print(100,100,"Greater than 1000",white) end if currentTime > 2000 then counter:reset(0) counter:start() end screen.waitVblankStart() screen.flip() end
so HOW do i set it to 1 number in 1 sec???
2. Question:
this is simple code for info...i want it so when i press X it throw me back in Main Menu...it works but only sometimes...normally a i have to tap the button and then it randomly close and im back in menu...sometimes i pres X once...sometimes 20 times... i dont know whats the problem :/Code:--biela white = Color.new(255,255,255) while true do screen:clear() pad = Controls.read() screen:print(190,100,"Autor: myschoo",white) screen:print(110,110,"Podakovanie: QJ forum a EvilMana.com",white) screen:print(140,120,"Stlac X pre navrat do menu",white) if pad:cross() then break end screen.waitVblankStart() screen.flip() end
3. question is similar to 1st question:
when i use this code i can hear only maybe 0.5 sec from music then it plays from start..again and again and again...how to STOP this???Code:Music.playFile("music.xm", true)
THX 4 answers!Geändert von myschoo (10-03-2006 um 10:14 AM Uhr)
[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]
-
10-03-2006, 10:11 AM #3593QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
1. The timer is in milliseconds which is why it seems so fast. If you want seconds then simply divide it by 1000.
(You may want to floor it to get a whole number)Code:currentTimeInSecs = currentTime / 1000
2. You need to store the state of the button in the previous frame so you can tell the difference between a button press and a when you hold down the button.
-
10-03-2006, 11:47 AM #3594QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
head_54us:
thx mate 1st. thing sorted...i will try the second one
edit. sorted :)
so my last question again:
"Music.playFile("music.xm ", true)"
when i use this code, i dont know what to add so the music plays correctly...
[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]
-
10-03-2006, 11:50 AM #3595i r leet lol

- Registriert seit
- Sep 2006
- Ort
- England
- Beiträge
- 2.615
- Points
- 17.776
- Level
- 84
- Downloads
- 0
- Uploads
- 0
Well atleast someone sorted your problem out
whyHELLOder.
-
10-03-2006, 11:58 AM #3596QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
yeeh well good thread!!
[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]
-
10-03-2006, 06:39 PM #3597NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
im just trying to ad collisions what am i doing wrong here?Code:System.usbDiskModeActivate() line = Image.load("line.png") player = Image.load("player.png") linee = Image.load("line1.png") --Colisions function collisionCheck(object) if (Player.x + playerWidth > object.x) and (Player.x < object.x + object.width) and (Player.y + playerHeight > object.y) and (Player.y < object.y + object.height) then Player.x = oldx Player.y = oldy end end screenwidth = 480 - player:width() screenheight = 272 - player:width() Player = { } Player[1] = { x = 10, y = 75 } playerHeight = 60 playerWidth = 66 oldx = Player.x oldy = Player.y line = { } line[1] = { x = 0, y = 150 } while true do pad = Controls.read() screen:clear() screen:blit(0,50,linee) screen:blit(0,150,line) --check collision for line collisionCheck(line[1]) screen:blit(Player[1].x,Player[1].y,player) if pad:left() and Player[1].x > 0 then Player[1].x = Player[1].x - 4 end if pad:right() and Player[1].x < screenwidth then Player[1].x = Player[1].x + 4 end if pad:up() and Player[1].y > 0 then Player[1].y = Player[1].y - 4 end if pad:down() and Player[1].y < screenheight then Player[1].y = Player[1].y + 4 end if pad:start() then break end screen.waitVblankStart() screen.flip() end[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-03-2006, 06:48 PM #3598Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
whats your error?
Zitat von iamcanadian
--------------------------------------------------------------------------------------
-
10-03-2006, 06:51 PM #3599NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
bad argument #2 'blit' (image expected, got table) but that dosent make sence beacuse it never had problems eith any blit's intill i added the collision script???
[SPOILER="Donations"]Donators: TMK 1Mill, cowsruledaworld 300k, Arsonist 75k and 10 k, and thx spiral for the
prem....Thank you every one that has donated :D[/SPOILER]
[SPOILER="funny comic of the day!!!"][IMG]http://www.explosm.net/db/files/Comics/Matt/self-diagnosis.png[/IMG][/SPOILER]
Join #QJChat and #marshalls on IRC, at irc.toc2rta.com
-
10-03-2006, 09:43 PM #3600QJ Gamer Bronze
- Registriert seit
- Oct 2005
- Ort
- Alabama
- Beiträge
- 272
- Points
- 5.975
- Level
- 50
- Downloads
- 0
- Uploads
- 0
its because you created a table named line after you had already created line for an image.
Change the name of one of the two.My lua tutorials for PSP - www.evilmana.com/tutorials
PSP Lua CodeBase - Add your own code examples to the codebase! - www.evilmana.com/tutorials/codebase/


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