←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Error for print

phaleron's Photo phaleron 19 Jan 2013

hey guys,
iv'e got an error when i send something from my other computer..
and its showing only when im using "print(hey)"


rednet.open("back")
term.clear()
term.setCursorPos(1,1)
i, m = rednet.receive()
write("van "..i.."")
print("hey")
write(m)

beside that.. can i put an varible or a string in a print()?
like this :

print(m)
or
print("you've got "..m.." cakes")

thats the reason im using write
Quote

theoriginalbit's Photo theoriginalbit 19 Jan 2013

yes you can use variables inside of print... and you can concatenate strings around the variable... just make sure that the variable actually has something inside of it...

what is the exact error?
Quote

phaleron's Photo phaleron 19 Jan 2013

thanks for the fast reply!

my error is
"startup"6" attempt to call string"

(ps. im dutch.. sorry for the bad english :) )
Quote

crazyguymgd's Photo crazyguymgd 19 Jan 2013

the error you are getting might be from something else. The code you posted works fine. So...

View PostTheOriginalBIT, on 19 January 2013 - 11:25 PM, said:

what is the exact error?
Quote

phaleron's Photo phaleron 19 Jan 2013

uhmm.. thats weird..
the one that is sending is:


term.clear()
term.setCursorPos(1,1)
rednet.open("back")
print("Mail box")
print()
write("Name: ")
n=read()
write("to: ")
i=tonumber(read())

print("message:")
print()
m=read()
rednet.send(i, m)


i think its something with "tonumber()" .. i dont know of that is true..
Quote

theoriginalbit's Photo theoriginalbit 19 Jan 2013

tonumber will only error if you add any non-number characters...

so the error is on line 6 of that EXACT code? o.O

have you tried rebooting the computer recently? you may have overridden an OS function at some point...
Edited by TheOriginalBIT, 19 January 2013 - 11:42 PM.
Quote

remiX's Photo remiX 19 Jan 2013

The tonumber() is needed because you need to convert the string of input (i) to a number in order to send a message to that PC/turtle via rednet.

On the other hand, your code has no errors...

This is exactly right to concatenate a string and a variable.
print("you've got "..m.." cakes")

Before that, maybe add a print(type(m)) to see if it's a string or whatever.

PS: Please use [code]code here...[/code] tags :)
Quote

phaleron's Photo phaleron 19 Jan 2013

View PostTheOriginalBIT, on 19 January 2013 - 11:41 PM, said:

tonumber will only error if you add any non-number characters...

so the error is on line 6 of that EXACT code? o.O

have you tried rebooting the computer recently? you may have overridden an OS function at some point...

yeah, i know.. so maybe the receiver must convert the "tonmuber" to a string again?
Quote

Doyle3694's Photo Doyle3694 19 Jan 2013

You have a variable, or a string rather called "print" somewhere on your computer.
Quote

theoriginalbit's Photo theoriginalbit 19 Jan 2013

View Postphaleron, on 19 January 2013 - 11:45 PM, said:

View PostTheOriginalBIT, on 19 January 2013 - 11:41 PM, said:

tonumber will only error if you add any non-number characters...

so the error is on line 6 of that EXACT code? o.O

have you tried rebooting the computer recently? you may have overridden an OS function at some point...

yeah, i know.. so maybe the receiver must convert the "tonmuber" to a string again?
No because the tonumber that you are performing is so the rednet API knows which computer to send to... but according to your error and the code you just posted the error is with write("Name: ") not to number... is that script thats sending the "startup" file?
Quote

phaleron's Photo phaleron 19 Jan 2013

View PostTheOriginalBIT, on 19 January 2013 - 11:48 PM, said:

View Postphaleron, on 19 January 2013 - 11:45 PM, said:

View PostTheOriginalBIT, on 19 January 2013 - 11:41 PM, said:

tonumber will only error if you add any non-number characters...

so the error is on line 6 of that EXACT code? o.O

have you tried rebooting the computer recently? you may have overridden an OS function at some point...

yeah, i know.. so maybe the receiver must convert the "tonmuber" to a string again?
No because the tonumber that you are performing is so the rednet API knows which computer to send to... but according to your error and the code you just posted the error is with write("Name: ") not to number... is that script thats sending the "startup" file?
yes, it is the startupfile..
Quote

phaleron's Photo phaleron 19 Jan 2013

it works now!.

first what i have done whas removed print() out of

print("message:")
print() -- this one removed
m=read()

and then i rebooted the computers

so helpfull!
thanks guys!
Quote

phaleron's Photo phaleron 20 Jan 2013

there is only one problem left

I want to send i, m and n with
rednet.send(i, m, n)

when i do something like this
write("name ")
n=read()

then when i send Varible "n" there stands a number 3.
do you guys know a solusion?
Quote

theoriginalbit's Photo theoriginalbit 20 Jan 2013

View Postphaleron, on 20 January 2013 - 12:05 AM, said:

there is only one problem left

I want to send i, m and n with
rednet.send(i, m, n)

when i do something like this
write("name ")
n=read()

then when i send Varible "n" there stands a number 3.
do you guys know a solusion?

Sending end
-- read the variables here
rednet.send( i, textutils.serialize( {m,n} ) )

Receiving end
-- receive rednet
msgTable = textutils.unserialize( receivedMsg )
m = msgTable[1]
n = msgTable[2]

This will make a table of all the items you want to send by turning it into a string and sending it... Then at the other end will turn it back into a table where you can use it.
Quote