Kagee

Untitled

May 15th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. -- from http://computercraft.info/wiki/Redstone_(event)
  2.  
  3. -- Set up a list which contains the sides as keys, and the current redstone state of each side as a boolean value
  4. statelist = {
  5.   ["top"] = rs.getInput("top"),
  6.   ["front"] = rs.getInput("front"),
  7.   ["left"] = rs.getInput("left"),
  8.   ["right"] = rs.getInput("right"),
  9.   ["back"] = rs.getInput("back"),
  10.   ["bottom"] = rs.getInput("bottom"),
  11. }
  12.  
  13. -- Ready the terminal for printing to
  14. term.clear()
  15. term.setCursorPos(1,1)
  16.  
  17. while true do -- Start an endless loop
  18.   os.pullEvent("redstone") -- Yield the computer until some redstone changes
  19.   -- We don't care what the event returns, since the first variable will be "redstone" and the rest will be nil.
  20.  
  21.   -- Now we check each side to see if it's changed.
  22.   for side, state in pairs(statelist) do -- Run the lines of code in this loop for each key/value pair in statelist
  23.     if rs.getInput(side) ~= state then -- If the side we're checking doesn't match what it was last time we checked then
  24.       print(side.." is now "..tostring(rs.getInput(side))) -- Print the new state of the side.
  25.       statelist[side] = rs.getInput(side) -- Update the statelist with the new change
  26.     end
  27.   end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment