←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

I need help with the code

gergo654's Photo gergo654 29 May 2016

if i get a KEYREQ message i get a error that says: rednet:87 Expected number.
can someone help?



term.setTextColor(colors.blue)
term.clear()
term.setCursorPos(1,1)
print("Server started!")
print("------------------------")
rednet.open("back")
while true do
id,msg = rednet.receive()
print("Listening")if msg == "SENDING" then
stringid = tostring(id)
print("Got MSG from:",stringid)
if fs.exists(stringid) == false then
print("File does not exist")
else
local file1 = fs.open(stringid,"w")
contents = file1.readAll()
file1.close()
print("Requesting password")
rednet.send(id,"REQKEY")
id1, msg1 = rednet.receive(10)
end
end

if contents == msg1 then
rednet.send(id1,"scs")
print(stringid,"Logged in successfully")
end
if msg == "KEYREQ" then
print("File already exists!")
else
print("Got MSG2 from:",stringid)
random = math.random(1000000,10000000)
stringrandom = tostring(random)
print("Generated random")
rednet.send(id,stringrandom)
print("Sent Password")
id2, msg2 = rednet.receive()
local file = fs.open(stringid,"w")
file.write(msg2)
file.close()
end
end
Quote

TYKUHN2's Photo TYKUHN2 29 May 2016

In my case, it's because contents = nil and msg1 = nil so it tried to use id1 which is nil.

File from which contents comes from is not created on my end
Edited by TYKUHN2, 29 May 2016 - 05:13 PM.
Quote

Creator's Photo Creator 29 May 2016

What is the last thing that gets printed?
Quote

gergo654's Photo gergo654 01 Jun 2016

i already fixed it but thank for the help :)
Quote