|
| 25 Feb 2012 09:26 AM |
| I remember someone posting the recreated wait function about a year ago but I can't find it now... |
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
| |
|
| |
|
| |
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 25 Feb 2012 10:50 AM |
| Coroutines make two things run at once. |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 25 Feb 2012 10:59 AM |
| http://www.roblox.com/Forum/ShowPost.aspx?PostID=62687943 |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 25 Feb 2012 11:03 AM |
@Miz656,
Actually, coroutine.yield() is used for the RBX.lua wait() function.
~Flurite |
|
|
| Report Abuse |
|
|
FerraiF50
|
  |
| Joined: 02 Apr 2011 |
| Total Posts: 202 |
|
|
| 25 Feb 2012 11:06 AM |
| I think i remember what your talking about but i forget the name |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 25 Feb 2012 11:09 AM |
@Flurite
Really? Hmmm... Swimguy777 just told me you use coroutines to run two scripts at once. But I did not know that. I'ma look at up now :D |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
| |
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 25 Feb 2012 11:50 AM |
All scripts are pretty much like coroutines, by calling coroutine.yield() (AKA wait()) you pause the script.
~Flurite |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 25 Feb 2012 11:51 AM |
| Can you show a simple example? |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2012 11:51 AM |
@miz They can run two functions at once, catch errors, and yield one thread while another runs.
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 25 Feb 2012 11:54 AM |
| I wanna see an example of coroutine.yield :P |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2012 11:55 AM |
http://wiki.roblox.com/index.php/Function_Dump/Coroutine_Manipulation#coroutine.yield_.28.C2.B7.C2.B7.C2.B7.29
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 25 Feb 2012 11:58 AM |
co = coroutine.create(function() print(coroutine.yield()) end) coroutine.resume(co) coroutine.resume(co, 4, 5)
Where does it suspend it? |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
| |
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 25 Feb 2012 12:54 PM |
You need to make a thread scheduler. Here's a very simple one to demonstrate the idea (well, simple is relative, but the one in Roblox is considerably more complicated than this one):
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()
Note: If you ever need to find this in the future just search "threadlist", me posting this example on various threads will be the only result. |
|
|
| Report Abuse |
|
|