Created more files for a gamemode

I am not sure what the Lua community calls them, but I will refer to them as files I guess.

I am coding a gamemode and would like to know the most efficient way to create the project. I have programming experience, but I am brand new to Lua so I thought I would get out of my usual shell and pride of not asking questions to just asking questions when I have them.

I know you need 3 basic files when created a game mode (actual Lua code files), the cl_init, init, and shared. I believe they are called. I also know you can have more files in your game mode as most game modes don’t cram everything into these 3 files.

When I create more files and add them as includes does that mean the file I included it in, I can use the functions in it? Or how does that work out? I guess what I am asking is if I have cl_init, and inside cl_init I include shared. What advantage or properties does that now give me with the 2 files?

I guess my final question for the time being would be, is it better to create specific files for different game modes systems rather than fewer files?

So say I want to create a money system within my gamemode would it be beneficial to create a new lua file to just handle the Money so as not to clutter up the rest of the project with it.

My natural instinct is telling me to create separate files for everything so it is easier to read and change specific parts, without having money and team spawning and weapons and everything crammed all next to each other.

I guess I lied, one more question! :slight_smile:

The cl_ is a client file, does Lua see file names or is this strictly for human readability? How would I know when to go about using cl_ instead of server files or shared? When do I use shared, when do I use cl_ when do I use just plain server?

I am assuming cl_ would be used to display stuff to the users, such as a HUD, and team selections and the likes, and server would be used for handling the basic workings of the game mode, such as suiting characters with equipment and having a money system. But when would I use shared opposed to just server or just cl_ ?

Thanks for the help guys.

the only files that the server auto recognizes are the init.lua cl_init.lua and shared.lua along with said same files for entities and sweps. Those are theo nly name it recognizes to the rest of the files with the name cl_ in them is soley for human purposes. If you include a file say your money example serverside you can call functions from the money file from the init.lua file. the cases where you use cl_ files (not necisarily named that) is for hud mostly and some other values that they need to know. shared is simply that shared between client and server so both client and server can access said files.

Alright, so shared would be used so that say the server could set a value and the client could modify that value based on their actions? Something like that?

So I can set up a file and put a bunch of functions in it and then include it and then just run it? Sounds good. Thanks for the help you offered.

Well yes if its shared the client cna edit the info. But you do not want to put important information in shared for the client aka money and what not because they could physically alter the value and tweek stuff they shouldn’t tweek thats the kind of info you send via datastream /usermessages and console commands.

To include a file basically means simply to run it.

A shared file is one included by both the client and server. It is run on both the client and server, but it’s not synchronized - therefore, you cannot access the data the server modifies on the client and vice versa - you must transfer that information through the use of usermessages, networked variables, console commands, and datastream.

I recommend this site for all your Gmod Lua needs: http://wiki.garrysmod.com/?title=Main_Page

Yeah I use the wiki a lot, however some of this isn’t covered.