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.)
love.event.wait freezing game window
-
- Prole
- Posts: 8
- Joined: Mon Dec 31, 2018 8:20 am
Re: love.event.wait freezing game window
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.
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.
-
- Prole
- Posts: 8
- Joined: Mon Dec 31, 2018 8:20 am
Re: love.event.wait freezing game window
Do I drag the "hump-master" folder into my game's folder (folder with main.lua)?
-
- Prole
- Posts: 4
- Joined: Wed Jan 02, 2019 10:03 am
Re: love.event.wait freezing game window
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
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').
Then you require it with e.g. local timer = require("hump.timer") (if you stored it in a folder called 'hump').
-
- Prole
- Posts: 4
- Joined: Wed Jan 02, 2019 10:03 am
Re: love.event.wait freezing game window
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?
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?
-
- Party member
- Posts: 107
- Joined: Wed Oct 15, 2014 5:00 pm
- Location: Yorkshire, England
Re: love.event.wait freezing game window
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
Re: love.event.wait freezing game window
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
-
- Prole
- Posts: 8
- Joined: Mon Dec 31, 2018 8:20 am
Re: love.event.wait freezing game window
Is it possible to do the same thing but with images?
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: love.event.wait freezing game window
Yes.
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.
Who is online
Users browsing this forum: No registered users and 4 guests