How to use include

I’ve never really messed around with this before, so just a few questions,

When using include in your gamemode do you want to include your serverside files in init.lua?

Do you include client files in cl_init?

Do you put any includes in shared? Where do you include your shared files?

i bet i will feel stupid when someone tells me the answer
rate me boxes

I might be wrong so someone correct me in that case.

In your gamemode there are 2 files that are automatically read. The server instance will read init.lua and the clientside instant will read cl_init.lua

Execution will stop there unless you also include other files in these. When you include a file the contents of that file is executed before the code continues reading the first file. You can very easily have a file that includes a file that includes another, but most of the time it’s simpler to have it all in one place. Shared.lua is just the name commonly used for code you want both instances to execute, so it should be included in both init.lua and cl_init.lua. Then any file you need to use in both instances should be included from shared.lua.

I hope some of that made sense and helped you.

init.lua
[lua]
include( ‘shared.lua’ )
include( ‘classes.lua’ )
[/lua]
cl_init.lua
[lua]
include( ‘shared.lua’ )
include( ‘cl_classes.lua’ )
include( ‘nightvision.lua’ )
[/lua]

The files I have in my gamemode are as follows;
Server;
init.lua
classes.lua
Client;
cl_init.lua
cl_classes.lua
nightvision

When I try to run it though, classes.lua isn’t getting ran and I don’t know why.

It probably contains an error. You should always be watching your console for them. Try placing print() at strategic locations (such as the first line of classes.lua) to debug.