Problem with adding external files to gamemode

My external file ‘cl_connectderma.lua’ is not being found at all, I tried using a Usermessage to check if it was being loaded but it says unhanded usermessage which I can only presume that the receiving end does not exist.

Heres my setup:

init.lua:


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "modules/cl_connectderma.lua" )

include( "shared.lua" )

function InitialPlayerSetup( ply )
	ply:SetNWBool( "showRadius", false )
	timer.Create( "UniqueName1", 1, 1, function()
	umsg.Start( "MyUsermessage" );
	umsg.End();
end )
end



cl_connectderma.lua:


include( "shared.lua" ) -- I have tried removing this to see if that would fix this as the sandbox gui files do not have this but had no luck

local function RecvMyUmsg()
 
	// print something to the console
	print( "MyUsermessage was received!" );
 
end
// hook the callback function to the usermessage
// when the client receives "MyUsermessage", RecvMyUmsg will be called
usermessage.Hook( "MyUsermessage", RecvMyUmsg );

As you can see, a fairly simple function that should be called, but is unhandled.

I’d recommend using the net library instead of usermessages for something like this

[editline]16th August 2016[/editline]

You could use net messages like this:
init.lua:



AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "modules/cl_connectderma.lua" )

include( "shared.lua" )

util.AddNetworkString( "MyUsermessage" )

function InitialPlayerSetup( ply )
	ply:SetNWBool( "showRadius", false )
	timer.Create( "UniqueName1", 1, 1, function()
		net.Start( "MyUsermessage" );
		net.Send( ply );
	end )
end


cl_connectderma.lua:



local function RecvMyUmsg()
 
	// print something to the console
	print( "MyUsermessage was received!" );
 
end
// hook the callback function to the usermessage
// when the client receives "MyUsermessage", RecvMyUmsg will be called
net.Receive( "MyUsermessage", RecvMyUmsg );


Also, try doing include( “modules/cl_connectderma.lua” ) in the init file, that might be the problem

[editline]16th August 2016[/editline]

Also, did you ever call the InitialPlayerSetup function? It doesn’t look like you did from the code you posted

Yes the function is called. I missed out the hook.add in the copy. I do not believe that usermessages are the problem but i will look into the net library, thanks.

Ive tried adding something that would cause an error and the error did not come up in the console which i think means that the file is not being read.

In response to the add an include, the file i wish to create should be clientside not shared.

Okay, so I have taken your advice to include the file into the init.lua to use the file as a shared file and now the file is recognized, however I am having some trouble with the network messaging:

init.lua:


function GM:Initialize()
util.AddNetworkString("Test")
end

function InitialPlayerSetup( ply )
	ply:SetNWInt( "goldsmooth", 0 )
	ply:SetNWInt( "gold", 125 )
	ply:SetNWBool( "showRadius", false )
	
	net.Start("Test")
	net.WriteEntity( ply )
	net.Broadcast()

end

cl_connectderma.lua:


net.Receive( "Test", function()
	 local ply = net.ReadEntity()
	 ply:ChatPrint("cl_connectderma.lua works!")
end )

There is no error printed to the console however the function is not called when it should be. Any help is appreciated.

/////////////////////////////////// UPDATE ////////////////////////////////

So i was able to determine that the problem is that the net message was being sent to the client - the file that I was trying to send it to was a shared file, so I would like to go back to my initial problem

How do i make an external clientside file.

[editline]17th August 2016[/editline]

Okay, so within 3 minutes of posting this, I was able to determine the problem and the fix. I will post it here then resolve the thread for those curious, thank you for all your help:

Problem: The net.Recieve was in a serverside file which I thought was clientside/shared however I did not include(“shared.lua”) inside of the file. I tried to include it however it couldnt find the file as it was in another folder:

Solution:


include( "../shared.lua" )

net.Receive( "test", function()
	 local ply = net.ReadEntity()
	 ply:ChatPrint("cl_connectderma.lua works!")
end )

Again, thanks to all that helped.