Page 1 of 1
Wait() Function?
Posted: Wed Nov 30, 2022 1:47 am
by xcrvaz
Hey! I'm brand new to love. I've read a few forums and I know I should give a .love file, but I don't know how to actually get the .love file yet. I'm using an atom text editor plugin to run my code.
Is there a wait function? Outside of love.timer.sleep(), because that wasn't working.
I'm not new to lua, but I'm not great with this type of lua, I'm used to luau.
I wan't to start making games with love2d so.
What I want to do is just make the background flash rainbow,
When I did
red = {255/255, 0/255, 0/255}
orange = {255/255, 102/255, 0/255}
love.graphics.setBackgroundColor(red)
love.timer.sleep(3)
love.graphics.setBackgroundColor(orange)
It just went black with a big white square in the center.
Any better wait function?
Re: Wait() Function?
Posted: Wed Nov 30, 2022 2:32 am
by BrotSagtMist
Firstoff .love files are just zips with a fancy name (main.lua in toplevel)
Second, luau? That was the roblox thing if i remeber correctly? Yea forget everything you know then, this is not lua, not even the slightest.
Sleep puts your program to sleep, it will do absolutely nothing for the time given, this is probably not what you want.
If you want to wait a specific time you will have to create it yourself meaning you have a value that contains the time and you increase it every frame by the time given in love.update : T=T+dt
Next you will check if T is greater than the specified time (due to frame time this wait method cannot be exact) and then trigger your event and eventually reset T.
And yea this is no function but a simple if case. A generic easy wait function is not really handy to have.
Re: Wait() Function?
Posted: Wed Nov 30, 2022 2:44 am
by xcrvaz
BrotSagtMist wrote: ↑Wed Nov 30, 2022 2:32 am
Firstoff .love files are just zips with a fancy name (main.lua in toplevel)
Second, luau? That was the roblox thing if i remeber correctly? Yea forget everything you know then, this is not lua, not even the slightest.
Sleep puts your program to sleep, it will do absolutely nothing for the time given, this is probably not what you want.
If you want to wait a specific time you will have to create it yourself meaning you have a value that contains the time and you increase it every frame by the time given in love.update : T=T+dt
Next you will check if T is greater than the specified time (due to frame time this wait method cannot be exact) and then trigger your event and eventually reset T.
And yea this is no function but a simple if case. A generic easy wait function is not really handy to have.
Yeah I know its not lua, I've played around a little bit with it and I can tell its pretty different. Thanks for the help too!
Re: Wait() Function?
Posted: Wed Nov 30, 2022 10:05 am
by pgimeno
If you want to use Löve with the conventional non-event-oriented program flow, check this tool:
viewtopic.php?f=5&t=87262&p=229610#p229610
But you're advised to learn the Löve way of doing things. Löve is constantly in a loop that reads inputs (calling your input events when an input happens, if you've defined them), then calls your love.update if you have defined it, then clears the screen and calls your love.draw if you have defined it, and then shows everything you've drawn in love.draw and starts again.
So, this program will show you a number that increases every frame:
Code: Select all
local frame = 0
function love.update(dt)
frame = frame + 1
end
function love.draw()
love.graphics.print(tostring(frame))
end