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

File Transfering Program

Started by mannybjh, 20 September 2015 - 11:18 PM
mannybjh #1
Posted 21 September 2015 - 01:18 AM
Hey and thanks in advance for help. I am probably missing something very simple, but I can not find it. I am trying to create a file transfering program for my single player world. Here is the code:

args = {...}
function getModemSide()
  print("What side is the modem on?")
  side = read()
  return side
end
if args[1] == " " or args[2] == " " then
  print("Usage: fileT <action> <file name> [computer id]")
else
  if args[1] == "send" and args[3] == " " then
	print("Usage: fileT <action> <file name> [computer id]")
  else
	args[1] = action
	args[2] = fileName
	side = getModemSide()
	rednet.close(side)
	rednet.open(side)
	if action == "send" then
	  args[3] = computerId
	  file = fs.open(fileName, "r")
	  fileCode = file.readAll()
	  file.close()
	  rednet.send(tonumber(computerId), fileCode)
	
	elseif action == "receive" then
	  id, fileCode = rednet.receive()
	  file = fs.open(fileName, "w")
	  file.write(fileCode)
	  file.close()
	else
	  print("Action not accepted!")
	  print(action)
	end
  end
end

To run the program I type:
fileT send testProgram 4

I get the response:
Action Not Accepted!
(Then a blank line)

I know I'm not the best programmer so I'm sure this code could be cleaned up in about a million ways, but if you could help me with my problem, that would be great! Thanks!
Bomb Bloke #2
Posted 21 September 2015 - 05:00 AM
You're wanting to set "action" to args[1], not args[1] to action.