Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --MM Idea
- local rInterface = peripheral.find("redstoneIntegrator")
- local chatBox = peripheral.find("chatBox")
- if not rInterface then error("redstoneIntegrator not found! [Advanced Peripherals]") end
- if not chatBox then error("chatBox not found! [Advanced Peripherals]") end
- newGame = false
- user = "toastonrye"
- secretCode = nil
- checkedGuess = {}
- count = 1
- local function parseGuess(message)
- local msgArray = {}
- for w in string.gmatch(message, "%S+") do
- table.insert(msgArray, w)
- end
- return msgArray
- end
- local function checkGuess(guess, answer)
- print("GUESS")
- printLoop(guess)
- checkedGuess[count] = {}
- for i, code in pairs(guess) do
- if tonumber(code) == answer[i] then
- table.insert(checkedGuess[count], i, 2)
- else
- table.insert(checkedGuess[count], i, 0)
- end
- end
- print("STATS")
- printLoop(checkedGuess[count])
- end
- local function chatListener()
- while true do
- local event = {os.pullEvent("chat")} -- 1.event 2.player 3.message 4/5?
- local command = parseGuess(event[3])
- --printLoop(command)
- if command[1] == "gon" then
- print("New Game")
- newGame = true
- elseif command[1] == "goff" then
- print("Game Quit")
- newGame = false
- elseif command[1] == "g" then
- table.remove(command, 1)
- checkGuess(command, secretCode)
- count = count + 1
- end
- end
- end
- local function getCode()
- local r = {}
- for i=1,4 do
- table.insert(r, math.random(1,16))
- end
- return r
- end
- function printLoop(table)
- for k, v in pairs(table) do
- print(k, v)
- chatBox.sendMessageToPlayer(k .. ":" .. v, user)
- sleep(3)
- end
- end
- local function myMain()
- while true do
- if newGame then
- chatBox.sendMessageToPlayer("NEW GAME", user)
- secretCode = getCode()
- print("CODE")
- printLoop(secretCode)
- newGame = false
- end
- sleep()
- end
- end
- parallel.waitForAny(chatListener, myMain)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement