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

Search for a specific word?

Started by Imprivate, 23 December 2013 - 06:35 PM
Imprivate #1
Posted 23 December 2013 - 07:35 PM
So I'm trying to make a system with 4 computers where there is a sender, two receivers and a 'server'. The sender rednet.send's a string to the 'server' containing one of the receiving computers ID's. Is there a way for the 'server' to check the string for certain text (in this case the receiving computers ID) and, say, store it in a variable(e.g: ReceivingID). Then the server could do: rednet.send(ReceivingID, "String"). This is just a guess, is there any way at all for me to do this? Thanks for reading, Imprivate



I'm new to CC don't hate :)/>
TheOddByte #2
Posted 23 December 2013 - 08:08 PM
Well if you're just sending the ID's then it is easy

--# The computer that sends
local id = 101
rednet.send(<serverID>, id)

--# Server Computer
local id, receiverID = rednet.receive()
receiverID = tonumber(receiverID) -- Converts receiverID to a number
Imprivate #3
Posted 25 December 2013 - 05:22 PM
Well if you're just sending the ID's then it is easy

--# The computer that sends
local id = 101
rednet.send(<serverID>, id)

--# Server Computer
local id, receiverID = rednet.receive()
receiverID = tonumber(receiverID) -- Converts receiverID to a number

I wanted the ID in a string but oh well. I can always do read() and save that as the ID, I was just wondering if there was a way to check strings for certain text. Thanks anyway for you reply :)/>
P.S Checked out your Lasers game btw, +1'd :)/>
Inumel #4
Posted 25 December 2013 - 09:36 PM
I wanted the ID in a string but oh well. I can always do read() and save that as the ID, I was just wondering if there was a way to check strings for certain text. Thanks anyway for you reply :)/>
P.S Checked out your Lasers game btw, +1'd :)/>
id = tostring(id)
Imprivate #5
Posted 26 December 2013 - 08:15 AM
I wanted the ID in a string but oh well. I can always do read() and save that as the ID, I was just wondering if there was a way to check strings for certain text. Thanks anyway for you reply :)/>
P.S Checked out your Lasers game btw, +1'd :)/>
id = tostring(id)

Wouldn't that just check for the word "ID"? Oh well, this is still really useful, thanks! :)/>
awsmazinggenius #6
Posted 26 December 2013 - 11:05 AM
No, tostring() converts numbers to strings. tonumber() does the opposite, as long as the string represents a valid number.