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; noob question: i want to make part of an image transparent. and i am using gimp image editor (works alright) ...
-
06-19-2009, 03:28 PM #9931QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
noob question: i want to make part of an image transparent. and i am using gimp image editor (works alright) and i want to make a middle part of the image transparent (or just gone completly) any tips?
-
06-19-2009, 03:45 PM #9932Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Well in paint.net you just have to select the area you want transparent, & cut it. If you want it partiallh transparent then you simply change the alpha value in the paint window (the window were you click to chose your colours & theres the colour circle.)
Don't know about gimp though, to save time install paint.net, once you've finished unistall it
-
06-19-2009, 04:59 PM #9933QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 106
- Points
- 2.716
- Level
- 31
- Downloads
- 0
- Uploads
- 0
the default password is ur psp s system nickname but i wanted 2 make an option 2 change the password from within the program so people w/out knowledge of lua wont have 2 manually open the lua file 2 change the password . ive tried both though w/file:read("*a") and file:read(*n) but it just seems 2 be having problems comparing the osk input with reading the file
-
06-19-2009, 06:48 PM #9934QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
k. thanks for the help dan369
-
06-20-2009, 02:20 PM #9935QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
Well I'm completely stumped by this. How do I make music loop in the latest Luaplayer HM. I tired all sorts of techniques but nothing is working.Let me give you situation.
I load an Ogg then I play it in my main loop. Then I try to stop the music near the end and re-play the music. This is pretty much the gist of how I'm trying to do it:
Code:BG1 = Ogg.load("Music.ogg") music = true while true do pad = Controls.read() if music == true then Ogg.play(BG1) end if music == false then Ogg.stop(BG1) end if pad:circle() then music = true end if pad:cross() then music = false end end
-
06-20-2009, 03:55 PM #9936Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
it'll only play if your holding circle add this:
Code:oldpad = Controls.read() --in main loop if pad:circle() and not oldpad:circle() then --do stuff end --near the end of your script oldpad = pad
-
06-20-2009, 05:46 PM #9937QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
-
06-21-2009, 09:50 AM #9938Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Yes it does, when you press circle the state would be true, when you let go it'll go to false. I've been doing this for about 2 and a half years now, i think i can tell you the problem (sarcasm).
Use tostring to print 'music' to the screen, that'll show you that i'm correct.
-
06-21-2009, 10:18 AM #9939QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
i have a question about zoom. i have tried adding to size by just pressing the button (wich i didnt get to work :P)but i was wondering if their was a code i could implement to make it steadily zoom.
heres the code if it helps (i was just messing around with code to make this box move around screen)
Code:blue=Color.new(0,0,255) i = 32 box=Image.createEmpty(i,i) box:clear(blue) Box={x = 30, y = 100} screenwidth = 480 - box:width() screenheight = 272 - box:width() function move() if Box then Box.x = Box.x - 1 end end function moveUp() if Box then Box.y = Box.y - 1 end end function collide() if Box.x < 0 then Box.x = Box.x + 480 end end function collideUp() if Box.y < 0 then Box.y = Box.y + 272 end end while true do pad = Controls.read() screen:clear() screen:blit(Box.x,Box.y,box) if pad:start() then break end if pad:r() then i = i + 50 end collide() collideUp() move() moveUp() screen.waitVblankStart() screen.flip() end
-
06-21-2009, 12:56 PM #9940QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
That's completely false. I think you should review my code.
It doesn't just magically become false for no reason. The only way that would happen is if I put the music variable in my loop which I obviously didn't do.
Now onto the problem I am having. Whenever I use Ogg.stop() I can't use Ogg.play(). So I see no way of making a loop. I've tried making another while loop. I've tried loading dummy music file in addition to my other music file. I've tried checking to see when the music stops then using a Ogg.play(). and a whole lot more.
This looks fine if you want it to "steadily" zoom. (I assume you want to control the rate) Just edit your i = i + 50. 50 seems a bit much though I'd try 4 or something like that.
But if you want maximum control over the rate at which it zooms try:
The way above would give absolute control over the rate at which your box zooms. You could have it zoom fast then slow.Code:counter = 0 function BoxZoom() counter = counter + 1 if counter == 5 then i = 2 end if counter == 10 then i = 3 counter = 0 end end
-
06-21-2009, 02:03 PM #9941QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Sorry dan, but you are wrong in this case. The flag music ONLY gets assigned false when cross is pressed.
However Xteaph-N, you do realise that play or stop is getting called EVERY frame depending on the state of the flag which isn't recommended and to be honest, I am surprised it even works as it is now.
Add another flag that represents if the music is playing or not so you can correctly decide when to call play and stop.[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]
-
06-21-2009, 02:20 PM #9942Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Yeah my bad, just realised what he has done. He shouldn't use stop, he should be using pause that is un-less you want it to start from the beginning.
I got it muddled up, i thought he set music to false but he set it to true at the beginning, but like yaustar said the 'state' only changes whilst your pressing cross.
-
06-21-2009, 04:28 PM #9943QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
I could call it out differently like so:
However this doesn't help. Whenever I use Ogg.stop() function I can no longer use Ogg.play(). I am completely stumped as how I could make a loop; being this as the case.Code:BG1 = Ogg.load("Music.ogg") music = true if music == true then Ogg.play(BG1) end if music == false then Ogg.stop(BG1) end while true do pad = Controls.read() if pad:circle() then music = true end if pad:cross() then music = false end end
I've already tried multiple things in and out of my loop and none seem to work.
Ok, this is really upsetting me now. Go back and read the last 3 posts I've made in this thread. If you've done that you will see I've been repeating myself exclusively to you. In all 3 posts they've been about a "music loop". I don't see how you could not have gotten this. It was quite plan. There is no point in trying to help someone if you don't pay attention to what they are saying.
-
06-21-2009, 05:13 PM #9944QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
thanks for the response Xteaph-N. but for some reason it still doesnt zoom at all. it stays at one size. here is the code now
Code:blue=Color.new(0,0,255) i = 32 box=Image.createEmpty(i,i) box:clear(blue) Box={x = 30, y = 100} screenwidth = 480 - box:width() screenheight = 272 - box:width() counter=0 function BoxZoom() counter=counter+1 if counter == 5 then i = 2 end if counter == 10 then i = 3 counter = 0 end end function move() if Box then Box.x = Box.x - 1 end end function moveUp() if Box then Box.y = Box.y - 1 end end function collide() if Box.x < 0 then Box.x = Box.x + 480 end end function collideUp() if Box.y < 0 then Box.y = Box.y + 272 end end while true do pad = Controls.read() screen:clear() screen:blit(Box.x,Box.y,box) if pad:start() then break end if pad:r() then i = i + 5 end BoxZoom() collide() collideUp() move() moveUp() screen.waitVblankStart() screen.flip() end
-
06-21-2009, 05:14 PM #9945Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
I help loads of people, i made one mistake & you come down on me. I'm not going to even bother now.
Geändert von dan369 (06-21-2009 um 05:31 PM Uhr)
-
06-21-2009, 06:05 PM #9946QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
Oh, your not calling my function right. This is a way you can call it:
Also I realized I made a simple mistake with the BoxZoom() function which is also fixed here. I've also added comment where I changed things.Code:blue=Color.new(0,0,255) i = 32 box=Image.createEmpty(i,i) box:clear(blue) Box={x = 30, y = 100} screenwidth = 480 - box:width() screenheight = 272 - box:width() counter=0 function BoxZoom() counter=counter+1 if counter == 5 then --This is why it wasn't zooming -- Also causes slow increase i = i + 2 -- Rate of zoom variable end if counter == 10 then --This will be a faster zoom i = i + 5 -- Rate of zoom variable counter = 0 end end function move() if Box then Box.x = Box.x - 1 end end function moveUp() if Box then Box.y = Box.y - 1 end end function collide() if Box.x < 0 then Box.x = Box.x + 480 end end function collideUp() if Box.y < 0 then Box.y = Box.y + 272 end end while true do pad = Controls.read() screen:clear() screen:blit(Box.x,Box.y,box) if pad:start() then break end --Pressing R activates the function if pad:r() then BoxZoom() end collide() collideUp() move() moveUp() screen.waitVblankStart() screen.flip() end
I also want you to know the way in which it grows will be slow then fast, slow then fast et cetera. But you can easilly change that to what ever you want.
*faceplam* Uhg, read my last post. You made 5 mistakes.(not including this one)
1. Ignoring my question
2. Your answer was wrong
3. Ignoring my question again
4. Your rebuttal was wrong
5. Ignoring my question again
Also I'm only upset because you had no idea(it seemed) what the problem was. I'm sure you help a lot of people, I've also helped lots of people too in hardware. However I was only pointing out something as a matter of fact. I wasn't "coming down" on you.
Here is what I said:
All of this is fact, there was no mean intention in it.
Too further prove my point; I could have said all kinds of mean factual statements like "You are just being plain incompetent". But I chose instead to not use that version. Your just acting childish right now. I could continue to explain but I think this is enough.
-
06-21-2009, 06:20 PM #9947Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Look now i'm going to ignore that post, seeing as if i wanted to i could point out loads of mistakes with the things you have coded but i'll leave it at that.
Now if you actually used the simplest of debugging, just simply printing 'music' to the screen then you'd see that there is a problem with Hmv2. I tried my own program, similar to yours. When i press circle, using your script, music got set to 'true' so it should play. But it didn't, this isn't a code problem but i think it's a HM problem. Also i tried to just pause the music for a moment but neither did that work, it plays tiny parts of the song instead of just pausing & re-playing when i feel like it.
Note: music was set to false when i tried to set music back to true. Just to say
Now let me point out the mistakes seeing as you do it with me:
if statements are always:
There's no need for the == true part. For false you'd do thisCode:if somethingIsTrue then do stuff end
'Music' is a bad variable name, it doesn't tell me anything about what it is used for only that it is used in connection with 'music'. Something like 'musicIsPlaying'. Also indent and use spaces because your code is all together and looks rather ugly.Code:if not something then do something end
Edit: Though there is a possibility that the code is wrong, i don't use Hmv2 mostly so my code my not be 100% correct but, with what i have it seemed that it was a Hm problem.
-
06-21-2009, 06:46 PM #9948QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
k. i tried making the changes and it didnt work. then i tried copying ur code and it still didnt work. so im thinking it is the way im "blit"ing the box to the screen or my version of lua player. i have luaplayer 0.20. any more suggestions would be appreciated. btw thanks for the responses Xteaph-N, :)
-
06-21-2009, 07:53 PM #9949QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
I already know I don't organize my code very well. But this is only superficial both ways work the same. The reason you see me doing it like:
"Music == true"
is because I'm not always using a boolean statement sometimes I have things like:
"Music == BGM1"
"Music == BGM2"
I have these statements which aren't boolean, and so it wouldn't make sense to put Music_Is_Playing. Besides I like to read spaghetti code. Though your correct if we where only doing boolean, which as I stated will not be the case. As for indentation, I simply hate them. I like them in C/C++, but in lua I it's hard for my eyes to look at it.
I always thought this was a problem with the player itself. I tried asking the dev of the player and got no reply as of this post.
I see I just tried to make it in luaplayer 0.20, and you are right. The problem is in the way it blits. The variable i is increasing but the box is not for some reason. I guess that part is not looping, just how it was made I guess.
Luaplayer HM has a resize function. Image.resize() example:
Image.resize(100,100,box)
Also this works on PNG image files too!
-
06-21-2009, 07:53 PM #9950QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
-
06-21-2009, 09:04 PM #9951QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
darn i was hoping my guess was wrong. is coding for hm much different than coding for just regular? and if i was gonna go off what i know, should i learn hm or pge? suggestions?
-
06-21-2009, 10:48 PM #9952QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
HM is going to be most similar to what your using now. PGE is much different then HM. But PGE is going to be your best bet. It's a bit more complex but the trade of is certainly worth it. But for what your doing PGE might not have the resize function.
But I think this is a good solution to your problem in luaplayer 0.20.
Also I was thinking this might also be a solution:
Tell me what you think?Code:blue=Color.new(0,0,255) box1=Image.createEmpty(32,32) box1:clear(blue) box2=Image.createEmpty(47,47) box2:clear(blue) box3=Image.createEmpty(62,62) box3:clear(blue) box4=Image.createEmpty(77,77) box4:clear(blue) box5=Image.createEmpty(92,92) box5:clear(blue) Box={x = 30, y = 100} Image_Change = box1 screenwidth = 480 screenheight = 272 counter=0 function BoxZoom() counter=counter+1 if counter == 5 then Image_Change = box2 end if counter == 10 then Image_Change = box3 end if counter == 15 then Image_Change = box4 end if counter == 20 then Image_Change = box5 counter = 0 end end while true do pad = Controls.read() screen:clear() if pad:r() then BoxZoom() end screen:blit(Box.x,Box.y,Image_Change) if pad:start() then break end screen.waitVblankStart() screen.flip() end
I'm not going to do it. It really disorients me. Besides I bet none will try to learn from my lua script anyway.
-
06-21-2009, 11:27 PM #9953QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
YES. This will work. all i need to do is switch image back and forth. while holding r. thanks for the help. :)
-
06-21-2009, 11:46 PM #9954QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
-
06-22-2009, 04:20 AM #9955Lua guy
- Registriert seit
- Jan 2008
- Ort
- Wales, cardiff
- Beiträge
- 1.442
- Points
- 11.690
- Level
- 71
- My Mood
-
- Downloads
- 0
- Uploads
- 0
-
06-22-2009, 09:20 AM #9956QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Beiträge
- 69
- Points
- 2.018
- Level
- 27
- Downloads
- 0
- Uploads
- 0
sorry double post. please delete this one
-
06-22-2009, 12:24 PM #9957QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
Well, no there is a glitch in HM. You can't call out Ogg.stop() unless you plan on stopping forever. But I found a pretty good way around this. I'll just compose the music myself in lua.
Let me demonstrate an example:
This is just my concept I haven't actually done it yet, nor do I know the code above will work. Though this should work in theory. Even if this doesn't work it is obviously possible so I will do it.Code:Piano_A = Sound.load("A.wav") Piano_B = Sound.load("B.wav") Piano_C = Sound.load("C.wav") Piano_D = Sound.load("D.wav") Piano_E = Sound.load("E.wav") Piano_F = Sound.load("F.wav") Piano_G = Sound.load("G.wav") Piano_AS = Sound.load("A#.wav") Piano_BS = Sound.load("B#.wav") Piano_CS = Sound.load("C#.wav") Piano_DS = Sound.load("D#.wav") Piano_ES = Sound.load("E#.wav") Piano_FS = Sound.load("F#.wav") Piano_GS = Sound.load("G#.wav") Tempo = 1 Counter = 0 function BGM1() Counter = Counter + Tempo if Counter >= 100 and Counter <= 199 then Piano_A:play() end if Counter == 200 and Counter <= 299 then Piano_A:play() end if Counter == 300 and Counter <= 399 then Piano_A:play() end if Counter == 400 and Counter <= 499 then Piano_A:play() end --Et Cetera..... end while true do pad = Controls.read BGM1() -- This increases the tempo of the song, I.E. Speed if pad:right() then Tempo = Tempo + .1 end if pad:left() then Tempo = Tempo - .1 end screen.waitVblankStart() endGeändert von Xteaph-N (06-22-2009 um 01:15 PM Uhr)
-
06-22-2009, 05:39 PM #9958QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
That's a crappy way to do it.
Code:noteNames = {'A', 'A#' 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'} pianoSounds = {} for i, noteName in ipairs(noteNames) do pianoSounds[noteName] = Sound.load(noteName .. '.wav') end song = { {length = 1, name = 'E'}, {length = 1, name = 'D'}, {length = 1, name = 'C'}, {length = 1, name = 'D'}, {length = 1, name = 'E'}, {length = 1, name = 'E'}, {length = 2, name = 'E'} } for i, note in iparis(song) do pianoSounds[note.name]:play() wait(note.length) end
-
06-22-2009, 05:55 PM #9959QJ Gamer Blue
Achievements:
- Registriert seit
- May 2009
- Ort
- California
- Beiträge
- 75
- Points
- 2.165
- Level
- 28
- Downloads
- 0
- Uploads
- 0
-
06-22-2009, 06:35 PM #9960QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Huh?


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