Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is official documentation of the Scripters Forum Breakfast Club. Created on 5/25/2015. Official group: http://www.roblox.com/My/Groups.aspx?gid=2582784
- This is the 8th installment of SFBC’s, ‘As Fast as Possible’ series. Officially abbreviated ‘AFAP’, AFAP will be aiming to teach the basic – intermediate subjects as fast as possible. Every single AFAP will include an exercise which is an optional task for the reader to see if they understand it.
- This installment will cover the spawn function: what it is, and how to use it.
- [NOTE] - Before you read this you should read the article on functions: http://www.roblox.com/Forum/ShowPost.aspx?PostID=162455804
- The spawn function is something that is very useful if you want to have a loop run or a block of code run while another block of code is running. Here is an example of how the spawn functions works.
- while true do
- print(1+1)
- wait()
- end
- print(2+2)
- This code will only print 1+1 all the time and will never print 2+2, right? Not unless you use the spawn function.
- Here is how you would do that
- function PrintOnePlusOne()
- while true do
- print(1+1)
- wait(1)
- end
- end
- spawn(PrintOnePlusOne)
- print(2+2)
- What the code above will do is continue to print 1 + 1 but also print 2 + 2 once. You do not have to write it like this you could do something like this
- spawn(function()
- while true do
- print(1+1)
- wait(1)
- end
- end)
- print(2+2)
- That will have the same effect. You should also note that spawn does not need the s to be lowercase. The s can be uppercase but the roblox community prefers it lowercase. Using the spawn function is very useful for things like changing a parts position while giving each player a certain amount of points.
- The main use for the spawn function is having something that a loop is needed for and something a loop is not needed for happen at the same time. However, if you put it like this way it will return the elapsed time and the current place time.
- function returntime(delay, placetime)
- print("The delay was " .. delay)
- print("The place time is " .. placetime)
- end
- spawn(returntime)
- What this will do is print the amount of time it took for the function to run and the amount of time the place has been running(in miliseconds)
- [EXERSIZE] - Make a script that continues printing "hi" but prints "bye 5 times" and use a numerical for loop to print "bye" 5 times
- Thanks for reading.
- If you would like to support SFBC and want more of these kind of articles, then please join http://www.roblox.com/My/Groups.aspx?gid=2582784 to show your support. Thank you.
- Scripters Forum Breakfast Club - Serving the best scripts in the global environment.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement