24 posts
Location
location = "Singapore"
Posted 25 November 2012 - 03:56 AM
I need to send an input from a computer to another computer, and it needs to use this:
rednet.send(10, input.."q")
(It's done like this right? :lol:/>/> )
BUT, when the other computer receives it, I need to do some maths do the input, and I don't know how to remove the "q"from the string(So that I can convert it into a number). Please help me :D/>/> . I'm a beginner at Lua so… yea :P/>/> Help will be much appreciated! :D/>/>
818 posts
Posted 25 November 2012 - 04:02 AM
sender, message = rednet.receive()
sentnumber = string.sub(message,#message-1,#message)
message = string.sub(message,1,#message-1)
1688 posts
Location
'MURICA
Posted 25 November 2012 - 04:06 AM
Some other solutions, you could capture the number with match:
id, message = rednet.receive()
number = tonumber(message:match('(%d+)q'))
if number then
-- stuff
end
Or you could simply remove the q altogether with gsub:
id, message = rednet.receive()
number = tonumber(message:gsub('q',''))
if number then
-- stuff
end
536 posts
Posted 25 November 2012 - 04:10 AM
or you could do:
local id, message, distance = rednet.receive()
number = tonumber(message:sub(1, -2))
8543 posts
Posted 25 November 2012 - 02:12 PM
Or, since you're only appending the q to make it into a string:
rednet.send(10, tostring(input))
--receive:
id, message = rednet.receive()
message = tonumber(message)
1688 posts
Location
'MURICA
Posted 25 November 2012 - 02:16 PM
Isn't it turned into a string when it's sent, though? I haven't actually sent a number though rednet before, so I'm not sure. :/
8543 posts
Posted 25 November 2012 - 02:24 PM
No, it'll yell at you if you try passing non-strings as the message.
2005 posts
Posted 26 November 2012 - 07:35 AM
I was trying to think of a plausible explanation for why the q was needed in the first place.
1688 posts
Location
'MURICA
Posted 26 November 2012 - 07:39 AM
I was trying to think of a plausible explanation for why the q was needed in the first place.
I thought it was a check to make sure that a specific receiving program only process the data with the "q" at the end, and not other rednet signals.