Top posting users this month | |
Latest topics | » Where to go from here.September 14th 2020, 1:20 pm by MrNicNac» Send me an EmailSeptember 14th 2020, 1:16 pm by MrNicNac» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]July 6th 2015, 7:38 pm by m27frogy» New Site PossiblyJuly 6th 2015, 4:16 pm by m27frogy» Ambassador!April 15th 2015, 11:40 pm by naknak» Boop - TagApril 13th 2015, 9:46 pm by naknak» Vip Class ScriptApril 13th 2015, 4:54 pm by naknak» Who's active?!April 13th 2015, 4:52 pm by naknak» Genesis PointJuly 17th 2014, 7:04 pm by branefreez» Reward SystemJuly 17th 2014, 5:41 am by m27frogy» Script RequestJuly 10th 2014, 11:43 am by naknak» local scripts?July 10th 2014, 11:39 am by naknak» Project: Reconstruction [Died]July 10th 2014, 11:36 am by naknak» Hi. I am new hereApril 26th 2014, 4:01 pm by altshiftkey» What's your favorite sport?January 1st 2014, 2:13 pm by m27frogy» FlashLight ScriptJanuary 1st 2014, 2:11 pm by m27frogy» Gun Making! [READ DESC]January 1st 2014, 2:10 pm by m27frogy» Hi, I am new here!November 26th 2013, 3:33 pm by Keanu73» Improve CodingOctober 26th 2013, 1:12 pm by pook03» Simple ButtonSeptember 1st 2013, 6:19 pm by branefreez |
|
| Coroutines and you | |
| | Author | Message |
---|
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Coroutines and you August 1st 2010, 2:50 pm | |
| there are a few commands you need to know for coroutines: coroutine.create -- makes a coroutine coroutine.resume -- resumes a coroutine corouinte.yield -- yields a coroutine pretty obvious commands? My favorite way to use a coroutine is like this: - Code:
-
corutine.resume(coroutine.create(function() wait(1) print("I is a coroutine!") end)) while wait(1) do print("I is a loop!") Oddly enough, create went after resume. Why? because otherwise it wouldn't have activated. Use this script in studio to see how the two loops work side by side without issue. | |
| | | Guest Guest
| Subject: Re: Coroutines and you August 2nd 2010, 5:23 am | |
| The while true do loop has no end and therefore will error. |
| | | Bobbyfishstick5 Expert Scripter
Posts : 13 Join date : 2010-07-30 Age : 28
| Subject: Re: Coroutines and you August 2nd 2010, 8:39 am | |
| Well, You can end a loop with the break statement. | |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Coroutines and you August 2nd 2010, 9:06 pm | |
| I didn't want to put the ends... | |
| | | Guest Guest
| Subject: Re: Coroutines and you August 2nd 2010, 11:49 pm | |
| |
| | | slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: Re: Coroutines and you August 5th 2010, 3:37 pm | |
| - sckum555 wrote:
- What's a courotine?
it helps with debugging. | |
| | | Guest Guest
| Subject: Re: Coroutines and you August 5th 2010, 7:53 pm | |
| - slayer9365 wrote:
- sckum555 wrote:
- What's a courotine?
it helps with debugging. Eh, no. You can use log files, xpcall, test servers, et cetera, for debugging. Coroutines are not really one of them. Though, coroutine.yield is REALLY useful for making a wait function that doesn't cross a Lua/C boundry and error in a(n) (x)pcall |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Coroutines and you December 18th 2010, 9:41 am | |
| or print(loadstring("failz scriptz will error in loadstring. xD")()) | |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Coroutines and you January 17th 2011, 12:08 am | |
| I wish coroutines were a bit less annoying to use. thats about it. | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Coroutines and you January 17th 2011, 8:59 am | |
| I'm kinda new to corutines. Would this print 1, 2, 3, 4, 5, coroutine yielded? - Code:
-
x = 0 cor = coroutine.create(function() for i = 1, 100 do x = x + 1 print(x) wait(0.2) end end) coroutine.resume(cor) wait(1) coroutine.yield(cor) print("coroutine yielded")
| |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Coroutines and you January 17th 2011, 12:17 pm | |
| | |
| | | Guest Guest
| Subject: Re: Coroutines and you January 17th 2011, 4:46 pm | |
| aaah... I think that would depend on how strong you computer is? your limit is only time, not a specific point. |
| | | Guest Guest
| Subject: Re: Coroutines and you January 17th 2011, 4:48 pm | |
| - Quote :
-
- Quote :
- slayer9365 wrote:
sckum555 wrote: What's a courotine?
it helps with debugging.
Eh, no. You can use log files, xpcall, test servers, et cetera, for debugging. Coroutines are not really one of them. Though, coroutine.yield is REALLY useful for making a wait function that doesn't cross a Lua/C boundry and error in a(n) (x)pcall
uh VoidHack? do you even know what your talking about? |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Coroutines and you January 17th 2011, 5:13 pm | |
| Voidhack knows what he is talking about. Or at least, he used to if not anymore. | |
| | | Guest Guest
| Subject: Re: Coroutines and you January 17th 2011, 5:24 pm | |
| he used to? what matters to others is if this is real in the scripting worlds (this is scripting not programming because we're using an engine) |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Coroutines and you January 18th 2011, 6:16 am | |
| he knows what he is talking about. you can't put a wait() in pcall or xpcall but u can in coroutines. | |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Coroutines and you January 18th 2011, 6:10 pm | |
| This works in RBX.lua
I use them whenever I want a script that does a lot at once without all the lag. | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: Re: Coroutines and you January 19th 2011, 6:49 am | |
| | |
| | | Sponsored content
| Subject: Re: Coroutines and you | |
| |
| | | | Coroutines and you | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| Who is online? | In total there are 2 users online :: 0 Registered, 0 Hidden and 2 Guests
None
Most users ever online was 136 on October 21st 2024, 12:16 pm
|
| Please tell us what time zone you are in here
Got a really good idea? Post it in projects and it might show up here! |
|