Reading data files from server and sending to the client.

Hello, I’m kind of stuck. I was coding an addon that shows two values and a player’s name which is stored inside of the data folder. When I finished I noticed I was reading from the client’s data folder instead of the server’s data folder which made the addon useless. What it does essentially is make a data file named after the player’s SteamID64 and then .txt. Because I loop over these files (the system doesn’t know how many files) I use k, v in pairs to loop through the files the files contain data like this:

15 | Galaxy | 30

I use string.Explode on " | " so I get a table with 15, Galaxy and 30. These three values need to be read off a data file on the server and then displayed in a DListView on the client, everything worked fine except it was reading client data files :confused:

What would be the best solution? I have tried networking the tables but that’s practically impossible due to it using k, v in pairs to loop over all the files. I wouldn’t mind downloading the files on the client everytime a file get’s updated but I wouldn’t know how, best way I think might be using net.WriteTable but as said above it doesn’t really work out. I believe there might be a pretty simple solution I’ve looked over several times now, please let me know :slight_smile:

That isn’t even a good way to store information. Your script would break if someone with the | character in their name joined.

You’re essentially talking about flatfile storage; GMod implementations usually use JSON to achieve this. You can network all necessary information when the player first joins, or when they first open the panel. Just remember that many things like constant strings can be networked as ints using a stringtable, and net.WriteTable isn’t necessary if you know exactly what data you’re sending.

Also, other data storage methods like SQL and redis might be of interest to you if you want more speedy, permanent memory retrieval.

Damn totally forgot about that, good thing you told me.

[editline]12th February 2017[/editline]

Could I make the server write data to a table in SQLite and let the client read this or would this cause problems? Seeing as sql.Query is shared according to the wiki. Also does SQLite update instantly like a txt file or would it require the player to relog or server to restart?

The method is shared, but uses two separate “databases.” SQL should only be used for storage and not any sort of clientside info retrieval – you will still have to network.

I’ll try that out soon then, thanks for the help.