Loop to include client side files

Hi All,

EDIT: My file structure is:

addon_name
– lua
– -- autorun
– -- – server
– -- – -- sv_base.lua
– -- – client
– -- – -- cl_base.lua
– -- – sh_base.lua
– -- modules
– -- – modulename
– -- – -- sv_modulename.lua
– -- – -- cl_modulename.lua
– -- – -- sh_modulename.lua

I have this server-side:



function SGN.LoadModules()
	local files, folders = file.Find( "modules/*", "LUA" )

	for _, folder in pairs(folders) do

		local files, folders = file.Find( "modules/" .. folder .. "/lua/*", "LUA" )
		local modulePath = ( "../../modules/" .. folder .. "/lua/" )

		for _, file in pairs(files) do

			if string.StartWith( file, "sh_" ) then
				include( modulePath .. file )
				AddCSLuaFile( modulePath .. file )
			end		

			if string.StartWith( file, "sv_" ) then
				include( modulePath .. file )
			end

			if string.StartWith( file, "cl_" ) then
				AddCSLuaFile( modulePath .. file )
			end

		end
		
	end

	print( ModuleTitle .. " has loaded successfully." )

end


All the server side files get included fine and work, my issue is when it comes to client-side: How do I use a similar loop to include the SH and CL files which are sent using AddCSLuaFile

I have this in cl_init.lua in my autorun/client file:



function SGN.LoadModules()
	local files, folders = file.Find( "modules/*", "LUA" )

	for _, folder in pairs(folders) do
		print(folder)
		local files, folders = file.Find( "modules/" .. folder .. "/lua/*", "LUA" )
		local modulePath = ( "../../modules/" .. folder .. "/lua/" )

		for _, file in pairs(files) do
			print(file)
			if string.StartWith( file, "sh_" ) then
				include( modulePath .. file )
			end		

			if string.StartWith( file, "cl_" ) then
				include( modulePath .. file )
			end

		end
	print("Modules Loaded")		
	end
end


Which I believe you should be able to do, but I can’t find where they are to include them? If that makes sense.

Thanks.

You don’t use AddCSLua on the client like that, just use include.

FFS, I know that :stuck_out_tongue: How did I not spot that myself… that might be the reason - however it also seemed like the sh_ files weren’t being included either. Let me test.

[editline]31st January 2016[/editline]

But either way - when you use AddCSLuaFile where do they go? Where do I need to start the loop?