Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. --- Command Buffer Class ---
  2.  
  3. CommandBuffer = {commands = {}}
  4.  
  5. --- New Command Buffer ---
  6.  
  7. function CommandBuffer:new ()
  8. cmd_bfr = {}
  9. setmetatable(cmd_bfr, self)
  10. self.__index = self
  11. self.commands = {}
  12. self.running_command = false
  13. return cmd_bfr
  14. end
  15.  
  16. --- Command Buffer Functions ---
  17.  
  18. function CommandBuffer:RunNextCommand(func)
  19. if self.running_command return false
  20. self.running_command = true
  21.  
  22. if not self.commands[0].func() return false
  23.  
  24. table.remove(self.commands, 0)
  25.  
  26. self.running_command = false
  27. end
  28.  
  29. function CommandBuffer:AddCommand(func)
  30. table.insert(self.commands, Command:new(func))
  31. end
  32.  
  33. --- Command Class ---
  34.  
  35. Command = {func = nil}
  36.  
  37. --- New Command ---
  38.  
  39. function Command:new (exe)
  40. cmd = {}
  41. setmetatable(cmd, self)
  42. self.__index = self
  43. self.func = exe
  44. return cmd
  45. end
  46.  
  47. --- Command Functions ---
  48.  
  49. --- Mining Drone ---
  50.  
  51. MiningDrone = {
  52. command_buffer = nil,
  53. }
  54.  
  55. --- New Mining Drone ---
  56.  
  57. function MiningDrone:new ()
  58. mngdrn = {}
  59. setmetatable(mngdrn, self)
  60. self.__index = self
  61. self.command_buffer = CommandBuffer:new
  62. return mngdrn
  63. end
  64.  
  65. --- Test ---
  66.  
  67. function MiningDrone:test ()
  68. self.command_buffer.AddCommand(turtle.dig())
  69. self.command_buffer.RunNextCommand()
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement