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

Bios 48 string expected, got nil

Started by Djinn, 09 May 2013 - 02:08 AM
Djinn #1
Posted 09 May 2013 - 04:08 AM
Title: Bios 48 string expected, got nil

I was trying to write a chat program that chat and receive messages.
The program will loop at receiving a message until i press "enter", which then i will be able to type in a message.
In this program, everything works fine, until i press a different key other than "enter" in receiving mode.

It printed out "Please press enter to chat" then produced the following error, bios: 48 : string expected, got nil
please help, met a few hiccups but was stomped at this one



term.clear()
term.setCursorPos(1, 1)
x,y,z = rednet.receive()
print(y)
print("Please enter username")
write ("Username: ")
user = read()
rednet.send(x, "user")
rednet.send(x, user)
function chat()
 sEvent, param = os.pullEvent("key")
  if sEvent == "key" then
   if param == 28 then
    write ("Message: ")
    mess = read()
    rednet.send(x, "message")
    rednet.send(x, user)
    rednet.send(x, ": ")
    rednet.send(x, mess)
   else
    print ("Press enter to chat")
   end
  end
end
while true do
 x,y,z = rednet.receive(0.1)
 write(y)
 x,y,z = rednet.receive(0.1)
 write(y)
 x,y,z = rednet.receive(0.1)
 print(y)
 chat(0.1)
end
Goof #2
Posted 09 May 2013 - 12:29 PM
could we see the server code.? somehow i think there might be a server code, since this is at the top:

x,y,z = rednet.receive()
print(y)
GravityScore #3
Posted 10 May 2013 - 04:08 AM
This is likely due to this:


 x,y,z = rednet.receive(0.1)
 write(y)

The computer probably isn't getting a response in the 0.1 seconds it's waiting for, meaning that rednet.receive is return nil. Next it tries to print out y, which is nil. The bios doesn't like this, and throws an error, saying a string is needed.

As Mikk said, could we see the server code?
Djinn #4
Posted 10 May 2013 - 11:45 AM
could we see the server code.? somehow i think there might be a server code, since this is at the top:

x,y,z = rednet.receive()
print(y)
This is likely due to this:


x,y,z = rednet.receive(0.1)
write(y)

The computer probably isn't getting a response in the 0.1 seconds it's waiting for, meaning that rednet.receive is return nil. Next it tries to print out y, which is nil. The bios doesn't like this, and throws an error, saying a string is needed.

As Mikk said, could we see the server code?

thing is, the 0.1 is for a timer, so that it keeps looping. I tried parallel but that may the screen really weird. With the current code changed to rednet.receive(), it stays at receiving a message which forces me to send a message over. Also, the error only happens when i press another key during the rednet.receive(). The thing is, esc button is also a key, which prevented me from checking whether it can receive messages or not.

yeah there is a server code

here


print("Chat Server Initiated")
print("Please enter server message")
write ("Message: ")
welcome=read()
print("Thank you")
print(" ")
while true do
x,y,z = rednet.receive()
if y == "ping" then
  rednet.send(x, "pong")
  write ("computer ")
  write (x)
  print (" pingged")
  sleep(1)
  rednet.send(x, welcome)
elseif y == "user" then
  x,y,z = rednet.receive()
  write (y)
  print (" is online")
  rednet.broadcast(y)
  rednet.broadcast("is now online")
elseif y == "message" then
  x,y,z = rednet.receive()
  write(y)
  rednet.broadcast(y)
  x,y,z = rednet.receive()
  write(y)
  rednet.broadcast(y)
  x,y,z = rednet.receive()
  print(y)
  rednet.broadcast(y)
end
end

oh and there is a client code before the code that has an error



print ("What is server number?") -- computer ID
x =tonumber(read())
print ("checking server...")
rednet.send(x, "ping")
x,y,z = rednet.receive(5)
if y == "pong" then
  print ("server connected")
  sleep(1)
  shell.run("chat")
else
  print ("server is not online at the moment")
end