Created
January 4, 2016 22:08
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local component = require("component") | |
local rs = component.redstone | |
local event = require("event") | |
local ev_print | |
local close_log | |
local logfile = io.open("log.txt", "w") | |
if not logfile then error("no logfile") end | |
local function log_print(s) | |
-- print("log") | |
logfile:write(s) | |
print(s) | |
end | |
ev_print = function(...) | |
local arg = {...} | |
local s = "EV:" .. arg[1] | |
table.remove(arg, 1) | |
s = s .." " | |
for k, v in pairs(arg) do | |
s = s .. v .. "," | |
end | |
log_print(s) | |
end | |
local function ev_rs_repeat(side) | |
log_print("Actual Rs on side later " .. side .. " => " .. rs.getInput(side)) | |
end | |
local function ev_rs(ev, addr, side) | |
log_print("Actual Rs on side " .. side .. " => " .. rs.getInput(side)) | |
event.timer(2, function() ev_rs_repeat(side) end) | |
end | |
local tog = false | |
local function ev_char(ev, addr, char, code, pName) | |
-- print("test"..char.. " == "..string.byte("x")) | |
if char == string.byte("x") then | |
tog = not tog | |
-- print("PP") | |
log_print("Toggle! Now: " .. tostring(tog)) | |
-- print("pc") | |
rs.setOutput(5, (tog and 15 or 0)) | |
elseif char == string.byte("c") then | |
-- print("c down!") | |
close_log() | |
end | |
end | |
close_log = function() | |
-- print("ohithere") | |
logfile:close() | |
-- print("stillhere") | |
local r = event.ignore("redstone_changed", ev_print) | |
print("Ignore: " .. tostring(r)) | |
event.ignore("key_up", ev_char) | |
event.ignore("redstone_changed", ev_rs) | |
print("Closed") | |
end | |
function end_log() close_log() end | |
local r = event.listen("key_up", ev_char) | |
print("Listen Control: " .. tostring(r)) | |
local r = event.listen("redstone_changed", ev_print) | |
print("Listen: " .. tostring(r)) | |
local r = event.listen("redstone_changed", ev_rs) | |
print("Listen: " .. tostring(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment