• Can't insert to table inside of a net receive?
    5 replies, posted
I am trying to send data from a text file I have on the server to the client, this is my client code [CODE]local data= {} net.Receive("sendData", function() local line = net.ReadString() table.insert(data, line) print("Succesfully received data!") end) print(data[1])[/CODE] On the server, I iterate by line through the text file and send a net string of each line to the client so that I don't hit the writestring limit, everything is being sent and received. If I were to print the readstring in the net.Receive it would print out what I want.. But the table.insert isn't inserting into the cached table outside of the net.receive, the print outside of the function is printing nil.. Why is this?
[QUOTE=Moat;52015854]You're printing it before the server has a chance to send you the string and have you insert it into the table.[/QUOTE] The send is in a playerAuth hook, I thought that might be the case but even after refreshing the script in game after loading fully in it still prints nil.
The print outside of the function is running when your file is loaded and data is still empty, you need to run it after you receive some data.
Okay, that makes sense, after putting it in a timer.simple I got it to print out. Thanks for the help! [CODE]timer.Simple(10, function() print(data[1]) end)[/CODE]
Sorry, you need to Log In to post a reply to this thread.