Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Command Buffer Class ---
- CommandBuffer = {commands = {}}
- --- New Command Buffer ---
- function CommandBuffer:new ()
- cmd_bfr = {}
- setmetatable(cmd_bfr, self)
- self.__index = self
- self.commands = {}
- self.running_command = false
- return cmd_bfr
- end
- --- Command Buffer Functions ---
- function CommandBuffer:RunNextCommand(func)
- if self.running_command return false
- self.running_command = true
- if not self.commands[0].func() return false
- table.remove(self.commands, 0)
- self.running_command = false
- end
- function CommandBuffer:AddCommand(func)
- table.insert(self.commands, Command:new(func))
- end
- --- Command Class ---
- Command = {func = nil}
- --- New Command ---
- function Command:new (exe)
- cmd = {}
- setmetatable(cmd, self)
- self.__index = self
- self.func = exe
- return cmd
- end
- --- Command Functions ---
- --- Mining Drone ---
- MiningDrone = {
- command_buffer = nil,
- }
- --- New Mining Drone ---
- function MiningDrone:new ()
- mngdrn = {}
- setmetatable(mngdrn, self)
- self.__index = self
- self.command_buffer = CommandBuffer:new
- return mngdrn
- end
- --- Test ---
- function MiningDrone:test ()
- self.command_buffer.AddCommand(turtle.dig())
- self.command_buffer.RunNextCommand()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement