|
| 26 May 2012 06:18 PM |
Is there a similar function in Love2D to the wait() function here? Although I understand that you can use coroutines and a number of other methods to do this, I would've thought that they had something like that.
love.timer.sleep doesn't work since it actually 'puts the program to sleep'.
Is there any other methods?
I tried..
whatever = "" starttime = love.timer.getTime() repeat whatever = "a" until love.timer:getTime() - starttime == 1
However that crashed and I'm assuming other loops like that would fail just as badly.
So is there any other way? |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 06:28 PM |
| Why would you want to put the program to sleep? |
|
|
| Report Abuse |
|
|
| |
|
|
| 26 May 2012 06:52 PM |
| Wait; then what do you want to do? |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 06:54 PM |
There is no wait.
♪ Can you dig it? ♪ |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 06:56 PM |
>Wait; then what do you want to do?
Make something similar to the wait() function in RBX.Lua
>There is no wait.
I understand, which is why I'm trying to find a way to create one. Coroutines are the solution I've been able to think of, and in this case I don't think it'll work since I'm using love.mousepressed and the thread ends relatively fast. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 26 May 2012 08:03 PM |
Darkkiller, I want to ask.
How come you're not asking these questions to the LOVE2D forum? |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 08:08 PM |
I posted this in the Love2D forums already. The roblox 'Scripting Helpers' forum is quite a bit more active than the Love2D forum.
I post in both spots hoping to get a reply faster. |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 08:10 PM |
Must you use Love2D libraries to achieve this? I'm not familiar with Love2D, but if it includes the os.time library, then this will suffice:
function wait(seconds) local start = os.time() local end = start+seconds while end ~= os.time() do end end |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 08:11 PM |
Oops, I failed. Naming a variable "end" will confuse the interpreter.
function wait(seconds) local start = os.time() local _end = start+seconds while _end ~= os.time() do end end |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 09:50 PM |
| Thanks! Although is there a way to make it so that it doesn't generate so much lagg? |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 09:59 PM |
| Well, I'm running it in SciTE, so there's no lag. Again, I'm not familiar with Love2D, so their graphics engine is your problem. :P |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 10:04 PM |
@ElectricBlaze
Please look up "busy waiting" on Wikipedia. It'll benefit you a lot.
You do realize that's going to take 100% of the CPU by checking as much as it can, right?
It'd be much more efficient to just check every time the [ function of which I forgot the name ] is called. |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 10:33 PM |
Yeah, the loop would run every possible moment to check. If I were to do wait(10) with that function it'd pretty much crash the application.
@Julien; I think I may have an idea. Thanks. |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 11:48 PM |
love.timer.sleep(seconds)
That is for 0.8.0. Anything lower is the same, but the argument is milliseconds.
Of course, this makes the whole program sleep, so it's not entirely useful. |
|
|
| Report Abuse |
|
|
|
| 26 May 2012 11:49 PM |
Wow, just ignore my post. Apparently I fail at reading.
Currently there's no really good way to do this. It would be nice if they had a sleep method for threads. |
|
|
| Report Abuse |
|
|
|
| 27 May 2012 10:54 AM |
Well I was thinking about using coroutine.yield and some other messing around with coroutines, but along with math, coroutines are my weak spot.
I tried using love.update() to count up to 1 but unless I put the function inside the love.update function it wouldn't work right. And if it was inside the love.update function it wouldn't work at all.
So I guess I'm just giving up on this until love has a feature added that makes this possible. |
|
|
| Report Abuse |
|
|
|
| 27 May 2012 11:09 AM |
I found it! Someone made a library for this! Amazing!
Go onto their wiki.
After the /wiki in the url address, put in
cron.lua
This is a timed library with the functions we need! Praise this guy!
|
|
|
| Report Abuse |
|
|