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

User-Selected Computer ID

Started by Xninjacat, 14 March 2012 - 11:30 AM
Xninjacat #1
Posted 14 March 2012 - 12:30 PM
How do i get the user to enter an id?

Spoilerterm.clear()
term.setCursorPos(1, 1)

rednet.open("back")

io.write("Enter a Messege: ")
m = io.read()
io.write("Enter PC ID: ")
i = io.read()

rednet.send(i, m)
^^^that code doesn't work^^^

How do i fix it?
Liraal #2
Posted 14 March 2012 - 02:05 PM
try rednet.send(tonumber(i), m)
kamnxt #3
Posted 14 March 2012 - 02:07 PM
You must use tonumber() to change the string to a number.

term.clear()
term.setCursorPos(1, 1)
rednet.open("back")
io.write("Enter a Message: ")
m = io.read()
io.write("Enter PC ID: ")
i = tonumber(io.read())
rednet.send(i, m)
Xninjacat #4
Posted 14 March 2012 - 03:01 PM
You must use tonumber() to change the string to a number.

term.clear()
term.setCursorPos(1, 1)
rednet.open("back")
io.write("Enter a Message: ")
m = io.read()
io.write("Enter PC ID: ")
i = tonumber(io.read())
rednet.send(i, m)

Thanks sooo much :mellow:/>/>
It works now.
I read about the tonumber function but i thought you could only use it like this


x = "blah"
tonumber(A NUMBER HERE)
print(x)

But any way, thanks again. ;)/>/>

EDIT:

BTW sorry i didn't use the
 tags...
Xninjacat #5
Posted 15 March 2012 - 08:48 PM
One more thing, can i make a program to display text on monitor?


monitor right hello
[/code

obviously doesn't work.
Liraal #6
Posted 15 March 2012 - 08:52 PM
you have to redirect the output:
local screen=peripheral.wrap(side)
term.redirect(screen)

Not sure whether that is correct, i don't know the monitors well
Xninjacat #7
Posted 16 March 2012 - 04:47 AM
you have to redirect the output:
local screen=peripheral.wrap(side)
term.redirect(screen)

do i put that inside the hello program or inside a different file (i.e show.lua/show)?

and what do you mean by screen in "term.redirect(screen)"?