I made a net wrapper!

Woo, haha I was just wondering if I could get some critiquing or advice? I feel like I accomplished something but at the same time I don’t

Right now it mostly just shortens up using net messages, and it also allows me to send different messages to the same network. This should help with custom mods that need to set up multiple networks for various things.
[lua]
Net_Wrapper = {}
Net_Wrapper.Bridges = {}

function NetWrapper()
return Net_Wrapper
end

function Net_Wrapper:AddNetBridge( String )
if SERVER then
util.AddNetworkString( String )
elseif CLIENT then
net.Receive( String, function( len )
Net_Wrapper.Bridgesnet.ReadFloat()
end )
end
end

if SERVER then
function Net_Wrapper:SendData( pl, Bridge, Connection, NetFunctions )
net.Start( Bridge )
net.WriteFloat( Connection )
NetFunctions()
net.Send( pl )
end
elseif CLIENT then
function Net_Wrapper:GetData( Bridge, Connection, Functions )
Net_Wrapper.Bridges[Connection] = Functions
end
end
[/lua]

I was also trying to make this apart of the GAMEMODE table if that makes things any better, and if it does maybe someone can show me how that’s done.

Usage
shared.lua
[lua]
NetWrapper():AddNetBridge( “Net_Coins” )
[/lua]

init.lua
[lua]
function PLAYER:SetCoins( Int )
self.Coins = Int
NetWrapper():SendData( self, “Net_Coins”, 1, function()
net.WriteFloat( Int )
end )
end
[/lua]

cl_int.lua
[lua]
NetWrapper():GetData( “Net_Coins”, 1, function()
LocalPlayer().Coins = net.ReadFloat()
end )
[/lua]

I don’t get the purpose

Why is NetWrapper a function?

SHUT UP I’M EXPERIMENTING!.. I don’t know… but I feel like the net messages can be wrapped up in a more simple and easy to use way than they are now. What I like though is that I don’t have to write:
[lua]

net.Start( “String_Shit” )
net.WriteFloat( 50 )
net.Send( pl ) [/lua]

And not only that, but I only have to change one variable to use the same networked connection. Such as:

Instead of this:
[lua]

net.Start( “Net_SetCoins” )
net.WriteFloat( 50 )
net.Send( pl )

net.Start( “Net_Coins_OpenMenu” )
–Open some coins related menu.
net.Send( pl ) [/lua]

See now these two different networks would either set the players cash an send it to the client. Orr have something happen on the server, then send a message to the client to open a certain menu. Instead of creating different networks to use “Net_SetCoins” and “Net_Coins_OpenMenu” I can just use the wrapper thingy I made to open one network, then differentiate from the separate connections. Such as:

[lua] NetWrapper():AddString( “Net_Coins_Mod” )

NetWrapper():SendData( pl, “Net_Coins_Mod”, 1, function() --1 would be for connection 1 obviously.
net.WriteFloat( 50 )
end)

NetWrapper():SendData( pl, “Net_Coins_Mod”, 2, function() --2 is for connection 2.
–Open some coins related menu.
end) --they are both accessing the same networked string, “Net_Coins_Mod” but they do different things depending on the which connection they have. [/lua]

Maybe someone gets what I’m saying… Serverside it is not much work between these two ways, but clientside… Using my wrapper you only need to make one “net.Recieve()” function, not using it you would have to make one per networked message sent.

I guess what I was going for was simplicity, all you need to do is complete three different parts of code to make a reliable and convenient networked variable. And this is all for a gamemode which will probably be based on mods to give it actual gameplay, so I figured this would come in handy?

It seems pointless unless you where using a lot of net connections in a single script/gamemode, and only then would it make it some what more tidy.

That’s not very nice.

a wrapper for a wrapper.

Well, since you asked for suggestions - don’t do that.
It’s best to stick with the established routines, so either have
a) a singleton accessed like a library - see the undo module or
b) a set of isolated objects that you create an instance of with a function and then hang on to and call functions on without interfering with other instances.
You’ve got a singleton object that you access via a function and then call functions on before discarding which is more than a little bit odd.