love.event freezing system

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
saiko-chriskun
Prole
Posts: 6
Joined: Wed Dec 01, 2010 8:13 pm

love.event freezing system

Post by saiko-chriskun »

Code: Select all

function love.draw()
  for event, key in love.event.poll() do
    if event == 'keypressed' then
      love.graphics.print(key, 0, 0)
    end
  end
end

function love.keypressed(key, unicode)
  love.event.push('keypressed', key)
end
The above causes love to freeze once a key is hit. any help?
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: love.event freezing system

Post by Jasoco »

You're not supposed to call event yourself. That's done for you in love.run() which is a function you can't see, but it's there, and it makes sure everything works.

Look into love.keyboard.isDown() instead.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: love.event freezing system

Post by bartbes »

Or just setting a variable.

Now, as to why it's freezing:
love.keypressed is executed in love.run's event loop, whenever the 'keypressed' event has been sent, your love.keypressed sends a new 'keypressed', so it keeps on handling these new events and therefore it creates in infinite loop.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 5 guests