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

functions and sending a string through veriable

Started by kain184, 01 July 2014 - 02:05 PM
kain184 #1
Posted 01 July 2014 - 04:05 PM
hello all trying to get a little help i just started making functions and am having a little bit of a time trying to send a string through a veriable can anyone help me do so here is my code that i need with some notes

function test()
os.loadAPI("rom/apis/rednet")
rednet.open("right")
com = rednet.isOpen("right")
if com == true then
    print("communication established")
    print("testing connections")
    rednet.send(21, "test")
    event,id, message = os.pullEvent("rednet_message")
  if id ==21 and message== "test" then
    print("communication good")
    rednet.send(18, "test")
    event,id, message = os.pullEvent("rednet_message")
   if id ==18 and message== "test" then
    print("communication good")
 
 
  
   else
   print("message error")print(id)print(message)
   end
  else
  print("message error")print(id)print(message)
  end
else
print("communication error")
end
end
--###############################################
function isOpen(messageSend, idnum)
   rednet.open("right")
   com = rednet.isOpen("right")
   if com == true then
    rednet.send(messageSend, idnum)-- need to send message as string and idnum as number
   else
   print("communication error")
   end
end
--###############################
function isRec(messageRec, idnum)
event,id, message = os.pullEvent("rednet_message")
if id ==idnum and message== messagerec then
return true
else
return false
end
end
--################################
function plant()
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(15)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(3)
		 redstone.setOutput("back", true)
		 sleep(2)
		 redstone.setOutput("back", false)
		 sleep(3)
		 redstone.setOutput("back", true)
		 sleep(2)
		 redstone.setOutput("back", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)
		 sleep(1)
		 redstone.setOutput("top", true)
		 sleep(1)
		 redstone.setOutput("top", false)
		 redstone.setOutput("top", false)

end
--################################
while true do
os.loadAPI("rom/apis/rednet")
test()
print("supply and enable processing")
isOpen(supply, 21) -- need to send word as string into veriable and number as number
if not isRec(supply, 21) then --need to recieve word as string and number as number
print("message error")print(id)print(message)
else
print("supply complete")
print("planting")
isOpen(plant, 18)
  if not isRec(plant, 18) then
  print("message error")print(id)print(message)
  else
 
  print("bot planting")
plant()
sleep(1)
redstone.setOutput("bottom", false)
print("disable processing")
isOpen(harvest, 21)
   if not isRec(harvest, 21) then
   print("message error")print(id)print(message)
   else
   print("harvest Complete")
isOpen(supply, 21)
    if not isRec(supply, 21) then

    else
	 print("supply complete")
    end
   end
  end
end
end  
--#############################
if anyone can help me it would be most appreciated
AssossaGPB #2
Posted 01 July 2014 - 07:32 PM
Your problem is here:
rednet.send(messageSend, idnum)
The rednet send command is:
rednet.send(idToSendTo,Message)
There is also:
rednet.broadcast(Message)
Which broadcasts the message to all computers.

To combine a string with another variable, use ".."
So, for you code line:
rednet.send(id,messageSend..idnum)

I hope that helped
Edited on 01 July 2014 - 05:32 PM
kain184 #3
Posted 02 July 2014 - 12:50 AM
yes i relized the send was backwords a little bit after i had but the only reason the idnum is there is to pull from outside the function which number i need to send to that way i would only have to fill in the number i dont have to recieve that number but for the error check but it always sends that anyway. thank you for the help though.