Simple question

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
Tuxion
Prole
Posts: 14
Joined: Mon Jan 08, 2018 6:31 pm

Simple question

Post 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?
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Simple question

Post 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.
Me and my stuff :3True 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

Post 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.
Tuxion
Prole
Posts: 14
Joined: Mon Jan 08, 2018 6:31 pm

Re: Simple question

Post by Tuxion »

Thanks Ostego160 ! it solves my problem.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests