Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Main Program
- local console = require("console");
- local event = require("event");
- local thread = require("thread");
- local serialization = require("serialization");
- local network = require("network");
- local filesystem = require("filesystem");
- local computer = require("computer");
- local data = {};
- console.init();
- local testVariable = 0;
- local shouldRun = true;
- function close()
- console.kill();
- shouldBeRunning = false;
- shouldRun = false;
- os.exit();
- end
- function saveData()
- local file = io.open("data.dat", "w");
- file:write(serialization.serialize(data));
- file:close();
- end
- if filesystem.exists("/usr/CM_Automator/data.dat") then
- print("Loading Data...");
- local file = io.open("data.dat", "r");
- local fileIn = file:read("*a");
- file:close();
- data = serialization.unserialize(fileIn);
- if data["verify"] == nil then
- print("&eError loading file...closing.");
- close();
- else
- print("&5Data loaded successfully!")
- end
- else
- print("No data found. Assuming to be new.");
- data["verify"] = true;
- saveData();
- end
- console.print("Program Started.");
- function commandHandler()
- while shouldRun do
- e, cmd = event.pull("command");
- if cmd == "clear" then
- console.clearLog();
- elseif cmd == "close" then
- close();
- elseif cmd == "update" then
- os.execute("cmauto -i");
- elseif cmd == "test" then
- os.execute("/home/test.lua");
- elseif cmd == "help" then
- console.print("Haven't added this in yet :P you're on your own.", false)
- elseif cmd =="reset" then
- os.execute("rm data.dat");
- print("Resetting.");
- computer.shutdown(true);
- else
- console.print("&eCommand not found! Try \'help\' for more information", false);
- end
- end
- end
- table.insert(threadList, thread.create(commandHandler));
- if data["robotAddress"] == nil then
- print("No robot address found. Assuming new. Attempting to find robot.");
- local robotAddress = network.findRobot();
- if robotAddress ~= nil then
- print("&5Paired with robot! [&a" .. robotAddress .."&5]")
- data["robotAddress"] = robotAddress;
- saveData();
- network.init(robotAddress);
- else
- print("&eError adding robot.")
- end
- else
- network.init(data["robotAddress"]);
- end
- function updateConsoleTopBar()
- end
- while shouldRun do
- os.sleep(.1);
- end
Advertisement
Add Comment
Please, Sign In to add comment