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 tried using functions. Thats when it isn't working. Hmm I'll just go over the code again. Thx though!...
-
01-31-2006, 01:07 PM #451
I tried using functions. Thats when it isn't working. Hmm I'll just go over the code again. Thx though!
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
01-31-2006, 10:03 PM #452QJ Gamer Green
- Registriert seit
- Nov 2005
- Ort
- Sweden
- Beiträge
- 460
- Points
- 6.520
- Level
- 52
- Downloads
- 0
- Uploads
- 0
I guess that this part should be more like this.
Zitat von Altair
Code:if pad:cross() and menustatus == 0 then dofile("./data/game.lua") end
-
02-01-2006, 02:35 AM #453
That wasn't my code but soadnation's, but thx anyway =). BTW idon't really understand your piece of code, atleast i don't see how it would make your character jump. Im guessing yP is the jumpt variable. But i don't get the time thingies. So sorry can't help ya there.
And i still don't get my code to run. Since i put those functions in it doesnt work. I don't get it. According to me theres nothing wrond, but yeah ofcourse there is. Is this a correct usage of the function command:
function game()
while true do
...... -- code here
end
end
And can i go back to it like this:
if pad:cross() then
game()
end
Its a bit long sorry bout that.
Altair
EDIT: Ok got it to work but only because i changed the code to using while commands instead of function. I would still like to know if i use the function command correct though and what i coould have done wrong. Thx!Geändert von Altair (02-01-2006 um 02:03 PM Uhr)
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-01-2006, 02:33 PM #45411th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
This is a fixed version of your code.
Zitat von soadnation
I Deleted everything that wasnt neededCode:green = Color.new(0, 255, 0) color = Color.new(255, 255, 255) menustatus=0 while true do --set menu option --Select Options pad = Controls.read() if pad:down() then menustatus = menustatus + 1 screen.waitVblankStart(10) end if pad:up() then menustatus = menustatus - 1 screen.waitVblankStart(10) end if pad:cross() and menustatus == 0 then dofile("./index.lua") end if menustatus == 2 and pad:cross() then break end --Make Menu if menustatus == 0 then screen:print(160, 100, "Play", color) screen:print(160, 120, "Info", green) screen:print(160, 140, "Exit", green) screen.flip() end if menustatus == 1 then screen:print(160, 100, "Play", green) screen:print(160, 120, "Info", color) screen:print(160, 140, "Exit", green) screen.flip() end if menustatus == 2 then screen:print(160, 100, "Play", green) screen:print(160, 120, "Info", green) screen:print(160, 140, "Exit", color) screen.flip() end if menustatus == -1 then menustatus = menustatus +3 end if menustatus == 3 then menustatus = menustatus -3 end end
Because you had alot of stuff that wasnt needed at all lol.
Anyway i hope you like it
and i made it possible
to select "EXIT" and then press cross to exit lol.
EDIT:
I Added the bit where you are at "Play" and then
press up and you select EXIT...
Anyway please say thanks when you drop by :icon_biggGeändert von c5cha7 (02-01-2006 um 02:56 PM Uhr)
FAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
02-01-2006, 04:17 PM #455QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 375
- Points
- 5.631
- Level
- 48
- Downloads
- 0
- Uploads
- 0
sweet thanks alot. i was starting to think i should just ask someoene if i could use there menu. anyways now i just need to get started on the game part. it should be pretty easy exept for one part but ill ask for help when i get to it.
quick question. ive been looking at some other apps and they use dofile to load stuff like all the colors, in game menu's, or like in acno's energizer he loads the dig funtion.do i have to do anything special for that or can i just load then in the begining of the script?Geändert von soadnation (02-01-2006 um 04:26 PM Uhr)
-
02-02-2006, 05:16 AM #45611th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
You do know that you dont need to load a new script
Zitat von soadnation
from the menu?? You can just add your script to the menu
along with options etc..
I Could probally show you an example but i aint
so good at menu's yet (even though i fixed yours??? lol).
Anyway i think "dofile" is mainly for loading a new lua script.
Or you could probally use it to load addons etc..
I hope that clear's something on your todo list lol...
Good Luck :icon_smilFAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
02-02-2006, 05:54 AM #457
Well i have some sort of a basic menu, but it's in the main code. So if that's your question then no you don't have to use dofile. The only use i can think of it's easy to keep track of the different parts of code. Also its easy to change between different pieces of code: you can just rename the files.
Anyway i dont need it yet.LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-02-2006, 06:01 AM #458
@HaxxBlaster:
I don't know how you want to code the jump, but i was thinking:
Just have a variable say z. Where z is the jump height. And if z increase you just make some anymation of a jump that plays at the same time. Increasing the z and then decreasing it when it reaches a certain value shouldn't be that hard. I don't really know how to make an animation of different images, but it shows you how to here (its at the last part) .
You probably have something like this, i guess. But if not then maybe this is a solution?
Altair
EDIT:
I see you did what i said sort of. But you can also do it like this, without the time variable, so its shorter:
Code:if pad:cross() then while i < 140 do -- or you can use "for ...." etc. if i<71 then -- so till 70 yP = yP - 1 end if i > 70 then -- so from 71 yP = yP +1 end i=i+1 end -- end while end -- end if pad:cross()
Geändert von Altair (02-02-2006 um 08:01 AM Uhr)
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-02-2006, 08:11 AM #459
c5cha7, does the 10 in "screen.waitVblankStart(1 0 )" mean it waits 10 times the whole cycle or 10 seconds or something completly different?
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-02-2006, 11:53 AM #460QJ Gamer Blue
- Registriert seit
- Aug 2005
- Ort
- USA
- Beiträge
- 214
- Points
- 5.594
- Level
- 48
- Downloads
- 0
- Uploads
- 0
60=one second so that makes it wait about a 6th of a second
Zitat von Altair
-
02-02-2006, 12:01 PM #461QJ Gamer Blue
- Registriert seit
- Aug 2005
- Ort
- USA
- Beiträge
- 214
- Points
- 5.594
- Level
- 48
- Downloads
- 0
- Uploads
- 0
how would you make it so if x=5 then score+1 when x is pushed? i tried this but it didnt work
if pad:cross() then
screen:blit(184, 213, mallet)
screen.flip()
if count = 6 then
score = score + 1
end
-
02-02-2006, 02:08 PM #462QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
first off, i'm not an experienced coder. (see my sig?) so if someone else comes with a possible solution, ignore me and listen to them, but i'll still try to help.
Zitat von sofa king dumb
from what i see, the problem is what i dont see. your code doesnt mention 5 anywhere. i assume what you want is for the "count" to reach 6.
so this what i think you should do:
if pad:cross() then
screen:blit(184, 213, mallet)
screen.flip()
if count = 5 then --simply change 6 to 5.
score = score + 1
end[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
02-02-2006, 02:53 PM #46311th Squad Captain
- Registriert seit
- Jun 2005
- Ort
- You are here -----> 名前: アダム | 飲むコー
- Beiträge
- 2.562
- Points
- 26.490
- Level
- 97
- Downloads
- 0
- Uploads
- 0
60 = 1 second so 10 equal's 10 Mini sec's or whatever lol...
Zitat von Altair
I just did that because it flicks past the menu too fast so you
wouldnt off been able to select anything ;) .FAVORITE GAME! - BEER & ANIME! - SO EXICTING!

開発者, 携帯用プログラマー 日本サポータおよび恋人 本名のアダムの鍛冶屋
Currently Working On: - Flashmod V2.50 - Flashmod V2.60
Currently Drinking: Coffee! - 私はコーヒーを飲む
Chao Garden: DEMO v0.6
Chao Garden V0.5b Review!
-
02-02-2006, 03:09 PM #464QJ Gamer Bronze
- Registriert seit
- Oct 2005
- Ort
- Alabama
- Beiträge
- 272
- Points
- 5.975
- Level
- 50
- Downloads
- 0
- Uploads
- 0
Explain more about what you are doing... also show more of your code.
Zitat von sofa king dumb
and to compare you use ==
= is an assignment operator
if count == 6 is how you would check for that.
You said earlier you wanted to know how would you make it so if x=5 then score+1 when x is pushed
If you have a main loop the screen.flip() should be at the bottom of your main loop.Code:if pad:cross() and x == 5 then screen:blit(184, 213, mallet) score = score + 1 end
Geändert von PSPMillionaire (02-02-2006 um 03:22 PM Uhr)
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/
-
02-02-2006, 03:25 PM #465QJ Gamer Blue
- Registriert seit
- Jun 2005
- Beiträge
- 375
- Points
- 5.631
- Level
- 48
- Downloads
- 0
- Uploads
- 0
i just want to do a dofile because it makes things seem more organized to me. in my vb programing class once im done with the basics i spend mroe time making it look nicer and more organized then i do on fixing it up.
Zitat von Altair
now for the reason why i quoted. i was wondering if this would work(the part about juust having a Z variable for jumping)
-
02-02-2006, 07:01 PM #466
well it works (i think, i haven't tried it yet), but it wont change the position of the character. By z i meant another variable than x and y, which i, and i think most people, use for the x and y coordinates. The z variable is just there so you can compare the z of the character and the z of the thing you are jumping over (if you have assigned it a specific z value). If you just want the jump animation, then just use the animation.
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-02-2006, 07:03 PM #467
Thx both sofa king dumb and c5cha7, for explaining!
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-02-2006, 11:41 PM #468
- Registriert seit
- Sep 2005
- Beiträge
- 7
- Points
- 4.478
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Im trying to create a stopwatch for my psp but I've run into a few problems
maybe some of you guys could help me out. I've been using MagicianFB's timer example that was posted earlier in this thread but I've run into a few problems. Most importantly is that after 15min or so it 'breaks', it displays 63 minutes and every minute after that it goes it subtracts a minute instead of adding one (62, 61, 60, 59 and so on) Anyone know a way to fix it or have an example of another timer? Here is the example I've been using:
Code:-- Define Colors white = Color.new(255, 255, 255) yellow = Color.new(255, 255, 0) -- Print Instructions screen:print(5, 5, "Press L to begin and R to stop.", yellow) screen:flip() -- Create Timer Timer = Timer.new(0) -- Start Main Program while true do screen.waitVblankStart(5) pad = Controls.read() if pad:l() then Timer:reset() Timer:start() while true do pad = Controls.read() screen:clear() screen:print(5, 5, "Press L to begin and R to stop.", yellow) screen:print(220, 133, tostring(math.floor(Timer :time()/1000/60) .. ":" .. math.floor((Timer:time()/1000/60-math.floor(Timer:time()/1000/60))*60) .. ":" .. string.sub(tostring(math. floor(Timer:time()/10)), -2)), white) screen:flip() if pad:r() then Timer:stop() break end end elseif pad:start() then break elseif pad:select() then screen:save("screenshot.png") end end
-
02-03-2006, 04:04 AM #469
Which example is that? Can you post a link? Oh and there is a stopwatch example in the sample applications that come whith LUA.
EDIT:
Ok i think i have something here:
should be:Code:screen:print(220, 133, tostring(math.floor(Timer :time()/1000/60) .. ":" .. math.floor((Timer:time()/1000/60-math.floor(Timer:time()/1000/60))*60) .. ":" .. string.sub(tostring(math. floor(Timer:time()/10)), -2)), white)
Idon't think you need the "tostring" part aswell. I just don't know if it's possible to display multiple variables then, but probably you can.Code:screen:print(220, 133, tostring(math.floor(Timer:time()/1000/60) .. ":" .. math.floor((Timer:time()/100)/10) .. ":" .. math.floor(Timer:time()/10)), white)
Geändert von Altair (02-03-2006 um 04:32 AM Uhr)
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-03-2006, 04:06 AM #470
Could someone explain what the command "local" means? I sometimes see it in front of some variables i think.
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-03-2006, 06:02 AM #471
W00t!!! I finished my little test game! Its for some reason really addictive, eventhough it's a really stupid game. Its sort of an analog-skillz-trainer. You have to move a really small cursor over a really small target :) .
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-03-2006, 12:38 PM #472
- Registriert seit
- Sep 2005
- Beiträge
- 7
- Points
- 4.478
- Level
- 42
- Downloads
- 0
- Uploads
- 0
Zitat von Altair
I used the code you gave me but it still breaks.... around 8 minutes
-
02-03-2006, 11:03 PM #473words 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
technically, it waits 10 vertical blanks, which are how many times the processor refreshes the screen with what you said, so if you wanted some image to display for 5 seconds, than blit the image or w/e and put Screen.waitVblankStart(60 * 5)
Zitat von Altair
its much easier just to have the psp do the math then have u, look in my other tread about me doing my homewokr in C/C++, youll see in my code (if u understand C/c++ that all i had to know was the procedure inwhich to do the problem, so if it was -x^2 (-x squared), you would do
thats c/c++ simple functions on a graph, meaning the function is x squared then to its opposite, when x = pi, and earlier, pi was definedCode:x = pi; x * x * -1 = y; return y;
you also could do it this way
Code:x = pi; x^2 = y; return y;
Geändert von SG57 (02-03-2006 um 11:08 PM Uhr)

...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
-
02-04-2006, 12:22 PM #474QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Puerto Rico
- Beiträge
- 310
- Points
- 7.109
- Level
- 55
- Downloads
- 0
- Uploads
- 0
The damn thing does not work.I'm using lua player 1.15. I'm just playing around with it. I just want to show a pic and display a some words.Lession one basics, but it doesn't work.Is it ok?This is my code:
testing---------------
black=Color.new(0,0,0)
background=Image.load("ba ckground.png")
screen:blit(0,0,backgroun d,false)
screen.waitVblankStart()
screen.flip()
end
screen
rint(200,130,"It worked Finally",black)
screen:flip()
while true do
screen.waitVblankStart()
end
end
-
02-04-2006, 02:33 PM #475
- Registriert seit
- Feb 2006
- Beiträge
- 5
- Points
- 4.168
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Hi everyone I'm new here and i need a little help.Does someone know how can i create a slideshow with sound and can you upload me the index.lua(1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg and sound.wav)Please help
-
02-04-2006, 02:44 PM #476QJ Gamer Green
- Registriert seit
- Oct 2005
- Beiträge
- 543
- Points
- 6.721
- Level
- 53
- Downloads
- 0
- Uploads
- 0
that might work.....Code:black=Color.new(0,0,0) background1=Image.load("1.jpg") background2=Image.load("2.jpg") background3=Image.load("3.jpg") background4=Image.load("4.jpg") background5=Image.load("5.jpg") sound=Sound.load("sound.wav") while true do screen:clear(black) sound:play() if stage==1 then screen:blit(backround1) stage=2 elseif stage==2 screen:blit(backround2) stage=3 elseif stage==3 screen:blit(backround3) stage=4 elseif stage==4 screen:blit(backround4) stage=5 elseif stage==5 screen:blit(backround5) stage=6 elseif stage==6 screen:blit(backround2) stage=1 end screen.waitVblankStart(90) screen.flip() endHELP ME HAIRY LEG!!!!
I have a 1.5 (downgraded) US PSP
[code]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
( P | S | P | - | P | r | o | g | r | a | m | m | i | n | g )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
_ _ _ _ _
/ \ / \ / \ / \ / \
( A | d | m | i | n )
\_/ \_/ \_/ \_/ \_/ [/code]
-
02-04-2006, 03:03 PM #477
- Registriert seit
- Feb 2006
- Beiträge
- 5
- Points
- 4.168
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I doesnt work but thanks anyway,does anyone else know?
-
02-04-2006, 08:28 PM #478QJ Gamer Silver
- Registriert seit
- Jun 2005
- Ort
- Puerto Rico
- Beiträge
- 310
- Points
- 7.109
- Level
- 55
- Downloads
- 0
- Uploads
- 0
Is my code able to work of not? If not why?
-
02-05-2006, 07:33 AM #479
@ KKDDKK:
Nathan's code is almost right he just forgot to state that "stage =1" at the beginning. That's why it doesn't work because stage is never equal to 1, so it never starts (duh). So just add stage=1 at the beginning.
EDIT: Also change the "backround"'s to "background"'s hehe that might help hehe :P
@shadow-evillink:
Is this your complete code?
if so then it should be:Code:testing--------------- black=Color.new(0,0,0) background=Image.load("background.png") screen:blit(0,0,backgroun d,false) screen.waitVblankStart() screen.flip() end screenrint(200,130,"It worked Finally",black) screen:flip() while true do screen.waitVblankStart() end end
The thing you did wrong was that you put in an "end" while there wasn't any if/while/for/etc. command in fornt of it. Also you have a lot of waitVblankstart's and screenflips, but that should still work, i think.Code:black=Color.new(0,0,0) background=Image.load("background.png") screen:blit(0,0,background,false) screenrint(200,130,"It worked Finally",black) while true do screen.waitVblankStart() screen:flip() endGeändert von Altair (02-05-2006 um 07:35 AM Uhr)
LUA manual:
[url]http://www.lua.org/manual/5.0/manual.html[/url]
LUA Wiki:
[url]http://wiki.ps2dev.org/psp:lua_player[/url]
-
02-05-2006, 11:28 AM #480
- Registriert seit
- Feb 2006
- Beiträge
- 5
- Points
- 4.168
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I edited it like this but it shows Error: index.lua:16: 'then' expect near 'screen'Code:stage =1 black=Color.new(0,0,0) background1=Image.load("1.jpg") background2=Image.load("2.jpg") background3=Image.load("3.jpg") background4=Image.load("4.jpg") background5=Image.load("5.jpg") sound=Sound.load("sound.wav") while true do screen:clear(black) sound:play() if stage==1 then screen:blit(background1) stage=2 elseif stage==2 screen:blit(background2) stage=3 elseif stage==3 screen:blit(background3) stage=4 elseif stage==4 screen:blit(background4) stage=5 elseif stage==5 screen:blit(background5) stage=6 elseif stage==6 screen:blit(background2) stage=1 end screen.waitVblankStart(90 ) screen.flip() end
Error: No script file found
Can someone please upload the whole document but the working one


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