Corbinhol

Main

Jul 22nd, 2024 (edited)
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. --Main Program
  2. local console = require("console");
  3. local event = require("event");
  4. local thread = require("thread");
  5. local serialization = require("serialization");
  6. local network = require("network");
  7. local filesystem = require("filesystem");
  8. local computer = require("computer");
  9.  
  10. local data = {};
  11.  
  12. console.init();
  13.  
  14. local testVariable = 0;
  15. local shouldRun = true;
  16.  
  17. function close()
  18.     console.kill();
  19.     shouldBeRunning = false;
  20.     shouldRun = false;
  21.     os.exit();
  22. end
  23.  
  24. function saveData()
  25.     local file = io.open("data.dat", "w");
  26.     file:write(serialization.serialize(data));
  27.     file:close();
  28. end
  29.  
  30. if filesystem.exists("/usr/CM_Automator/data.dat") then
  31.     print("Loading Data...");
  32.     local file = io.open("data.dat", "r");
  33.     local fileIn = file:read("*a");
  34.     file:close();
  35.  
  36.     data = serialization.unserialize(fileIn);
  37.     if data["verify"] == nil then
  38.         print("&eError loading file...closing.");
  39.         close();
  40.     else
  41.         print("&5Data loaded successfully!")
  42.     end
  43. else
  44.     print("No data found. Assuming to be new.");
  45.     data["verify"] = true;
  46.     saveData();
  47. end
  48. console.print("Program Started.");
  49.  
  50. function commandHandler()
  51.     while shouldRun do
  52.         e, cmd = event.pull("command");
  53.         if cmd == "clear" then
  54.             console.clearLog();
  55.         elseif cmd == "close" then
  56.             close();
  57.         elseif cmd == "update" then
  58.             os.execute("cmauto -i");
  59.         elseif cmd == "test" then
  60.             os.execute("/home/test.lua");
  61.         elseif cmd == "help" then
  62.             console.print("Haven't added this in yet :P you're on your own.", false)
  63.         elseif cmd =="reset" then
  64.             os.execute("rm data.dat");
  65.             print("Resetting.");
  66.             computer.shutdown(true);
  67.         else
  68.             console.print("&eCommand not found! Try \'help\' for more information", false);
  69.         end
  70.     end
  71. end
  72. table.insert(threadList, thread.create(commandHandler));
  73.  
  74. if data["robotAddress"] == nil then
  75.     print("No robot address found. Assuming new. Attempting to find robot.");
  76.     local robotAddress = network.findRobot();
  77.     if robotAddress ~= nil then
  78.         print("&5Paired with robot! [&a" .. robotAddress .."&5]")
  79.         data["robotAddress"] = robotAddress;
  80.         saveData();
  81.         network.init(robotAddress);
  82.     else
  83.         print("&eError adding robot.")
  84.     end
  85. else
  86.     network.init(data["robotAddress"]);
  87. end
  88.  
  89. function updateConsoleTopBar()
  90.  
  91. end
  92.  
  93. while shouldRun do
  94.     os.sleep(.1);
  95. end
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment