PSP music (NOOB)

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
darklitch
Posts: 11
Joined: Mon Oct 03, 2005 9:55 am
Contact:

PSP music (NOOB)

Post by darklitch »

I just started this lua programing 4 days ago and I can not figure out what is wrong with my script:

Code: Select all

if pad:cross() then
		if Music.playing() then
			Music.stop()
			gunshot:play()
		else
			gunshot:play()
		end
	end
I keep getting multiple instances of my gunshot audio. Any suggestions?[/code]
Koba
Posts: 59
Joined: Thu Sep 29, 2005 10:57 am

Post by Koba »

doesn't seem like it should run at all... music:playing isn't a real command afaik... try doing this:

Code: Select all

music:play()
music = true
if pad:cross() then
   if music == true then
      music:stop()
      gunshot:play()
   else
      gunshot:play()
   end
end
that would be easier imo, try it out and come back and tell me how it worked out, and remeber, variables are your friend :D
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: PSP music (NOOB)

Post by Shine »

Koba: you are right, music:playing is not a command, but the posted one, Music.playing(), is available.

[quote="darklitch"]I just started this lua programing 4 days ago and I can not figure out what is wrong with my script:

Code: Select all

if pad:cross() then
		if Music.playing() then
			Music.stop()
			gunshot:play()
		else
			gunshot:play()
		end
	end
You know that "if something then x else x end" is a tautology? You can just extract the gunshot:play() after the if-end block.

With "multiple instances" you mean you hear the sound multiple times at once? This might be because you call the play multiple times, because you might call the if pad:cross in some loop and as long as the cross is hold down, the music is started over and over again (I think there are 4 channels avaible, so you'll hear a chord of 4 musics playing). Check for pad changes, to play it only once when cross is pressed.
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

yeah, looks like you're probably retriggering it multiple times because the button is being held down.
Chaosmachine Studios: High Quality Homebrew.
Koba
Posts: 59
Joined: Thu Sep 29, 2005 10:57 am

Post by Koba »

ahhh looks like i need to look harder at posts from now on, thanks for correcting me Shine! i hope to be a LUA god like most of you guys soon ;)
darklitch
Posts: 11
Joined: Mon Oct 03, 2005 9:55 am
Contact:

Post by darklitch »

I am just getting started. How can i detect it as only pressed once? In other languages there are things like on (release) and on (press) is there anything like this in lua?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

darklitch wrote:I am just getting started. How can i detect it as only pressed once? In other languages there are things like on (release) and on (press) is there anything like this in lua?
Mr_Snuffle has started such a library, which can be done in pure Lua:

http://forums.ps2dev.org/viewtopic.php?p=22084#22084

perhaps send him a PM, if it is ready.
User avatar
JoshDB
Posts: 87
Joined: Wed Oct 05, 2005 3:54 am

Post by JoshDB »

Add System.sleep(25) to button-reading functions. This will make it wait enough so that you don't execute the function multiple times very rapidly. However, when you hold it down, it will loop again after that short wait is over.

Toy around with the time paused (25) and get something you're comfortable with.
darklitch
Posts: 11
Joined: Mon Oct 03, 2005 9:55 am
Contact:

Post by darklitch »

When I tried the System.sleep(25) thing, I got the error "attempt to call field 'sleep' (a nil value)" at first i thought it was because i forgot to add the 25 in it, but it was there. I tried something called wait(25), but that does not do what i want because when i call it, my sound works but my crosshair stops moving when i use it. Any suggestions?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

darklitch wrote:When I tried the System.sleep(25) thing, I got the error "attempt to call field 'sleep' (a nil value)" at first i thought it was because i forgot to add the 25 in it, but it was there. I tried something called wait(25), but that does not do what i want because when i call it, my sound works but my crosshair stops moving when i use it. Any suggestions?
You need version 0.11 for System.sleep, but it is not a good idea to use it to avoid multiple event on on key press. See http://www.luaplayer.org/gallery/calculator.lua.txt for an example how to do it the right way.
darklitch
Posts: 11
Joined: Mon Oct 03, 2005 9:55 am
Contact:

Post by darklitch »

that is exactly what i needed. Thanks shine
Post Reply