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; Code: screenwidth = 480 - player:width() screen height = 272 - player: width () im not a big pro but ...
-
10-04-2006, 06:11 AM #3601QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
im not a big pro but is this OK?Code:screenwidth = 480 - player:width() screenheight = 272 - player:width()
btw. i found what was the problem of this code...
i just had to put it outside main loop :oCode:Music.playFile("music.xm ", true)
[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-04-2006, 03:04 PM #3602NeilR is back
- Registriert seit
- Sep 2006
- Ort
- canada.. duh
- Beiträge
- 180
- Points
- 4.503
- Level
- 42
- Downloads
- 0
- Uploads
- 0
yeah thats ok but now i have a new error
Zitat von myschoo
error:attempt to perform arithmetic on global 'X' and sometimes it says 'player x' insted of 'x' i under stand what its telling me but i dont understand why its telling me :PCode:System.usbDiskModeActivate() line = Image.load("line.png") player = Image.load("player.png") linee = Image.load("line1.png") Player = { } Player[1] = { x = 10, y = 75 } playerHeight = 60 playerWidth = 66 oldx = Player.x oldy = Player.y screenwidth = 480 - player:width() screenheight = 272 - player:width() --Colisions function collisionCheck(object) if (Player.x + playerWidth > linem.x) and (Player.x < linemx + linem.width) and (Player.y + playerHeight > linem.y) and (Playery < linem.y + linem.height) then Player.x = oldx Player.y = oldy end end linem = { } linem[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(linem[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-04-2006, 03:20 PM #3603I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
You have this line:
Zitat von iamcanadian
oldx = Player.x
oldy = Player.y
and this line
Player.x = oldx
Player.y = oldy
But you use neither of these variables, and you didn't define any of them. You defined each one of them as being equal to an undefined variable. It's a giant loop. Just take them out, or do something like
Player.x = 0
Player.y = 0
oldx = 0
oldy = 0
Just to define them in some way.
-
10-04-2006, 05:04 PM #3604Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
You also changed the code inside the collisionCheck function. Change it back.
-
10-06-2006, 06:50 PM #3605
- Registriert seit
- Sep 2006
- Beiträge
- 18
- Points
- 3.800
- Level
- 38
- Downloads
- 0
- Uploads
- 0
I have a game where I print a 'bottle' to the screen when x is pushed, and it moves across the screen. Now I am having an issue being able to stop printing it once its x cord hits 0, so you can send another bottle down. I have the code to print it in a function, so its not working out to well. Heres my code.
Any ideas to make iit possible to send more then one 'bottle' at a time?Code:function bottleSpawn() randSpeed = math.random(2,6) if bottleCheckTop == true then bottle[1].x = bottle[1].x - randSpeed screen:blit(bottle[1].x, bottle[1].y, Bottle) end --and... if pad:cross() and player.y == -20 then bottleCheckTop = true
(Seems like such a simple problem, but I just can't figure it out. :rtfm: (What does RTFM mean anyways?))
-
10-06-2006, 07:12 PM #3606sceKernelExitGame();
- Registriert seit
- Jan 2006
- Ort
- New York
- Beiträge
- 3.126
- Points
- 19.955
- Level
- 89
- Downloads
- 0
- Uploads
- 0
try maybe
BTW, you need and 'end' here:Code:i = 1 function bottleSpawn() randSpeed = math.random(2,6) if bottleCheckTop == true then bottle[i].x = bottle[i].x - randSpeed screen:blit(bottle[i].x, bottle[i].y, Bottle) if bottle[i].x == 0 then i = i+ 1 end end
Code:if pad:cross() and player.y == -20 then bottleCheckTop = true
-
10-06-2006, 07:59 PM #3607likes kittens....awww....
- Registriert seit
- Sep 2006
- Ort
- Detroit
- Beiträge
- 628
- Points
- 6.975
- Level
- 55
- Downloads
- 0
- Uploads
- 0
read the f*ckin manual.
Zitat von rybarnes
-
10-07-2006, 06:18 AM #3608QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
help me im getting this error quite alot:
what does it mean ?Code:<eof> expected near "end"
[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-07-2006, 07:29 AM #3609
- Registriert seit
- Sep 2006
- Beiträge
- 18
- Points
- 3.800
- Level
- 38
- Downloads
- 0
- Uploads
- 0
You have one to many ends in your code.
Zitat von myschoo
-
10-07-2006, 07:58 AM #3610I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
It means that somewhere you forgot to put an 'end'. Probably at the end of a function or if/then statement.
Zitat von myschoo

-
10-07-2006, 01:24 PM #3611Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von ARza
actually, it means the opposite. you have an extra end somewhere. if you needed an end, it would say:
Code:error: line: 'end' expected to close whatever.. on line ..whatever.
--------------------------------------------------------------------------------------
-
10-08-2006, 12:26 AM #3612QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
thx guys...it was true i removed end and it worked
[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-08-2006, 05:27 PM #3613Look at my user title :p
- Registriert seit
- Feb 2006
- Ort
- Texas
- Beiträge
- 1.183
- Points
- 14.103
- Level
- 77
- Downloads
- 0
- Uploads
- 0
ok so i starte to code my game from the ground up again and i am just trying a simple code i made heres the error i get:
error: script.lua:6: function arguments wxpected near 'while'
heres my code:
i dont know whats wrong again. please dont flame me i just cant get this programing thing down but im tryingCode:red = Color.new(0,0,255) main1 = Image.load("main1.png") screen:print(0,0,"injustice",red) screen.flip() screen:clear while true do screen:clear screen:blit(0,0,main1) screen:clear screen.waitVblankStart() end end**********, ********** :p
http://img143.imageshack.us/img143/6...boysfanij8.gif
-
10-08-2006, 06:03 PM #3614Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von %chrono trigger%
youre not putting () after screen:clear(). it should be:
btw, when it says function arguments, its usually referring to the ().Code:red = Color.new(0,0,255) main1 = Image.load("main1.png") screen:print(0,0,"injustice",red) screen.flip() screen:clear() while true do screen:clear() screen:blit(0,0,main1) screen:clear() screen.waitVblankStart() end end--------------------------------------------------------------------------------------
-
10-08-2006, 06:52 PM #3615I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
And you have to many 'end's.

-
10-08-2006, 08:13 PM #3616Look at my user title :p
- Registriert seit
- Feb 2006
- Ort
- Texas
- Beiträge
- 1.183
- Points
- 14.103
- Level
- 77
- Downloads
- 0
- Uploads
- 0
yeah i know i have to many ends i just typed one more its not in my code and with the function arguments is it always parentheses or can it be something else? i read in a error index that thats all it is plus thank you all for being patient with me and my noob questions
**********, ********** :p
http://img143.imageshack.us/img143/6...boysfanij8.gif
-
10-08-2006, 08:20 PM #3617Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
Zitat von %chrono trigger%
its the parenthesis most of the time. im not sure though.--------------------------------------------------------------------------------------
-
10-08-2006, 08:29 PM #3618Look at my user title :p
- Registriert seit
- Feb 2006
- Ort
- Texas
- Beiträge
- 1.183
- Points
- 14.103
- Level
- 77
- Downloads
- 0
- Uploads
- 0
are there multiple reasons for why after you load the script it just stays black? or is that becasue of one main thing (error; mistake in the code)
**********, ********** :p
http://img143.imageshack.us/img143/6...boysfanij8.gif
-
10-08-2006, 08:32 PM #3619Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
say what? in laymans terms please. ;)
Zitat von %chrono trigger%
--------------------------------------------------------------------------------------
-
10-08-2006, 08:50 PM #3620Look at my user title :p
- Registriert seit
- Feb 2006
- Ort
- Texas
- Beiträge
- 1.183
- Points
- 14.103
- Level
- 77
- Downloads
- 0
- Uploads
- 0
i update my last post
-= Double Post =-
i updated my last postGeändert von %chrono trigger% (10-08-2006 um 08:50 PM Uhr) Grund: Automerged Doublepost
**********, ********** :p
http://img143.imageshack.us/img143/6...boysfanij8.gif
-
10-09-2006, 01:56 AM #3621
Well ofcourse there is an error in the code if the screen stays black. Or your screen just broke...
Zitat von %chrono trigger%
Also watch out that you don't devide something by zero. Then the screen will also stay black and the PSP will crash. This is sometimes harder to see, because there isn't an obvious mistake. You'll have to check if it's possible that the denominator (that's what its caled right?) becomes zero yourself.LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
10-11-2006, 04:41 AM #3622
is there a file number limiter in lua?
I know there is a file size limiter but what about file number? I tried to load 100 sequenced .png (all 480x272) files and it gave me an error saying load failed. I thought it exceeded the file size limit so i tried 100 sequenced .jpgs. It didn't gave me the error but it froze up and crash. Then i tried 20 but it still crash. The most i could get is like 10 or so. I have checked the total size of all my pngs and it's less than 2mb. I used some script to check my free memory and it said i had 8MB free without loading all the images. :Argh:
I have an OGG on playback in my script by the way. It may affect it?
Can someone tell me workaround for this? I've seen people adding a lot sprites into one png but can someone tell me an example on how to do this, for say 10 x 10 images? I am currently using a .pkg file and extracting sprites out to load it.
Please help me. Thanks :)Geändert von Fuzzie360 (10-11-2006 um 04:59 AM Uhr)
-
10-11-2006, 10:13 AM #3623QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
collision
pls help i cant figure out whats the problem with this code:
it ment to stop player to get out from the screen but it doesnt work... can figure out what the probCode:white = Color.new(255,255,255) blockA = Image.createEmpty(480,1) blockA:clear(white) blockB = Image.createEmpty(480,1) blockB:clear(white) blockC = Image.createEmpty(1,272) blockC:clear(white) blockD = Image.createEmpty(1,272) blockD:clear(white) BlockA = { x = 0, y = 0, height = blockA:height(), width = blockA:width() } BlockB = { x = 0, y = 271, height = blockB:height(), width = blockB:width() } BlockC = { x = 0, y = 0, height = blockC:height(), width = blockC:width() } BlockD = { x = 479, y = 0, height = blockD:height(), width = blockD:width() } player = Image.createEmpty(32,32) player:clear(white) Player = { x = 30, y = 100 } playerHeight = 32 playerWidth = 32 function movePlayer() pad = Controls.read() if pad:right() then Player.y = Player.y + 5 end if pad:left() then Player.y = Player.y - 5 end if pad:down() then Player.x = Player.x + 5 end if pad:up() then Player.x = Player.x - 5 end end 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 while true do oldx = Player.x oldy = Player.y screen:clear() collisionCheck(BlockA) collisionCheck(BlockB) collisionCheck(BlockC) collisionCheck(BlockD) screen:clear() movePlayer() screen:blit(Player.y,Player.x,player) screen:blit(BlockA.x,BlockA.y,blockA) screen:blit(BlockB.x,BlockB.y,blockB) screen:blit(BlockC.x,BlockC.y,blockC) screen:blit(BlockD.x,BlockD.y,blockD) screen.waitVblankStart() screen.flip() end
:Cry: HELP
[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-11-2006, 10:15 AM #3624Seven Year Vet. BOW DOWN.

- Registriert seit
- Dec 2005
- Ort
- Manchester, UK
- Beiträge
- 2.240
- Points
- 14.794
- Level
- 78
- My Mood
-
- Downloads
- 1
- Uploads
- 0
i don't see any problems, but i havn't slept in 27 hours, so obviously my judgement will be affected...
-
10-11-2006, 11:04 AM #3625QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
me to! i cant see any problems but it still doesnt work!!
[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-11-2006, 05:09 PM #3626Developer

- Registriert seit
- Jul 2006
- Beiträge
- 205
- Points
- 4.318
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Didn't I tell you to look at your code and think logically what it will do? ;)
I was going to tell you exactly what's wrong, but I don't feel like explaining. So I'll give you a hint: the order that you do things in your loop is the problem.
-
10-11-2006, 05:34 PM #3627I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Why do all that collision checking, when you can just put:
Zitat von myschoo
Just do that for all the sides. It's much easier.Code:if pad:left() and player.x > 0 then player.x = player.x - 2 end

-
10-12-2006, 10:04 AM #3628QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
wow ur my master
Zitat von LMelior
i got it :)
-= Double Post =-
im learning by evilmana tuts and thats how they explained it...:)
Zitat von ARza
Geändert von myschoo (10-12-2006 um 10:04 AM Uhr) Grund: Automerged Doublepost
[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-12-2006, 01:14 PM #3629Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
[rant]
Zitat von myschoo
i HATE it when some people have to do EVERYTHING by the tutorials.. geez, use YOUR brain for once! ever heard of the saying "there is more than one way to do something" ? LISTEN to it... [/rant] (not talking about you myscoo, just using you as an example.
)
anyways, myscoo try different things. try all ideas you get, one might help your performance a lot.--------------------------------------------------------------------------------------
-
10-12-2006, 01:35 PM #3630I'm Baaaack!

- Registriert seit
- May 2006
- Ort
- Nowhere
- Beiträge
- 2.186
- Points
- 17.067
- Level
- 83
- Downloads
- 0
- Uploads
- 0
Read tutorial 7 of ProgramLua. That'll help you so your player doesn't go off screen.



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