What would be the best way to set up a table that can be read and edited by server and client scripts?
use the net library.
[editline]24th May 2015[/editline]
That’s more sending existing tables, is it not?
Make it shared. Don’t put it in an “if Client then” or an “if SERVER then”. Put it in somewhere like /lua/autorun/ not /lua/autorun/server/ or /lua/autorun/client/. Or if you put it somewhere else make sure to AddCSLua it and include it.
Well, my entire goal for this thing is to be able to add the player firing a gun to a table that can be read by every client in the server, and I’m not sure how to do that, and I’m not entirely sure that what you’re suggesting would help.
Making it shared means it is shared between client and server. You could alternatively use net.WriteTable along with the net library to make the table on the server and send it to the client when they need it, which is probably a safer solution. If you don’t understand any of the suggestions someone has offered you so far you may want to learn a bit more about programming in Lua. Here is a good starter.
It’s not that I don’t understand any of these suggestions, it’s that none of them are particularly helpful. Frankly, I was hoping that there would be an easy solution that I’m ignorant of, as I’ve only just started using Lua in GMod and the wiki isn’t very elucidating.
Also, some of these solutions simply aren’t feasible because of the environment this needs to work in. I’m not trying to make this difficult, but I am just hoping there’s an easy way of doing this.
This is so wrong.
A shared file is just a concept we use; we create shared files that we want to execute on both the server and client, once it has executed, any changes made do not get sent between server and client unless we specifically network it.
so you can put this in a shared file:
MyVariable = 123
then if you change that on the server to 456, the client will still be 123.
I’m note sure that’s what he meant, but then again, I’m not sure what he meant at all.
Client and Server are not connected in anyway in glua.
So you need to connect them, for that you could use Net Library
What you need to do, is when server or client updates value, you tell the opposite that you changed the value to something, and then it updates it with your value so they will be synced.
What Blasteh means that you setup value for both, server and client and when you change that value it will not be changed in the opposite, so you need to use net library to change it on opposite.
Yup, this isn’t helpful, but thanks for the help.