Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

24KaratCarrot

Members
  • Content Count

    3
  • Joined

  • Last visited

Posts posted by 24KaratCarrot

  1. 1 hour ago, Molinko said:
    
     1 local manager = {}
     2 
     3 -- # local fs = require("filesystem")
     4 local component = require("component")
     5 local event = require("event")
     6 
     7 local modem = component.modem
     8 local SENDPORT = 1
     9 
    10 function manager.sendFile(fileName, address)
    11 	 inFile = io.open(fileName, 'r')
    12   modem.open(SENDPORT)
    13   modem.send(address, SENDPORT, fileName)
    14   os.sleep(2)
    15   fileString = infile:read('*a')
    16   modem.send(address, SENDPORT, fileString)
    17   modem.close(SENDPORT)
    18 end
    19
    20 -- ... The library goes on
    21
    22 return manager

    This uses the 'io' lib instead. Also note the '*a'(readall from buffer) arg passed to infile:read.

    Hope this helps :) 

    I think the inFile:read() thing was the problem, as when I changed that, the error changed. I honestly don't know exactly what fixed the problem, but I got it working and cleaned things up a bit! I think it was the read("*a") and requiring io, but I'm not  entirely sure.Thanks a bunch for your help, here's the final product:

    local manager = {}
    
    local component = require("component")
    local event = require("event")
    local io = require("io")
    
    if not component.isAvailable("modem") then
      error("No compatable network card found.")
    end
    
    local modem = component.modem
    local SENDPORT = 1
    
    function manager.sendFile(fileName, address)
      print("Preparing to send file...")
      modem.open(SENDPORT)
      local inFile = io.open(fileName, 'r')
      local fileString = inFile:read("*a")
      os.sleep(2)
      modem.send(address, SENDPORT, fileName)
      inFile:close()
      print("Sending file...")
      modem.send(address, SENDPORT, fileString)
      modem.close(SENDPORT)
      print("File sent.")
    end
    
    -- The library goes on
    
    return manager

     

  2. 27 minutes ago, Molinko said:

    address is misspelled as 'addresss'. too many s... That was surprisingly hard :P 

    Man, I wish this were the mistake! I don't know how that s got there, but it happened between my source and posting it here, the original code has address spelled correctly. But I'm surprised you caught that, I read over everything after I posted and didn't catch it! I've edited the question so that it's spelled correctly, but the problem still persists.

  3. I'm trying to port over a library I made for Computer Craft, but I can't tell for the life of me where this error is coming from.

    I know that the library works properly, as I've gotten another of it's functions working just fine. Sorry if this is a noob question, I am a java developer, and am just getting into lua.

     

    Full error message:

    bad argument #1 (number expected, got string):
    stack traceback:
        [C]: in function 'error'
        machine:986: in function <machine:983>
        (...tail calls...)
        /lib/fileMngr.lua:10: in function 'sendFile'
        /home/send:3: in main chunk
        (...tail calls...)
        [C]: in function 'xpcall'
        machine:751: in function 'xpcall'
        /lib/process.lua:63: in function </lib/process.lua:59>

    fileMngr.sendFile:

     1 local manager = {}
     2 
     3 local fs = require("filesystem")
     4 local component = require("component")
     5 local event = require("event")
     6 
     7 local modem = component.modem
     8 local SENDPORT = 1
     9 
    10 function manager.sendFile(fileName, address)
    11 	 inFile = fs.open(fileName, 'r')
    12   modem.open(SENDPORT)
    13   modem.send(address, SENDPORT, fileName)
    14   os.sleep(2)
    15   fileString = infile:read()
    16   modem.send(address, SENDPORT, fileString)
    17   modem.close(SENDPORT)
    18 end
    19
    20 -- ... The library goes on
    21
    22 return manager

    send.lua (simple test program):

    fm = require("fileMngr")
    address = "<the receiving modem's address>"
    fm.sendFile("test", address)

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.