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

My little E-Mail System's Table don't seem to work.

Started by craigforaday, 10 January 2013 - 10:39 AM
craigforaday #1
Posted 10 January 2013 - 11:39 AM
Basically I'm trying to make an Email system for the 5 of us on our FTB server, I got most of it working and I'm still working out some bits like the UI but the reading of Emails doesn't seem to work, as in I try sending a table across to another computer to read but it refuses to read any of the brackets (i.e if I try print(mail[2]) it leaves a blank line, whereas if I try print(mail) it prints the whole table like {[1]=blahblahblah [2]=…} etc.) Note my code on the client is not yet done, but the basic principal is that it will send to the server, which will store it, and when another user requests to check their mail they will get all the mail sent and their client will check which message is for them.

Any questions about my formatting then I'll try explain it…

Oh FYI, the rednet is opened in the startup for the Client PC.

Thanks.

Edit: Forgot to mention that - you may notice in the code - my ID for the server is 36 and the ID my PC used was 39.
theoriginalbit #2
Posted 10 January 2013 - 12:47 PM
For future reference, please try to post code using pastebin (for large code) or code tags [code][/code] for smaller code. A lot of the people in this section don't like downloading a file.

Now at a quick glance over the code I cannot see any problems… what does the print at line 64 of the client print?
craigforaday #3
Posted 10 January 2013 - 01:12 PM
Sorry, I'll remember that for next time… That line was there because I wasn't sure what the issue was so I added it just to see when the client was receiving the message as it originally wasn't.
theoriginalbit #4
Posted 10 January 2013 - 01:14 PM
and does it now? receive it?
craigforaday #5
Posted 10 January 2013 - 01:50 PM
It does receive it, it just cannot seem to read the table properly, the line below saying print( mail[2] ) should print the second item in the table yet it leaves a blank line and I'm not sure why, because if I type print(mail) it will print the whole table in form {[1]=39, [2]=Craig,… and so on until [6]=39,} So I know the table is there, I just don't know why I can't extract information from it.
theoriginalbit #6
Posted 10 January 2013 - 01:51 PM
ok and thats why I asked what print( mail ) did…. if its printing the whole table in that format that means the textutils.unserialize( table ) is required…. so trying to do mail[2] on a string is erroring…

EDIT: I do notice that you have it… there must be something else going on as to why it doesn't work… trying to find it now…
theoriginalbit #7
Posted 10 January 2013 - 02:02 PM
ok I have discovered what may be the cause… in the server this:


textutils.unserialize(data)
local msg = textutils.serialize(data)
rednet.send(senderId, msg)

can just be this


rednet.send(senderId, data)

since the contents of the file are already a serialized table. just an fyi doing this

textutils.unserialize(data)
didn't actually do anything, as the table gets returned, so it would have to be

data = textutils.unserialize(data)
to actually unserialize the data