|
| 01 Oct 2012 04:48 PM |
Since theres no inbuilt function to wait() or sleep(), i made this, and Im wondering if the math is correct:
function wait(t) local old = os.time() repeat until os.time() > old + t end
wait(4) print("hi") |
|
|
| Report Abuse |
|
|
Uuvinu
|
  |
| Joined: 19 Apr 2012 |
| Total Posts: 2206 |
|
|
| 01 Oct 2012 05:12 PM |
Does ROBLOX allow use of os.time?
Never knew that. |
|
|
| Report Abuse |
|
|
nairod7
|
  |
| Joined: 26 Mar 2010 |
| Total Posts: 869 |
|
|
| 01 Oct 2012 05:18 PM |
"luaforwindows" = Lua for windows. That's not RBX.Lua
Personally, I don't like the repeat until :/ This function would work but maybe there is another way to do this. |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2012 05:39 PM |
It waited until the time + 1. This is fixed, however, only works with integer values. How might I make it work with decimals?
function wait(t) local old = os.time() repeat until os.time() == old + t end |
|
|
| Report Abuse |
|
|
nairod7
|
  |
| Joined: 26 Mar 2010 |
| Total Posts: 869 |
|
|
| 01 Oct 2012 05:43 PM |
| If os.time() returns an integer, I think you'll have to use something else. But I can't help you, I don't know lua libraries out of roblox. |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2012 05:45 PM |
| Out of roblox? Its embedded in the standard lua. Oh well, back to the Lua 5.2 reference page :D |
|
|
| Report Abuse |
|
|
nairod7
|
  |
| Joined: 26 Mar 2010 |
| Total Posts: 869 |
|
|
| 01 Oct 2012 06:00 PM |
I mean I use lua only on roblox, We can't use io or even os so why would I learn this if I don't have to use them ? I script in lua in roblox only and in C++ in general ( still learning it ).
By the way, I found this, it may helps you: http://lua-users.org/wiki/SleepFunction |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2012 06:27 PM |
That will simply stall the thread for the right time.
In real-world applications (as in outside of Roblox) you shouldn't ever ever ever need to use wait. |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2012 06:37 PM |
| How do you explain weapon rate of fire then? :P |
|
|
| Report Abuse |
|
|
|
| 01 Oct 2012 06:53 PM |
In roblox? wait(), but this is roblox.
Outside of roblox, most games generally have a thread that is constantly running. Instead of using wait(), you use somewhat clever math and time to make things happen. |
|
|
| Report Abuse |
|
|