oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
|
| 21 Jan 2012 12:04 AM |
| Hm, nice challenge.. let me see what I can find in that nice little ROBLOX API.. hehe. |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 21 Jan 2012 12:05 AM |
"How could you reWrtie "wait" "
You don't. . . |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:06 AM |
@smurf279
Actually, it's possible. :) |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:07 AM |
In fact, I've already found the solution. I'll just see what others post.
Hint: you have to use an uncommon service. :) |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
| |
|
|
| 21 Jan 2012 12:08 AM |
Ok, here goes nothing: time = 0; tic=tick(); c = coroutine.create(function() print("Hello!") wait(5) print("Hi!") end) getfenv(c)["wait"]=function(t) time = t or 0 c.yield() end c.resume(); while coroutine.status(c)~="dead" do if(time>0) then time=time-tick(); if(time<=0)then c.resume() end end end
That *should* work. I think. Handles resuming the coroutine from the main thread, so it shouldn't hang itself.
|
|
|
| Report Abuse |
|
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
|
| 21 Jan 2012 12:11 AM |
DOH'. time = time - (tic-tick()); |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
|
| 21 Jan 2012 12:12 AM |
@RenderSettings
Nope, that doesn't work the same way as the wait function.
I'll wait a few more, and then I'll post my asnwer, if nobody answers correctly, hehe. |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:13 AM |
| Why is this in SH and not in scripters? |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:13 AM |
function sleep(s) local start = tick(); repeat until tick() >= start + s return tick() - start end
That's what I came up with, but that's about the definition of inefficiency >.<
"I WILL GIVE YOU BACON." - Deadmau5 ~Scarfacial |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:13 AM |
| Because oxcool thinks there are people here that can answer it correctly, and he's actually right. |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
|
| 21 Jan 2012 12:13 AM |
Oxcool:I set wait to my custom one via setfenv. I did not use the default one. Julien:He said to re-write it, I did. There doesn't have to be just one correct answer. |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:15 AM |
@SCARFACIAL
Nope. Doesn't work the same way as wait.
Hehe, my solution does, though. :) |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:15 AM |
Oxcool:You sure you can't do enviorment changes on coroutines? Ok then: f = function() print("Hi!") wait(5) print("Bye!") end wait2 = function(t) --insert wait stuff here-- end setfenv(f)["wait"]=wait2; c = coroutine.create(f); |
|
|
| Report Abuse |
|
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 21 Jan 2012 12:16 AM |
kinda wanna figure this out now :U Give me a minute |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:18 AM |
Hm. Ok then: function wait(t) local tic = tick(); local f = t or 0; repeat f=t-tick()-tic tic=tick() until f<=0 end |
|
|
| Report Abuse |
|
|
|
| 21 Jan 2012 12:19 AM |
*f=tick()-tic Don't know why I had a random t- there. |
|
|
| Report Abuse |
|
|