Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- for i,j in pairs(tbl) do
- if msg:find(i) then
- if type(j) == "table" then
- if j[1] and type(j[1]) ~= "table" then
- return j
- end
- return getFunction(j, msg)
- end
- end
- end
- end
- local function parseMessage(msg)
- return pcall(table.unpack(getFunction(messages, msg)))
- 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