## Simple question

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Tuxion
Prole
Posts: 14
Joined: Mon Jan 08, 2018 6:31 pm

### Simple question

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?

zorg
Party member
Posts: 2653
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: Simple question

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?

Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Ostego160
Prole
Posts: 14
Joined: Tue Oct 17, 2017 7:18 pm

### Re: Simple question

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.

Tuxion
Prole
Posts: 14
Joined: Mon Jan 08, 2018 6:31 pm

### Re: Simple question

Thanks Ostego160 ! it solves my problem.

### Who is online

Users browsing this forum: No registered users and 8 guests