Page 1 of 1

Help with making a wait() function

Posted: Wed Sep 09, 2020 5:02 am
by TypicalHB
Hello, I'm having issues with this wait() function that I made. It just seems to crash love when I call it. No error. it just opens, and then crashes.

Code: Select all

function wait(seconds)
  local start = os.time()
  repeat until os.time() > start + seconds
end

Re: Help with making a wait() function

Posted: Wed Sep 09, 2020 5:36 am
by grump
That code shouldn't crash. If it crashes then something is wrong with your system. It may result in a "Application is not responding" message from your OS if the value for seconds is sufficiently large, but it shoudn't crash.

Love already has a function for that, btw: love.timer.sleep.

Re: Help with making a wait() function

Posted: Wed Sep 09, 2020 7:01 am
by zorg
Besides, unless you literally want to suspend all processing, you shouldn't use that either; implement a timer or use a library instead like https://hump.readthedocs.io/en/latest/timer.html