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

rednet.send variable + string

Started by NorwayKtm, 01 September 2014 - 04:07 PM
NorwayKtm #1
Posted 01 September 2014 - 06:07 PM
Hey all!
I'm trying to rednet.send a variable + string but don't know how this works. :P/>

shell.run("clear")
term.setTextColor(colors.orange)
print("BackOS 1.5")
print("")
term.setTextColor(colors.white)
print("Wie viel Brot soll ich backen?")
term.setTextColor(colors.blue)
print("[1   |   3   |   6]")
term.setTextColor(colors.white)
local anzahl = io.read()
--This area
rednet.send(13,anzahl)
--*over me*
term.setTextColor(colors.green)
print("Ihr Brot wird nun gebacken")
term.setTextColor(colors.white)
sleep(3)
shell.run("startup")
And I want to send "anzahl" + a custom text.

local anzahl = io.read()
rednet.send(13,anzahl,"hello")

Help please :rolleyes:/>
hilburn #2
Posted 01 September 2014 - 10:44 PM
A relatively easy way to do this would be to just send the text in the first message and then the contents of the variable in the second.

Alternatively if you really want to send it in one you could do something with string functions. Something like:


local anzahl=io.read()
rednet.send(13,"<anzahl>"..anzahl.."</anzahl>".."hello")

and then on the receiving computer:


temp=string.sub(msg,string.find(msg,"<anzahl>(.-)</anzahl>")) --#removes the "hello" and anything else not included within the <></> tags
temp=string.gsub(temp,"<(.-)>","") --#removes the tags
local anzahl=temp --#returns the variable
KingofGamesYami #3
Posted 01 September 2014 - 10:48 PM
or you could send a table

rednet.send( 13, { anzah1 = anzah1, msg = "hello" } )

local anzah1, other_variable = msg.anzah, msg.msg
Edited on 01 September 2014 - 08:48 PM