The code you posted is not working. I tried using it, here is how I used it:
sender
local modemSide = "right" --Edit this for the side the modem is on.
local sendID = 3 --The ID to send the code to.
term.clear()
term.setCursorPos(1,1)
write("Script to run on receiving computer/turtle, separate arugments with a ','.")
input = read()
if input ~= "" then
rednet.open(modemSide)
rednet.send(sendID, input)
rednet.close(modemSide)
else
print("Example of use: go, forward")
end
receiver
function split(pString, pPattern) --I do not take credit for making this function. I found this on a website and this is what I use for most of my scripts.
local Table = {}
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
local modemSide = "right"
local receiveID = 4
while true do
id, msg = rednet.receive()
if id == receiveID then
local runs = split(msg, ",")
local runCode = "pcall("
for k,v in pairs(runs) do
runCode = runCode..runs[k]
end
runCode = runCode..")"
local run = loadstring(runCode)
success, error = run()
if not success then
print(error)
end
end
end
I ran program on receiver turtle. When running on sender, i typed "Dig2.1, 2" meaning dig2.1 program, argument 2. There was no error received on either computer or turtle.
I don't understand at all how the split function on the receiver is working or what its doing, nor the runs/runcode after that. It doesn't have to be fancy. All i want is to be able to define the argument to use on a specific program via rednet.