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

help i cant find string

Started by cmurtheepic, 23 November 2012 - 11:35 AM
cmurtheepic #1
Posted 23 November 2012 - 12:35 PM
my program keeps saying string expected


rednet.open(back, true)
function gettingNews()
  while true do
  message = rednet.recieve()
  end
end
x = message
function displayingNews()
  while true do
    textutils.slowWrite(x, 5)
  end
end
parallel.waitForAny(gettingNews(), displayingNews())
displayingNews()
 
 
 
Orwell #2
Posted 23 November 2012 - 12:38 PM
It expects a string at the first line:

rednet.open('back', true)
instead of:

rednet.open(back, true)

In your code, it's looking for a variable named back which is nil, while it actually needs the string 'back'.
Orwell #3
Posted 23 November 2012 - 12:43 PM
It expects a string at the first line:

rednet.open('back', true)
instead of:

rednet.open(back, true)

In your code, it's looking for a variable named back which is nil, while it actually needs the string 'back'.

Edit: message hasn't been declared yet when you do 'x = message', you might just wanna do this:

rednet.open(back, true)
local message = ""	 -- set to "" to make sure that it isn't nil when displayingNews uses it
function gettingNews()
  while true do
  message = rednet.recieve()
  end
end
function displayingNews()
  while true do
	textutils.slowWrite(message, 5)
  end
end
parallel.waitForAny(gettingNews, displayingNews)

Also, you should pass the function variables to parallel.waitForAny, not the result of the function calls. So rather my correction above than this:

parallel.waitForAny(gettingNews(), displayingNews())

Actual edit: How could I've pressed the wrong button..? ;)/>/>
cmurtheepic #4
Posted 23 November 2012 - 02:14 PM
ok now it is saying that

message = rednet.recieve()
is nil
help?
Orwell #5
Posted 23 November 2012 - 02:44 PM
ok now it is saying that

message = rednet.recieve()
is nil
help?
A line of code cannot be nil. ;)/>/> What is the exact error? And what is your full code by now?
Kingdaro #6
Posted 23 November 2012 - 04:11 PM
ok now it is saying that

message = rednet.recieve()
is nil
help?
Should be

id, message = rednet.receive()
Orwell #7
Posted 23 November 2012 - 05:03 PM
ok now it is saying that

message = rednet.recieve()
is nil
help?
Should be

id, message = rednet.receive()
Oh man… How could I've missed that? Time to go to bed. ;)/>/>