Jump to content

A small Problem (sounds)


Blinker.

Recommended Posts

hello guys , i need a little help here with start / stop sound. well , i tried two methodes stopSound and setSoundVolume

and both didn't work.

here's my lua (client-side)

  
function onGuiClick (button, state, absoluteX, absoluteY) 
  if (source == startbutton)  then 
    
   local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) 
   if musicName == "Music 3" then 
     local sound = playSound("music.mp3") 
     setSoundVolume(sound,1) 
    
    else if (source == stopbutton) then 
    stopSound("music.mp3") 
--setSoundVolume(sound,0) 
    end 
    end 
    end 
    end 
  

the music starts when i click on the start button, but it doesn't stop when i click on the stop button.

thanks in advance.

Link to comment

well , I tried that

function onGuiClick (button, state, absoluteX, absoluteY) 
  if (source == startbutton)  then 
    
   local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) 
   if musicName == "Music 3" then 
      sound = playSound("music.mp3") 
     setSoundVolume(sound,1) 
    else if (source == stopbutton) then 
    stopSound(sound) 
    end 
    end 
    end 
    end 

Still Can't Make the music Stop.

Link to comment
function exampleCode() 
    if(true == false and false ~= true) then 
        sound = playSound("File.mp3") 
    end 
end 
  
function onGuiClick (button, state, absoluteX, absoluteY) 
  if (source == startbutton)  then 
    
   local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) 
   if musicName == "Music 3" then 
     setSoundVolume(sound,1) 
    else if (source == stopbutton) then 
    stopSound(sound) 
    end 
    end 
    end 
    end 

Should be like that ? I didn't understand it well :|

Link to comment

Hi there, Dealman referred you to me, I am his mentor, and I spotted your problem right away!

Your problem lies in the fact your source can never be stopbutton because it's within the if statement whereby to get to that state it must be start button. In short/english: you need to put the "stopsound" else/if one level down by putting and end just before it.

Hope this helps.

Link to comment
Hi there, Dealman referred you to me, I am his mentor, and I spotted your problem right away!

Your problem lies in the fact your source can never be stopbutton because it's within the if statement whereby to get to that state it must be start button. In short/english: you need to put the "stopsound" else/if one level down by putting and end just before it.

Hope this helps.

tumblr_lk8ey31GtH1qfidlu.gif

Link to comment

it should be like that?

function exampleCode() 
    if(true == false and false ~= true) then 
        sound = playSound("File.mp3") 
    end 
end 
  
function onGuiClick (button, state, absoluteX, absoluteY) 
  if (source == startbutton)  then 
    
   local musicName = guiGridListGetItemText ( gridlist, guiGridListGetSelectedItem ( gridlist ), 1 ) 
   if musicName == "Music 3" then 
     setSoundVolume(sound,1) 
     end 
     end 
   if (source == stopbutton) then 
    stopSound(sound) 
    end 
    end 

Link to comment

Make sure the line

local sound = nil 

is present at or near the top of the code, before any conditions, and also remove the function you got from Dealman, instead add

sound = playSound("File.mp3") 

inside the first if statement somewhere, and don't forget to change the filename to your mp3.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...