forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PSP music (NOOB)

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
darklitch



Joined: 03 Oct 2005
Posts: 11

PostPosted: Mon Oct 03, 2005 10:01 am    Post subject: PSP music (NOOB) Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Koba



Joined: 29 Sep 2005
Posts: 59

PostPosted: Mon Oct 03, 2005 10:12 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Mon Oct 03, 2005 10:49 am    Post subject: Re: PSP music (NOOB) Reply with quote

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
View user's profile Send private message
chaos



Joined: 10 Apr 2005
Posts: 135

PostPosted: Mon Oct 03, 2005 12:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
Koba



Joined: 29 Sep 2005
Posts: 59

PostPosted: Mon Oct 03, 2005 3:29 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
darklitch



Joined: 03 Oct 2005
Posts: 11

PostPosted: Tue Oct 04, 2005 7:56 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Oct 04, 2005 8:24 am    Post subject: Reply with quote

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
View user's profile Send private message
JoshDB



Joined: 05 Oct 2005
Posts: 87

PostPosted: Thu Oct 06, 2005 7:58 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
darklitch



Joined: 03 Oct 2005
Posts: 11

PostPosted: Thu Oct 06, 2005 9:34 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Thu Oct 06, 2005 10:28 am    Post subject: Reply with quote

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
View user's profile Send private message
darklitch



Joined: 03 Oct 2005
Posts: 11

PostPosted: Thu Oct 06, 2005 10:33 am    Post subject: Reply with quote

that is exactly what i needed. Thanks shine
Back to top
View user's profile Send private message Visit poster's website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group