Table Empty on Client

Hey guys, I’m having a little problem with my loading system and would really appreciate some help. Basically, every time my gamemode loads for the first time and auto-refreshes, my simple loading system (shared) recursively loads all gamemode files according to their realm. In addition to loading the files, it also inserts them into a table according to their realm. The problem is, whenever I try and print the serverside file table on the client, it’s empty. Why would it be doing this when it’s a global table and the other file tables print out fine and are pretty much the same as the one that isn’t working? Here’s how I insert the files into the tables:

[lua]
– These tables are defined near the top of the shared load file
CLIENT_FILES = { }
SHARED_FILES = { }
SERVER_FILES = { }

– These are called in the actual load function
table.insert( SHARED_FILES, file )
table.insert( SERVER_FILES, file )
table.insert( CLIENT_FILES, file )
[/lua]

Any help would be much appreciated, thanks in advance.

I don’t think this is enough information to pinpoint the problem

I think we know exactly what the problem is… But I’ll try not to be rude.
shared doesn’t actually mean shared, it just means both the server and the client will run the code. This doesn’t mean there is one version of the code with the same variables accessable from both client and the server, rather the code is being compiled once on the server and once on the client and is run separately, shared is really equivalent to making two copies of the file calling one client and the other server…

Someone really needs to find some effective way of getting this concept through to new lua learners because SHARED seems to confuse the heck out of them and I want to cut myself every time a question like this gets asked.

But seriously why should a table of serverside files exist on the client?

Thank you for the detailed response, I really appreciate it. I now understand more of what shared actually means. As for my issue, I don’t quite see how I can resolve it with that info. Sorry if I seem really stupid here but I’m not trying to be… Should I elaborate on exactly what the problem is and or provide more of the code I’m using?

The thing I don’t understand is, why is the server realm file table (SERVER_FILES) returning empty on the client while on the server it’s not? I’m inserting the file strings the same for each realm so I don’t see why it wouldn’t work? I’m not using table.insert wrapped in ‘if ( SERVER ) then’ or ‘if ( CLIENT ) then’ so why are they different on the client and server? Let me provide an example of what I mean. Let’s say I have a file called ‘sh_test.lua’ and inside was the following code:

[lua]
TABLE_ONE = { }
TABLE_TWO = { }
TABLE_THREE = { }

concommand.Add( “tableone_insert”, function( )

table.insert( TABLE_ONE, "test_value" )

end )

concommand.Add( “tabletwo_insert”, function( )

table.insert( TABLE_TWO, "test_value" )

end )

concommand.Add( “tablethree_insert”, function( )

table.insert( TABLE_THREE, "test_value" )

end )
[/lua]
If I ran each of these commands and then used PrintTable on the three tables, shouldn’t they all have the same value? Regardless of whether I do this on the server or client? Please correct me if I’m wrong. This method is pretty much the same sort of thing I use for the files.

Have I explained this properly?

Pretty sure if the concommand was ran serverside, it will only add to the SERVER_FILES table serverside even though the file is shared.
Also thelastpenguin is right, why do you need a table of the serverside files on the client?

Furthermore, are you using file.Find to find the gamemode files? That way you wouldn’t need the global file tables. Take a look here.

I use file.Find in the loading system. The only reason I want to insert the files into a table is so that I can easily view all the files that I loaded in the system and also so that I can use table.Count on them to determine how many files were loaded in the system all up.

Network it?

If you want to view the serverside files clientside, you load each file and add it to a local table, and then after the files are done loading, network the table to the client.

I’m such an idiot. I’m confused myself so much with how tables work through realms. I thought that I could just easily create a shared concommand which inserts a value into a table and use this command on the client and it would work but it doesn’t, I can only do it on the server so for example in the server console for it to work. Why exactly is it like this? I must look like a real idiot now, but I really appreciate everyone’s help. I’m no where near an advanced coder, I’m still learning. And I guess networking is what I will have to do to get this all to work so I’ll give that a go. Thanks again. :slight_smile:

[editline]9th May 2014[/editline]

Thank you very much, I overestimated my knowledge. I can certainly say I’ve learnt something today! :slight_smile: I also apologise for my stupidity.

I used the net library and managed to get it all working how I wanted it to. Thanks for the help guys!