Adding toggle buttons?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Adding toggle buttons?

Post 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!
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Adding toggle buttons?

Post 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
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Adding toggle buttons?

Post 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
"In those quiet moments, you come into my mind" - Liam Reilly
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests