Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local colors = require("colors")
- local sides = require("sides")
- local rs = component.redstone
- local messages = {
- ["lights"] = {
- --Syntax: ["keyword"] = {function, all, other, arguments}
- ["on"] = {rs.setBundledOutput, sides.back, colors.cyan, 15},
- ["off"] = {rs.setBundledOutput, sides.back, colors.cyan, 0}
- },
- ["door"] = {
- ["open"] = {rs.setBundledOutput, sides.back, colors.magenta, 15},
- ["close"] = {rs.setBundledOutput, sides.back, colors.magenta, 0}
- }
- }
- local function getFunction(tbl, msg)
- if tbl[1] and type(tbl[1]) ~= "table" then
- return j
- end
- for i,j in pairs(tbl) do
- if type(i) == "string" then
- if msg:find(i) and type(j) == "table" then
- return getFunction(j, msg)
- end
- end
- end
- end
- local function parseMessage(msg)
- local fnc = getFunction(messages, msg)
- if not fnc then return false, "no command found" end
- return pcall(table.unpack(fnc))
- end
- local testmsg = "Please turn the lights on"
- local result, response = parseMessage(testmsg)
- print(result)
- print(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement