Page 1 of 1

Simple question

Posted: Mon Jan 08, 2018 7:14 pm
by Tuxion
I want to know, when a button is pressed, how to keep the function active after the button has been used. with what function do I do this?

Re: Simple question

Posted: Mon Jan 08, 2018 9:21 pm
by zorg
Hi and welcome to the forums;

Your simple question is truly simple, yet oh so vague; let me ask you a few follow-up questions:
- Do you mean mouse button, or a graphical button object you might have coded or want to code?
- What function do you exactly want to keep alive? And how do you define "keep alive"?
- What do you mean by "after the button has been used? As in the mouse-button released? Or a graphical one clicked on?
- Do you perhaps want a function to be called/executed/ran every frame after one of the aforementioned things, or would you like to do something else?

You know, help us help you, so we can give you a correct answer.

Re: Simple question

Posted: Mon Jan 08, 2018 9:36 pm
by Ostego160
You tie the input command to a boolean variable.

Code: Select all

function love.load()
  switchOn = false
end

function love.update(dt)
  if love.keyboard.isDown('space') then
    switchOn = true
  end
  
  if switchOn then
    doSomething()
  end
end
When the spacebar is pressed, switchOn becomes true and stays true even if released.

Re: Simple question

Posted: Tue Jan 09, 2018 10:45 am
by Tuxion
Thanks Ostego160 ! it solves my problem.