read if gay

This commit is contained in:
Crispy 2025-06-01 02:23:34 +02:00
parent 4f2631b349
commit 61eefcba8c
24 changed files with 21871 additions and 4224 deletions

View file

@ -1,24 +1,86 @@
pp = require("cc.pretty")
local filename = "tobuild"
rednet.open("left")
function stringtovec(str)
parts = {}
for part in string.gmatch(str, "([^,]+)") do
table.insert(parts,tonumber(part))
end
return vector.new(unpack(parts))
end
while true do
id, messages, protocol = rednet.receive()
id, message, protocol = rednet.receive()
if protocol == "getnexttobuild" then
file = fs.open(filename,"r")
line = file.readLine()
restof = file.readAll()
file.close()
file = fs.open(filename,"w")
file.write(restof)
file.close()
print(line)
rednet.send(id,line,"nexttobuild")
if message then
file = fs.open(
filename,
"r"
)
lines = {}
vec = stringtovec(message)
print(vector.new().tostring(vec))
record = nil
repeat
line = file.readLine()
wec = (line and stringtovec(line)) or nil
adding = wec
if
(wec)
and (
(not record)
or
(wec.y <= record.y)
)
then
if
(not record)
or
(
(vec-wec):length()
<
(vec-record):length()
)
then
--pp.pretty_print(wec)
--write("is better than")
--pp.pretty_print(record)
adding = record
record = wec
end
end
if adding then
table.insert(lines,adding:tostring())
end
until not line
rednet.send(id,record:tostring(),"nexttobuild")
print(record)
file.close()
file = fs.open(filename,"w")
for i,v in pairs(lines) do
file.writeLine(v)
end
file.close()
else
file = fs.open(filename,"r")
line = file.readLine()
restof = file.readAll()
file.close()
file = fs.open(filename,"w")
file.write(restof)
file.close()
print(line)
rednet.send(id,line,"nexttobuild")
end
elseif protocol == "failedtobuild" then
print(messages.."failed")
print(message.."failed")
file = fs.open(filename,"r")
restof = file.readAll()
file.close()
file = fs.open(filename,"w")
file.writeLine(messages)
file.writeLine(message)
file.write(restof)
file.close()
end