landie456
|
  |
| Joined: 17 Sep 2010 |
| Total Posts: 451 |
|
|
| 22 Jan 2012 08:25 PM |
| Well i feal really noob coming here for help but scripting help is filt with RBX.Lua n00bs so you people are more likely to know what im talking about. I require a pause function in normal lua a bit like the wait() in RBX.Lua but i have beed unable to find anything like that, so could you please point me to a libray or plugin that suports somthing like that? |
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 22 Jan 2012 08:27 PM |
function wait(time) local start = tick(); repeat wait(); until tick()-start >= time return tick()-start; end |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2012 08:28 PM |
@ENET
There is no such thing as tick() in normal Lua. |
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 22 Jan 2012 08:28 PM |
I meant....
function wait(time) local start = tick(); repeat until tick()-start >= time return tick()-start; end |
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 22 Jan 2012 08:29 PM |
| Well replace it with the unix time function. Not that hard.... Got it? K great :)> |
|
|
| Report Abuse |
|
|
landie456
|
  |
| Joined: 17 Sep 2010 |
| Total Posts: 451 |
|
|
| 22 Jan 2012 08:37 PM |
Well it gives me this name or '...' expected near '2' so im gessuing I did it wrong by doing thing function wait(2) local start = tick(); repeat until tick()-start >=2 return tick()-start; end (brackets that looked like this < where srounding name roblox thought it was HTML) |
|
|
| Report Abuse |
|
|
landie456
|
  |
| Joined: 17 Sep 2010 |
| Total Posts: 451 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Jan 2012 09:53 PM |
Use yield and coroutines to make a scheduler. This will work as expected:
local ThreadList = {}
function wait(t) t = t or -1 coroutine.yield(t) end
function Spawn(f) ThreadList[coroutine.create(f)] = -1 end
function Start() while true do local time = os.time() for thread, resumeAt in pairs(ThreadList) do if time >= resumeAt then local st, resumeIn = coroutine.resume(thread) if not st then --error occurred print("Error: "..tostring(resumeIn)) ThreadList[thread] = nil
elseif coroutine.status(thread) == 'dead' then --remove it ThreadList[thread] = nil
else --set when to resume ThreadList[thread] = time+(resumeIn or -1) end end end end end
Spawn(function() print("Hello, World...") for i = 1, 10 do wait(1) print("..."..i) end end)
Spawn(function() wait(5) print("In 5.") a.b = 7 end)
Start() |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2012 10:19 PM |
| Dang Stravant O_O I. might use that.. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 22 Jan 2012 10:26 PM |
@Stravent, he wanted one for Lua, not rbx.lua.
" I require a pause function in normal lua a bit like the wait() in RBX.Lua"
Don't think it's possible writing a wait function that *works* like roblox's would.
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 22 Jan 2012 10:38 PM |
Uhh, what? Yes, I understood the question, and mine works exactly as expected in normal Lua, did you even try it? |
|
|
| Report Abuse |
|
|
|
| 22 Jan 2012 11:19 PM |
"@Stravent, he wanted one for Lua, not rbx.lua." That's exactly what he wrote. Did you look at the code? |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 22 Jan 2012 11:53 PM |
| > Explaining why couritines and ROBLOX wait() never work for me. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 23 Jan 2012 12:30 AM |
Ah, "Spawn(function() print("Hello, World...") for i = 1, 10 do wait(1) print("..."..i) end end)"
Saw that and assumed it was rbx.lua, then read the first bit of your code. My bad.
<'+1 Post. Ujelly?'> |
|
|
| Report Abuse |
|
|