Page 1 of 1

Adding toggle buttons?

Posted: Wed May 29, 2013 4:09 pm
by Eamonn
In a game, you'd want it so you can press something like 'e' to toggle sound. How would you do this? Currently, I have it so there are 2 different buttons: One for enabling sound and one for disabling. Hopefully this makes sense. If it doesn't, feel free to ask and I'll be sure to elaborate!

Thanks! Any help is appreciated!

Re: Adding toggle buttons?

Posted: Wed May 29, 2013 4:15 pm
by MadByte

Code: Select all


local music = true

function love.keypressed( key )

  if key == "m" then
    music = not music -- actually changes the current state
  end

end

Re: Adding toggle buttons?

Posted: Wed May 29, 2013 5:23 pm
by Eamonn
MadByte wrote:

Code: Select all


local music = true

function love.keypressed( key )

  if key == "m" then
    music = not music -- actually changes the current state
  end

end
That didn't work :( It still played the music!

EDIT: Nevermind, it worked! I just have to slam the M key really hard