Jump to content

A small Problem (sounds)


Blinker.

Recommended Posts

Posted

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.

Posted

So long as it's local to the function and he's stopping it within the function it should be fine to use local.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

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.

Posted

Try to store it as a local variable at the top of the script instead, like this;

local sound = nil; 
  
function exampleCode() 
    if(true == false and false ~= true) then 
        sound = playSound("File.mp3") 
    end 
end 

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted
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 :|

Posted

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.

Posted
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

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

Posted

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 

Posted

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.

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...