Compare commits

...

3 Commits

Author SHA1 Message Date
448e0354ea Added some core loop mechanic 2025-05-07 14:43:22 +02:00
2edb549156 added tick to core 2025-05-06 14:56:27 +02:00
37c404603d Created a test for downloading the core with the core.
added some safe checks in the core
2025-05-06 14:47:51 +02:00
2 changed files with 52 additions and 2 deletions

View File

@@ -98,16 +98,45 @@ function Core:download(file)
return false, "Invalid type: "..textutils.serialiseJSON(data) return false, "Invalid type: "..textutils.serialiseJSON(data)
end end
if fs.exists(file) then
fs.delete(file);
end
local fileStream = io.open(file, "w"); local fileStream = io.open(file, "w");
fileStream:write(data.fileContent);
if not fileStream then
return false, "Failed to open fileStream"
end
fileStream:write(data.data);
fileStream:close(); fileStream:close();
return true, "Success" return true, "Success"
end end
function Core:tick()
if not self then
error("No instance!")
end
if not self.ws then
return false, "Not initilized"
end
self:send({type = "TICK"});
local success, data = self:read();
if not success then
return false, "Failed to do anything: "..data;
end
print("Server expects Action: "..textutils.serialiseJSON(data))
end
function Core:disconnect() function Core:disconnect()
if not self then if not self then
return "Not instance" error("No instance!")
end end
if not self.ws then if not self.ws then
@@ -115,4 +144,16 @@ function Core:disconnect()
end end
self.ws.close(); self.ws.close();
end
function Core:setLoop(loop)
self.loop = loop;
end
function Core:start()
while true do
if self.loop then
self.loop();
end
end
end end

9
downloadCore.lua Normal file
View File

@@ -0,0 +1,9 @@
require("core")
local core = Core.new();
core:connect();
core:download("core.lua");
core:disconnect();