generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: recreating the wait() function in normal lua?

Previous Thread :: Next Thread 
justasimpletest is not online. justasimpletest
Joined: 07 Feb 2011
Total Posts: 733
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 is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
25 Feb 2012 09:37 AM
[ Content Deleted ]
Report Abuse
justasimpletest is not online. justasimpletest
Joined: 07 Feb 2011
Total Posts: 733
25 Feb 2012 09:40 AM
Nopes.
Report Abuse
justasimpletest is not online. justasimpletest
Joined: 07 Feb 2011
Total Posts: 733
25 Feb 2012 10:46 AM
bump
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
25 Feb 2012 10:50 AM
Coroutines make two things run at once.
Report Abuse
smurf279 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
25 Feb 2012 11:47 AM
It's for both.

~Flurite
Report Abuse
Flurite is not online. 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 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
25 Feb 2012 11:51 AM
Can you show a simple example?
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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 is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
25 Feb 2012 12:02 PM
The coroutine..

~Flurite
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
25 Feb 2012 12:04 PM
Ok....Nevermind.
Report Abuse
stravant is not online. stravant
Forum Moderator
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image