Using self.Trololo from shared.lua in cl_init.lua

I need to use some data from shared.lua file of my swep soted is self. table, but client and server has different entity tables.

I tried to create a local variable in shared and then use it in cl_init, but that didn’t work.

Can anyone give an me an idea how to transfer data from shared to client, please.

I know thah some people asked questions like this, but I didn’t find the answer. And sorry for my English if something is wrong.

Thanks in advance.

The idea of shared data, is that it is the same on the client as it is on the server (that is at initialization).
If you want to access a variable on the client that was declared in a shared file, simply make it global (don’t make it local).

An example:

[lua]-- shared.lua
myVariable = 1234

– cl_init.lua

– init.lua
include(“shared.lua”) – not even necessary in this example, but added to show the idea of shared content files

I’ve already tried that yesterday but got nil on client.

Active 	= self.Active

surface.DrawText("Active: " .. tostring(Active))

If i print the var in server’s console, it return true, on client it is nil.

Because you’re probably setting the Variable serverside.

Even if the variable is shared, you can only access it on the state it is set in.

If you want it accessible from client and server you will have to set it shared.

– shared.lua
myNum = 14

– Server
myNum = 22
print(myNum) – Will print, 22

– Client
print(myNum) – Will print, 14

– Shared
myNum = 200
– Now the CLIENT and the SERVER will both print 200 because they both have access to the new variable setting.

Hope that explains it.

Use NWVar’s for what you’re trying to achieve.



Understood :smiley:
Bigga thanks to you all.