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

rednet file transfer help needed!

Started by arnipa2, 16 June 2012 - 08:09 PM
arnipa2 #1
Posted 16 June 2012 - 10:09 PM
Hi guyz i got this really anoying bug/problem when i use my sender program on pc1 to send an existing file on pc1 to pc2 using modems to overwrite file on pc2, everything works but lua changes the conten of the file transfered to a freaking table! anyone knows how to resolve this?? am fairly new to computercraft and LUA(got some experience with visualbasic xD and roblox)
BTW the main purpose of these programs is to use them on tekkit to make a local server on my plot…pls dont tell me how to do it better way( i like to do everything almost by myself)

Sender:
print("What do you want to send?")
filename = io.read()
file = io.open(filename, "r")
file2 = file.read("a")
rednet.broadcast(file2)

works perfectly …sends everything with no errors…( i know that cos i used the same code to send single lines of code to the other console)


receiver
local event, param1, param2, param3 = os.pullEvent("rednet_message")
print("Got message!!")
name = io.read() -- filename to be overwritten
local file = io.open("name", "w")
print("Processing Message")
file:write(param2)
print("Writting Mesage to the ",file)
file:close()
sleep(1)
print("Message save to ",file)

and on the receiver console i got:
>receiver
Got Mesage!!
save – my file which i want to overwrite
Processing Message
Writting Mesage to the table :17b59e2
Message saved to the table: 17b59e2

i like how the errors exactly fit my sentence choice
Cloudy #2
Posted 16 June 2012 - 11:28 PM
Lua doesn't change the file received into a table - the io library returns a table with functions you can call on it.

I don't understand why that is a problem? You seem to write the data fine, it's just you're printing the object.
arnipa2 #3
Posted 17 June 2012 - 09:53 AM
i dont understand what u mean
Lyqyd #4
Posted 17 June 2012 - 12:09 PM
He means that nothing is wrong; you're simply misunderstanding the nature of the file system operations. "file" as you're using it there is a table. The name of the file (which is what I think you would like to be using in your print calls) will still be in the variable "name", so you should use that instead.
arnipa2 #5
Posted 17 June 2012 - 01:09 PM
got it working xD with just text now checking if it sends file BTW thx for telling me bout name variable…i would not get that by my self