love.event.wait freezing game window

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Neox Hopper
Prole
Posts: 8
Joined: Mon Dec 31, 2018 8:20 am

love.event.wait freezing game window

Post by Neox Hopper »

I'm trying to make a walking animation using this script:

function love.update(dt)
if love.keyboard.isDown("d") then
x = x + (speed * dt)
love.event.wait(1)
potato = right
end

However, when I enter the "love.event.wait(1)" code, it freezes the game window for 1 second. Is there a way to "wait," and not freeze the game?

(Sorry for posting so many threads, I'm very new to Lua scripting and most (informative) forum posts are usually out-dated or don't work.)
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: love.event.wait freezing game window

Post by pgimeno »

This looks like a job for a timer library. Take a look at hump.timer.
https://github.com/vrld/hump (library)
https://hump.readthedocs.io/en/latest/timer.html (timer docs)

It's OK to post new threads, but this looks more appropriate for the Support forum rather than General.
Neox Hopper
Prole
Posts: 8
Joined: Mon Dec 31, 2018 8:20 am

Re: love.event.wait freezing game window

Post by Neox Hopper »

Do I drag the "hump-master" folder into my game's folder (folder with main.lua)?
BobTheBuilder
Prole
Posts: 4
Joined: Wed Jan 02, 2019 10:03 am

Re: love.event.wait freezing game window

Post by BobTheBuilder »

How do you properly install and use the timer library? (which folder do you drag it to, which .lua file do you drag it to, ect.)
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: love.event.wait freezing game window

Post by pgimeno »

You only need timer.lua anywhere within that folder. You can create a folder called 'hump', or you can create a folder called 'libs' or however you prefer to organize it.

Then you require it with e.g. local timer = require("hump.timer") (if you stored it in a folder called 'hump').
BobTheBuilder
Prole
Posts: 4
Joined: Wed Jan 02, 2019 10:03 am

Re: love.event.wait freezing game window

Post by BobTheBuilder »

I put the "hump" folder (with the timer.lua file in it) in my games folder and entered this script into main.lua:

local Timer = require("hump.timer")
function love.keypressed(key)
if key == 'a' then
Timer.after(1, function() print("Hello, world!") end)
end
end

function love.update(dt)
Timer.update(dt)
end

-but no "Hello world!" text was showing up in the game window when I press the "a" key. Do you know how to fix this issue?
pedrosgali
Party member
Posts: 107
Joined: Wed Oct 15, 2014 5:00 pm
Location: Yorkshire, England

Re: love.event.wait freezing game window

Post by pedrosgali »

Is the text being printed to the console? Your function added to the timer is calling print which adds text to the console.

Code: Select all

if not wearTheseGlasses() then
  chewing_on_trashcan = true
end
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: love.event.wait freezing game window

Post by pgimeno »

Yeah, note also that LÖVE erases the screen every frame, therefore even changing print() to love.graphics.print() will not work at all. What you can do is set a variable in the timer, and print it in love.draw, like this:

Code: Select all

local Timer = require("hump.timer")

local TextToPrint = ""  -- Print an empty string until TextToPrint is changed

function love.keypressed(key)
  if key == 'a' then
    Timer.after(1, function() TextToPrint = "Hello, world!" end)
  end
end

function love.update(dt)
  Timer.update(dt)
end

function love.draw()
  love.graphics.print(TextToPrint)
end
Neox Hopper
Prole
Posts: 8
Joined: Mon Dec 31, 2018 8:20 am

Re: love.event.wait freezing game window

Post by Neox Hopper »

Is it possible to do the same thing but with images?
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love.event.wait freezing game window

Post by zorg »

Yes.
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.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests