Advertisement
Guest User

Spawn

a guest
May 24th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. 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
  2.  
  3. 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.
  4.  
  5. This installment will cover the spawn function: what it is, and how to use it.
  6.  
  7.  
  8. [NOTE] - Before you read this you should read the article on functions: http://www.roblox.com/Forum/ShowPost.aspx?PostID=162455804
  9.  
  10.  
  11. 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.
  12.  
  13. while true do
  14. print(1+1)
  15. wait()
  16. end
  17. print(2+2)
  18.  
  19.  
  20. This code will only print 1+1 all the time and will never print 2+2, right? Not unless you use the spawn function.
  21.  
  22. Here is how you would do that
  23.  
  24. function PrintOnePlusOne()
  25. while true do
  26. print(1+1)
  27. wait(1)
  28. end
  29. end
  30.  
  31. spawn(PrintOnePlusOne)
  32. print(2+2)
  33.  
  34. 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
  35.  
  36. spawn(function()
  37. while true do
  38. print(1+1)
  39. wait(1)
  40. end
  41. end)
  42. print(2+2)
  43. 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.
  44.  
  45. 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.
  46.  
  47. function returntime(delay, placetime)
  48. print("The delay was " .. delay)
  49. print("The place time is " .. placetime)
  50. end
  51.  
  52. spawn(returntime)
  53.  
  54. 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)
  55.  
  56. [EXERSIZE] - Make a script that continues printing "hi" but prints "bye 5 times" and use a numerical for loop to print "bye" 5 times
  57.  
  58. Thanks for reading.
  59.  
  60. 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.
  61.  
  62. Scripters Forum Breakfast Club - Serving the best scripts in the global environment.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement