Page 1 of 2
love.event.wait freezing game window
Posted: Tue Jan 01, 2019 12:06 pm
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.)
Re: love.event.wait freezing game window
Posted: Tue Jan 01, 2019 4:55 pm
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.
Re: love.event.wait freezing game window
Posted: Wed Jan 02, 2019 1:25 am
by Neox Hopper
Do I drag the "hump-master" folder into my game's folder (folder with main.lua)?
Re: love.event.wait freezing game window
Posted: Wed Jan 02, 2019 10:14 am
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.)
Re: love.event.wait freezing game window
Posted: Wed Jan 02, 2019 10:32 am
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').
Re: love.event.wait freezing game window
Posted: Thu Jan 03, 2019 5:40 am
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?
Re: love.event.wait freezing game window
Posted: Thu Jan 03, 2019 7:43 am
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.
Re: love.event.wait freezing game window
Posted: Thu Jan 03, 2019 2:41 pm
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
Re: love.event.wait freezing game window
Posted: Thu Jan 03, 2019 10:46 pm
by Neox Hopper
Is it possible to do the same thing but with images?
Re: love.event.wait freezing game window
Posted: Thu Jan 03, 2019 11:31 pm
by zorg
Yes.