You can, but I'm 99% sure that's not what you want at all. As far as I can tell, you're going about this the wrong way. This isn't how LOVE (and a bunch of other frameworks out there) work.RBXcpmoderator12345 wrote:can i have a function in a if statement in a function then?
like this:Code: Select all
function love.keypressed(key) if key == "q" then function love.draw() love.graphics.draw(image) end end end
Look at love.run. This is the function that's actually behind every LOVE game. You don't have to understand what it does exactly, but it should give somewhat of a gist of what's actually going on.
Basically, video games work in frames. Every frame, the game updates itself, including all of its variables and such then draws elements on screen, such as images, text, shapes, and so on, according to these variables.
To put it in perspective, let's say you want a character to move across the screen. Every update, the game will ask: "is the user holding down the right arrow key?" If so, the game will then say "let's change the player's X variable by a certain amount." If not, the game will say "alright, so they aren't holding down the key, so we'll just do nothing there." Of course, the same will be done for every other arrow key, and subsequently for jumping, shooting guns, and so on.
Now, for your example, when love.draw is called, it will draw the image on screen every frame.
Code: Select all
function love.draw()
love.graphics.draw(image)
end
Code: Select all
function love.load()
showImage = true
end
function love.draw()
if showImage then
love.graphics.draw(image)
end
end
Code: Select all
function love.load()
showImage = true
end
function love.keypressed(key)
if key == 'q' then
showImage = not showImage -- toggles the showImage variable
end
end
function love.draw()
if showImage then
love.graphics.draw(image)
end
end