This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
gergo654's profile picture

I need help with the code

Started by gergo654, 29 May 2016 - 01:44 PM
gergo654 #1
Posted 29 May 2016 - 03:44 PM
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
TYKUHN2 #2
Posted 29 May 2016 - 06:12 PM
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 on 29 May 2016 - 04:13 PM
Creator #3
Posted 29 May 2016 - 08:26 PM
What is the last thing that gets printed?
gergo654 #4
Posted 01 June 2016 - 08:47 AM
i already fixed it but thank for the help :)/>