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

Anyone know how to alter the read?

Started by Cole, 03 December 2014 - 09:16 PM
Cole #1
Posted 03 December 2014 - 10:16 PM
so im making a simple chat program, but im trying to make it so read() can find out the ID, i've put
write("")
ID = read()
rednet.send(ID,"message")

so how do i make it so the program reads the read() as example instead of "example"
(the change there is the " " being around it, the big question is how do i make it so the system ignores the " "?)
Lyqyd #2
Posted 03 December 2014 - 10:21 PM
I'm really not sure what you mean. If you type "example", the string will contain "example", likewise with example. I'm really not sure what you're trying to ask. Unless you want to get a number instead of a string? You'd just need to tonumber() the return value.
Bomb Bloke #3
Posted 04 December 2014 - 12:17 AM
Sounds like he's indeed asking about types, without understanding that strings/numbers are generally called, um, strings/numbers. ;)/>

A basic example as to how you might convert the type of read()'s output:

ID = tonumber(read())

If what the user types can't be represented as a number, then tonumber() will fail and return nil.
Cole #4
Posted 04 December 2014 - 05:38 PM
thanks, really helped. i didn't really know the tonumber() was a thing. thanks again!