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; Just a heads up: JaX3RiR has recompiled Lua Player V0.16 to 3.XX kernel now (The other one you guys linked ...
-
01-05-2008, 05:48 AM #8251
Just a heads up:
JaX3RiR has recompiled Lua Player V0.16 to 3.XX kernel now
(The other one you guys linked to above, was V0.20)
[RELEASE]3.XX Kernel homebrew pack
PSP: PSP SLIM 2001 TA-088v2Custom Firmware: 5.00 M33-6
-
01-05-2008, 06:24 AM #8252Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
doesn't work
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-05-2008, 11:58 AM #8253lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Sweet!
Zitat von Mr_Shizzy
-
01-05-2008, 12:51 PM #8254
- Registriert seit
- Dec 2007
- Beiträge
- 4
- Points
- 2.781
- Level
- 32
- Downloads
- 0
- Uploads
- 0
Alright, I've been learning Lua for couple months now, and I'm stumped by this error message:Code:blue = Color.new(0,0,255) white = Color.new(255,255,255) red = Color.new(255,0,0) green = Color.new(0,255,0) test = {x = -8, y = 243, speed = 3, img = Image.createEmpty(8, 8)} test.img:clear(green) box1 = Image.createEmpty(480, 80) box1:clear(blue) line = Image.createEmpty(5, 80) line:clear(white) line1 = Image.createEmpty(90, 5) line1:clear(white) line2 = Image.createEmpty(3, 52) line2:clear(white) back = Image.createEmpty(480, 140) back:clear(red) function drawimages() screen:blit(0, 141, box1) screen:blit(101, 141, line) screen:blit(196, 141, line) screen:blit(0, 0, back) screen:blit(106, 141, line1) screen:blit(106, 216, line1) screen:blit(239, 221, line2) screen:blit(test.x, test.y, test.img) end function drawtext() screen:print(116, 151, "Fight", white) screen:print(116, 166, "Harmony", white) screen:print(116, 181, "Dissonance", white) screen:print(116, 196, "Items", white) end function test() if test.x < 500 then test.x = test.x + test.speed end end while true do screen:clear() drawimages() drawtext() test() screen.waitVblankStart() screen.flip() end
What am I doing wrong?34:attempt to index global 'test' (a function value)
Note: The code should cause an 8x8 green block scroll from offscreen on the left side of the screen to offscreen on the right side.
-
01-05-2008, 01:07 PM #8255QJ Gamer Bronze
- Registriert seit
- Mar 2007
- Beiträge
- 758
- Points
- 8.665
- Level
- 62
- Downloads
- 0
- Uploads
- 0
I'm pretty sure it's because you have a function called test and an array/table called test. Rename one of them. Then I THINK it will work.
-
01-05-2008, 01:07 PM #8256QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
You named "test" a table AND a function.
Zitat von Foxhull
Rename one of them.
Dang it, michaelp beat me to it. lol[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
01-05-2008, 01:10 PM #8257
- Registriert seit
- Dec 2007
- Beiträge
- 4
- Points
- 2.781
- Level
- 32
- Downloads
- 0
- Uploads
- 0
thanks, i'll try that
EDIT: Thanks, works now.
-
01-05-2008, 01:15 PM #8258QJ Gamer Green
- Registriert seit
- Dec 2005
- Ort
- Here
- Beiträge
- 2.715
- Points
- 13.310
- Level
- 75
- Downloads
- 0
- Uploads
- 0
Come back for any help you need. :)
[CENTER][IMG]http://img148.imageshack.us/img148/6985/siglw8.jpg[/IMG][/CENTER]
-
01-09-2008, 10:32 AM #8259
This is bugging the hell out of me. What EXACTLY is the screen object? I used to think it was an image, but when I tried to use it like one, it told me it was a table (With no elements in it). Can someone please explain it to me? I need to find a way to use it like an image object.
-
01-09-2008, 10:37 AM #8260Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
it is like a container
- if you blit an image to it it contains that data like a table if you want to use it like an image you cant i like to blit a blank image to it 480 x 272 and use that instead then it will act like a screen and an image
just remember
image_screen = image.createEmpty(480, 272)
then
image_screen.flip() and so on
thanks------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-09-2008, 01:07 PM #8261
I see.... I was trying to copy the screen into another variable:
But obviously this didn't work. Do you know any way I could make it work?Code:zoomOut = screen
-
01-09-2008, 02:08 PM #8262Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
why may i ask do you want to do that
from what you have said i can hazzard a guess that you want to take the screen content and soom out from it you could do this one of two ways that i can think of
screen:save() the screen and resize that
or
use the gu functions i dont know the specific commands off my head as i try to avoid using them where i dont need to and also because i havent learnt to use them properly
thanks------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-09-2008, 04:38 PM #8263lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
Learn the GU functions.
Its faster.
-
01-10-2008, 09:24 AM #8264
Your dead on. It's not REALLY a zoom effect though, more of a cropping effect. I was considering doing the screen:save(), but it wouldn't really be that efferent since I would have to save a file and delete it every time. I guess I'll have to learn the GU functions. Thanks. :)
Zitat von FaT3oYCG
-
01-10-2008, 09:42 AM #8265Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
What did you use for mazegen then ?
Zitat von Highsight
-
01-10-2008, 10:13 AM #8266
That was 3DGU, I believe they are referring to non 3D GU functions... right? XD
Incidentally, where can I learn about the GU functions Anti? I can't seem to find anything other than 3D GU, and I don't see how those would help. :/
-
01-10-2008, 10:19 AM #8267Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
its gu and gum commands if i am correct the 3d cube shows most of the commands but if you want to crop an image im sure that there is a much simpler way
for example create a blank image the size that you would like to crop to this will act like a view finder then blit the original image to that with minus co ordinate for that image and only the part that you want to see should be shown - that isnt a very good way though
im sure that screen:blit() accepts about 7 commands max which will do what you want with ease one mo ill try and find out the specific order they are in
EDIT:
screen:blit(x position, y position, full image to use, tile x start position on that image, tile y start position on that image, tile width, tile height)
an example of this would be
Code:lua_image = Image.load("lua_image.png") -- for example 200 x 200 image screen:blit(10, 10, lua_image, 30, 40, 100, 100) -- blits the image to 10, 10 x and y co-ordinates, tells it to use the lua_image and start 30 across from the start position in the image and 40 down, then takes 100 x 100 pixels of the image and blits that------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-10-2008, 10:35 AM #8268
Er, my code is already set up just like that, but that's not the problem. XD The problem is that the image I want to crop is an image that I get from the screen. What I am trying to do is create a transition between the player playing the game, and the brief pause between each game. So to do that, I need to get a picture of the screen and use that for the cropping process. The only thing is, I would like to be able to do this WITHOUT saving it as a PNG first, I would much rather use it as an Image object, if that is possible.
Zitat von FaT3oYCG
-
01-10-2008, 10:56 AM #8269QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Try creating a smaller blank image that is size of the crop and blitting the screen onto the blank image. No idea if it works though.
[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]
-
01-10-2008, 10:57 AM #8270Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
in that case wouldn't cropping_image = screen:save() do the trick and use that ??? not sure but anyway if you dont want to keep the image there is a function in lua to save a file as a temporary file and it is deleted after it has finished being used - you would have to search for that though
EDIT:
oh and yaustar i mentioned that before
Zitat von FaT3oYCG
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-10-2008, 11:01 AM #8271QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
screen:save returns nil and ALWAYS saves to the memory stick.
-= Double Post =-
Why wouldn't it be a good way?
Zitat von FaT3oYCG
Geändert von yaustar (01-10-2008 um 11:02 AM Uhr) Grund: Automerged Doublepost
[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]
-
01-10-2008, 11:02 AM #8272Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
fair enough oh and i wasn't trying to undermine you sorry if it seemed that way
because it is using minus values what i meant was there may be better ways but i dont like using minus values in my code, most of the time you could use an addition instead just by revising your code but i guess this is an exception------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-10-2008, 11:29 AM #8273QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Why don't you like using minus numbers? It really seems a little odd especially in programming.
Zitat von FaT3oYCG
[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]
-
01-10-2008, 12:09 PM #8274Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
because most of the time using a negative number will make your code more hard to understand and sometimes more complicated than it needs to be
not that this would happen but say for example you wanted to print some text at 10, 10 then you could use this
screen:print(480 - 470, 272 - 262, "text", white)
but that is much harder than just putting
screen:print(10, 10, "text", white)
i just used that as an example but you should get what i mean as when it does occur it is usually with complex code
but as i said that is why i try to avoid using minus numbers where i can------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-10-2008, 01:03 PM #8275Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
thats just bad programing. you're unnecessarily doing two subtractions every frame. but i dont usually have a problem with minus values, unless they're used the way you mentioned. other than that, they're ok.
--------------------------------------------------------------------------------------
-
01-10-2008, 01:15 PM #8276Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
thats my point basically what im trying to say is that i dont like using minuses as they make the code sometimes do unnecesary calculations that is why i try to avoid using them i was only using that as an example to show that i dont use them because it sometimes makes the code unefficient i will use them where needed but as you say if you use a minus where none is needed its bad programming - if you are doing complex coding whith lots of variables and values then you may unnececarily use a subtraction where the value can be obtained by not doing one which is uneficcient coding
Zitat von Grimfate126
if you still dont understand what i mean then dont try to instead read my sig and you will understand why
but anyway i think we have had enough discussion on using minuses on the help thread so lets leave it there------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).
-
01-14-2008, 06:00 PM #8277
Hi all,
Am new to Lua and relatively new to programming too i guess, anyway can anoyne help me with this problem please. I am getting the "loop in gettable" error when i try to mute my music. Code below:
The screenshot and quit functions mapped to Select and Start respectively work fine, however when i try to stop the music or set Music.volume(0) i get "error - loop in gettable".:Argh:Code:-- Activate USB Mode System.usbDiskModeActivate() -- Define Color White white=Color.new(255,255,255) -- Load Loading Image loadingImage = Image.load("images/loading.jpg") -- Print Loading Image as Background screen:blit(0, 0, loadingImage, false) screen.waitVblankStart() screen:print(200,130,"Loading - 0%",white) screen.flip() -- Begin Loading All Other Images backgroundImage = Image.load("images/background.jpg") screen:clear() screen:print(200,130,"Loading - 20%",white) screen.flip() gameimageImage = Image.load("images/game.jpg") screen:clear() screen:print(200,130,"Loading - 40%",white) screen.flip() dartImage = Image.load("images/dart.jpg") screen:clear() screen:print(200,130,"Loading - 60%",white) screen.flip() gameoverImage = Image.load("images/gameover.jpg") screen:clear() screen:print(200,130,"Loading - 80%",white) screen.flip() themeSound = Sound.load("sounds/theme.wav", true) splashImage = Image.load("images/splash.jpg") screen:clear() screen:print(200,130,"Loading - 100%",white) screen.flip() --Pause At 100% screen.waitVblankStart(60) --Clear The Screen Of Loading Text screen:clear() --Load The Splash Screen screen:blit(0, 0, splashImage, false) screen.flip() --Pause For One Second screen.waitVblankStart(180) --Load The Background Image screen:blit(0, 0, backgroundImage, false) screen.flip() --Play The Theme Music Music.volume(128) themeSound:play() --Update The Screen screen.waitVblankStart() while true do pad = Controls.read() if pad:start() then break end if pad:select() then screen:save("screenshot.png") end if pad:l() then if themeSound:playing() then themeSound:stop() else themeSound:play() end end end
If anyone can offer some pointers please i would be most grateful.
Many thanks.
-
01-14-2008, 07:29 PM #8278QJ Gamer Silver

- Registriert seit
- May 2006
- Ort
- Behind you.
- Beiträge
- 1.814
- Points
- 10.921
- Level
- 69
- Downloads
- 0
- Uploads
- 0
Ok, i haven't seen lua in a while (concept is same though), but here are some tips:
1) Try to indent properly. It helps when you have your code organized.
2) It seems that you are loading a lot of images, but not blitting them.
3) Instead of having a lot of "Loading..." printing, you could make a only one "Loading" printing when "if" blah is true, then change the "%" of loading. For example, if some image finishes loading, update the loading "%".Geändert von SuperBatXS (01-14-2008 um 07:54 PM Uhr)
Calypso - Enjoy the excellent 2D space shooter:
http://dl.qj.net/Calypso-v1-PSP-Home...6542/catid/195
"Quoting yourself in your signature means you love to masterbate while looking at the mirror." -me (oh, wait...)
-
01-15-2008, 06:34 AM #8279
Also, when blitting an image, you don't need the fourth argument. You only need it if it's true.
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
01-15-2008, 09:36 AM #8280Developer and Tutor.
- Registriert seit
- Jul 2007
- Ort
- Widnes, England
- Beiträge
- 1.649
- Points
- 8.736
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
other than the fact your code is set out wrong well its in the wrong order - logical order
Zitat von Andysan
for a start the Music.volume(128) is before while true do
so threfore if you change it its not true so it will crash
looks like you have some logic and indenting errors
- try fix your logic and indenting and see if it works
EDIT:
here i fixed most of it for you and laid it out better with proper indentations
here is a simple lua file template aswellCode:-- Activate USB Mode - should only be done while testing or creating a game with a game refresh function to start ti again if you save a file currently in use System.usbDiskModeActivate() -- Define Color White white = Color.new(255,255,255) -- Load Loading Image loadingImage = Image.load("images/loading.jpg") -- Load All Other Images backgroundImage = Image.load("images/background.jpg") gameimageImage = Image.load("images/game.jpg") dartImage = Image.load("images/dart.jpg") gameoverImage = Image.load("images/gameover.jpg") splashImage = Image.load("images/splash.jpg") themeSound = Sound.load("sounds/theme.wav", true) -- Print Loading Image as Background screen:blit(0, 0, loadingImage, false) screen.waitVblankStart() -- display loading text screen:clear() screen:print(200,130,"Loading - 0%",white) screen.flip() screen:clear() screen:print(200,130,"Loading - 20%",white) screen.flip() screen:clear() screen:print(200,130,"Loading - 40%",white) screen.flip() screen:clear() screen:print(200,130,"Loading - 60%",white) screen.flip() screen:clear() screen:print(200,130,"Loading - 80%",white) screen.flip() screen:clear() screen:print(200,130,"Loading - 100%",white) screen.flip() --Pause At 100% - for 1 second screen.waitVblankStart(60) --Clear The Screen Of all previous data screen:clear() --"display" The Splash Screen screen:blit(0, 0, splashImage, false) screen.flip() --Pause For One Second - that is three seconds 60 miliseconds in one second screen.waitVblankStart(180) -- "display" The Background Image screen:blit(0, 0, backgroundImage, false) screen.flip() --Update The Screen - keep whatever is on the screen untill told not to screen.waitVblankStart() while true do pad = Controls.read() --Play The Theme Music Music.volume(128) themeSound:play() if pad:start() then break end if pad:select() then screen:save("screenshot.png") end if pad:l() then if themeSound:playing() then themeSound:stop() else themeSound:play() end end end
thanksCode:white = color.new(255, 255, 255) -- create white as a colour oldpad = Controls.read() -- set oldpad as a secondary controller setup while true do -- while the above is true pad = Controls.read() -- set pad as a primary controller setup screen:clear() -- clear anything previously on the screen -- insert your main code here -- e.g. if pad:cross() then -- if cross is being held screen:print(10, 10, "i pressed cross", white) end if pad:cross() and oldpad:cross() ~= pad:cross() then -- do something if cross is pressed and not held end -- insert your main code here if Controls.read():start() then -- if you press start exit break -- break the current state end -- end the if oldpad = pad -- oldpad is the same as pad screen.flip() -- flip the screen at the end of every while loop - if set right the while loop should be continuous screen.waitVblankStart() -- keep any of that data on the screen untill specified otherwise end
Geändert von FaT3oYCG (01-15-2008 um 09:58 AM Uhr)
------ FaT3oYCG -----
AKA Craig, call me what you want to It's your preference.
My Website: http://www.modern-gamer.co.uk/
Currently working on:
(0) MediaGrab
(0) PGE Gears Of War - On hold (Very large project).
(0) PS???? -On Hold A tactical 2d side scrolling game involving AI and online multiplayer features. - Tile engine nearley finished (1 bug to fix).


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