| View previous topic :: View next topic |
| Author |
Message |
darklitch
Joined: 03 Oct 2005 Posts: 11
|
Posted: Mon Oct 03, 2005 10:01 am Post subject: PSP music (NOOB) |
|
|
I just started this lua programing 4 days ago and I can not figure out what is wrong with my script:
| Code: | 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] |
|
| Back to top |
|
 |
Koba
Joined: 29 Sep 2005 Posts: 59
|
Posted: Mon Oct 03, 2005 10:12 am Post subject: |
|
|
doesn't seem like it should run at all... music:playing isn't a real command afaik... try doing this:
| Code: | 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 |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Mon Oct 03, 2005 10:49 am Post subject: Re: PSP music (NOOB) |
|
|
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: | 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. |
|
| Back to top |
|
 |
chaos
Joined: 10 Apr 2005 Posts: 135
|
Posted: Mon Oct 03, 2005 12:02 pm Post subject: |
|
|
yeah, looks like you're probably retriggering it multiple times because the button is being held down. _________________ Chaosmachine Studios: High Quality Homebrew. |
|
| Back to top |
|
 |
Koba
Joined: 29 Sep 2005 Posts: 59
|
Posted: Mon Oct 03, 2005 3:29 pm Post subject: |
|
|
| 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 ;) |
|
| Back to top |
|
 |
darklitch
Joined: 03 Oct 2005 Posts: 11
|
Posted: Tue Oct 04, 2005 7:56 am Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Tue Oct 04, 2005 8:24 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
JoshDB

Joined: 05 Oct 2005 Posts: 87
|
Posted: Thu Oct 06, 2005 7:58 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
darklitch
Joined: 03 Oct 2005 Posts: 11
|
Posted: Thu Oct 06, 2005 9:34 am Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Thu Oct 06, 2005 10:28 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
darklitch
Joined: 03 Oct 2005 Posts: 11
|
Posted: Thu Oct 06, 2005 10:33 am Post subject: |
|
|
| that is exactly what i needed. Thanks shine |
|
| Back to top |
|
 |
|