Shared Table - Client

I have a table in shared.lua
As I know, you can use it at client and server side right?

I can print it from shared.lua but I can’t from cl_init.lua


Resources.Info = {}

Resources.Info = util.KeyValuesToTable(file.Read(“DarkAges/Save/info.txt”) )

[editline]31st October 2010[/editline]

Error message:

[darkages\gamemode\mainmenu.lua:105] attempt to index field ‘?’ (a nil value)

[editline]31st October 2010[/editline]

Line 105

[editline]31st October 2010[/editline]

Item is good

FYI, you don’t need the util. bit.

It seems that the Info table is empty. The file you are trying to read probably doesn’t exist client side.

Yeah, it is true, but it is loaded in shared.lua

Except it doesn’t work that way.

Your best bet is to use usermessages or datastream.

There’s no such thing as shared tables. When you create something in shared.lua, you actually create two instances of it - one on the server and one on the client. No connection is made between them.

But, for example, I have an other table in shared.lua

[LUA][1] = “sardine”[2] = “trout”[3] = “pike”[4] = “salmon”[5] = “lobster”

and I can use it on client side

That’s because you’ve already set up the keys and values in that table, and again, 2 instances are created.

You’re trying to load a file serverside, which would add it into the serverside table.

Okey, thanks

[editline]31st October 2010[/editline]

New problem :S
I have send it by datastream.

Got this:

[@lua\includes\extensions able.lua:103] bad argument #1 to ‘pairs’ (table expected, got nil)

When I print the table, I see everything


Data = {}
Data.Inventory = ply.Inventory
Data.Resources = Resources.Info

datastream.StreamToClients(ply, “cucc” ,Data )

function Inventory_Setup ( cucc, id, inv, data )

Resources = {}
Inventory = {}

Resources = data.Resources
Inventory = data.Inventory


Problem is here:

for k,v in pairs(Inventory) do

[editline]31st October 2010[/editline]

Any idea?


A qualified guess says Inventory is nil (ie ply.Inventory is nil)

Did you even hook that datastream? Because you did not include that in your pasted code.

It isn’t because I can print the data table

And yeah, I have hooked it

datastream.Hook(“cucc”, Inventory_Setup)