[SOLVED cause im stupid] I don't even know what to title this, sorry.

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
Charlie Gallie
Prole
Posts: 14
Joined: Sun Mar 18, 2018 2:53 pm

[SOLVED cause im stupid] I don't even know what to title this, sorry.

Post by Charlie Gallie »

I have an extremely strange issue which I haven't been able to solve for about two weeks now.
I have 6 .lua files, each a different screen for parts of my game.
When I get moved to deathScreen.lua (which is normal) and press any key, my music goes silent (not normal). I do have other files and I'll give the code to each love.keypressed(key) function which exists.

game.lua:

Code: Select all

function love.keypressed(key)
    if key == 'space' then
        if (not lost) and escKey == 0 then
            if not grow then
                grow = true
            else
                grow = false
            end
        end
    end

    if key == 'escape' and escKey == 0 then
        escKey = 1
        music:pause()
        bgm:play()
        love.mouse.setVisible(true)
        --PAUSE THE GAME
    else
        escKey = 0
        music:resume()
        love.audio.stop(bgm)
        love.mouse.setVisible(false)
        --CONTINUE THE GAME
    end

    if key == 'h' then
        if love.mouse.isVisible() == true then
            love.mouse.setVisible(false)
        else
            love.mouse.setVisible(true)
        end
    end

    if key == 'm' then
        if music:getVolume() > 0 then
            music:setVolume(0)
        else
            music:setVolume(v)
        end
    end
end
home.lua:

Code: Select all

function love.keypressed(key)
	if key == 'm' then
        if bgm:getVolume() > 0 then
            bgm:setVolume(0)
        else
            bgm:setVolume(0.3)
        end
    end
end
The the music which stops playing is bgm not music.
I also had an issue where my mouse would also become invisible whenever I press a key, but I solved that by just seeing if it was invisible, if so, make it visible. Not clean code I know, but it gets the job done.

I feel like if I just make the love.keypressed(key) function private/local (I don't know how to) it might fix my issue.

I'm sorry for being so vague, I just don't know what to actually put as I don't understand this problem in the slightest bit.
I would give the files but I don't think there's any need and I don't expect anyone to waste their time going through hundreds of lines of code just for me.

Thanks! :awesome:

P.S. English isn't my first language so sorry if this makes no sense.
Last edited by Charlie Gallie on Thu Feb 21, 2019 10:05 pm, edited 1 time in total.
User avatar
keharriso
Citizen
Posts: 98
Joined: Fri Nov 16, 2012 9:34 pm

Re: I don't even know what to title this, sorry.

Post by keharriso »

Charlie Gallie wrote: Thu Feb 21, 2019 9:28 pm

Code: Select all

    if key == 'escape' and escKey == 0 then
        escKey = 1
        music:pause()
        bgm:play()
        love.mouse.setVisible(true)
        --PAUSE THE GAME
    else
        escKey = 0
        music:resume()
        love.audio.stop(bgm)
        love.mouse.setVisible(false)
        --CONTINUE THE GAME
    end
I think you might mean:

Code: Select all

    if key == 'escape' then
        if escKey == 0 then
            escKey = 1
            music:pause()
            bgm:play()
            love.mouse.setVisible(true)
            --PAUSE THE GAME
        else
            escKey = 0
            music:resume()
            love.audio.stop(bgm)
            love.mouse.setVisible(false)
            --CONTINUE THE GAME
        end
    end
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
User avatar
Charlie Gallie
Prole
Posts: 14
Joined: Sun Mar 18, 2018 2:53 pm

Re: I don't even know what to title this, sorry.

Post by Charlie Gallie »

keharriso wrote: Thu Feb 21, 2019 9:43 pm
I think you might mean:

Code: Select all

    if key == 'escape' then
        if escKey == 0 then
            escKey = 1
            music:pause()
            bgm:play()
            love.mouse.setVisible(true)
            --PAUSE THE GAME
        else
            escKey = 0
            music:resume()
            love.audio.stop(bgm)
            love.mouse.setVisible(false)
            --CONTINUE THE GAME
        end
    end
Thank you very much sir! Wow, what takes me almost a week takes you only a few minutes!
I appreciate it. :nyu:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 208 guests