- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
-
Content Count
3 -
Joined
-
Last visited
Posts posted by 24KaratCarrot
-
-
27 minutes ago, Molinko said:
address is misspelled as 'addresss'. too many s... That was surprisingly hard
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.
-
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)
Getting error "bad argument #1 (number expected, got string):"
in Programming
Posted
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: