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

Mulitple input = read() Problem

Started by Computercrafterness, 23 February 2014 - 08:01 PM
Computercrafterness #1
Posted 23 February 2014 - 09:01 PM
I am trying to make a simple rednet email system on Tekkit Classic and i cant seem to get it to work the way i want it to. I want the user to be able to input the sender ID of the person they are trying to email, without having to open the coding and change it manually. I dont know what the problem is but im guessing it has to do with the input = read() stuff or the id, message = rednet.send(id, message) . The input = read() might be the problem because i dont think you can have more than one input that reads the written text because the first input gets canceled out when the next comes in. Im not sure how to make multiple input = read() lines. If you know what my problem is or think you can help, that would be great.
Lyqyd #2
Posted 23 February 2014 - 10:22 PM
Don't store them both in the "input" variable. If that's not what you're doing, you'll need to post your code.
ackley14 #3
Posted 24 February 2014 - 09:22 AM
Don't store them both in the "input" variable. If that's not what you're doing, you'll need to post your code.
yeah the part before the = read() is the variable name, that could be anything from a to blablabla. set it to something like compid = read() or something like that

edit - or if possible you can use local variables instead, that way they can be called individually, this will only work however if the two variables are in different functions and not needed in other functions. otherwise, use the original info i gave
Edited on 24 February 2014 - 08:24 AM
Thib0704 #4
Posted 24 February 2014 - 10:18 AM
I am trying to make a simple rednet email system on Tekkit Classic and i cant seem to get it to work the way i want it to. I want the user to be able to input the sender ID of the person they are trying to email, without having to open the coding and change it manually. I dont know what the problem is but im guessing it has to do with the input = read() stuff or the id, message = rednet.send(id, message) . The input = read() might be the problem because i dont think you can have more than one input that reads the written text because the first input gets canceled out when the next comes in. Im not sure how to make multiple input = read() lines. If you know what my problem is or think you can help, that would be great.

If I understood you are trying to get user input, and then send a rednet message?
If so:

local toID = read() -- Asks the user to input a String
toID = tonumber(toID) -- Changes the String to a Number
rednet.send(toID, "content of message!")
Edited on 24 February 2014 - 09:19 AM
Computercrafterness #5
Posted 24 February 2014 - 08:02 PM
Wow this is all great info. Thanks for all the help guys! ill let you know if it works. :)/>
Link149 #6
Posted 24 February 2014 - 09:40 PM
If I understood you are trying to get user input, and then send a rednet message?
If so:


local toID = read() -- Asks the user to input a String
toID = tonumber(toID) -- Changes the String to a Number
rednet.send(toID, "content of message!")

Of course, you would have to apply some "type checks" after changing the String to a Number, to make sure the content of the local variable "toID" is a valid number before calling the rednet.send() function. Otherwise you might get a nice error message like "[string: "yourProgramNameHere"]:lineNumber: number expected, got string" :)/>. And here's the problem in programming/scripting: You always need to think "What happens if the user does something ELSE than what I expect him to do ?"