• Using the Net library to call a function from a 3D2D button from one file in another
    2 replies, posted
So, for the past 2 days I have been trying to get a button (made in cl_init.lua) to run a function (which is in init.lua). The button is fine and it works because I can test it with a print command. I have boiled it down to using the Net library (which is new to me). What I have tried to do is this: (This is the button in the cl_init.lua) [CODE] if (player:KeyDown(IN_USE)) then --This will just change to color of the button when pressed surface.SetDrawColor(0, 0, 0, 240) net.Receive("collect") end [/CODE] This is the other stuff (function, other Net stuff in the init.lua) [CODE] util.AddNetworkString("collect") net.Start("collect", collectBtn) net.SendToServer() function collectBtn() print("test") end [/CODE] This is what I have tried, have I got the Start and the Receive the wrong way round, I did try it the other way. Also, with this I get no errors, nothing happens and no errors show. Is it something to do with the function or what?! I appreciate any help.
[QUOTE=Bittenfleax;48379411]So, for the past 2 days I have been trying to get a button (made in cl_init.lua) to run a function (which is in init.lua). The button is fine and it works because I can test it with a print command. I have boiled it down to using the Net library (which is new to me). What I have tried to do is this: (This is the button in the cl_init.lua) [CODE] if (player:KeyDown(IN_USE)) then --This will just change to color of the button when pressed surface.SetDrawColor(0, 0, 0, 240) net.Receive("collect") end [/CODE] This is the other stuff (function, other Net stuff in the init.lua) [CODE] util.AddNetworkString("collect") net.Start("collect", collectBtn) net.SendToServer() function collectBtn() print("test") end [/CODE] This is what I have tried, have I got the Start and the Receive the wrong way round, I did try it the other way. Also, with this I get no errors, nothing happens and no errors show. Is it something to do with the function or what?! I appreciate any help.[/QUOTE] What you need to do: [code] -- cl_init: if (player:KeyDown(IN_USE)) then --This will just change to color of the button when pressed surface.SetDrawColor(0, 0, 0, 240) net.Start("Collect") net.SendToServer() end [/code] [code] --init.lua: util.AddNetworkString("Collect") function collectBtn() print("test") end net.Receive("Collect",collectBtn) [/code]
[QUOTE=Kevlon;48379458]What you need to do: [code] -- cl_init: if (player:KeyDown(IN_USE)) then --This will just change to color of the button when pressed surface.SetDrawColor(0, 0, 0, 240) net.Start("Collect") net.SendToServer() end [/code] [code] --init.lua: util.AddNetworkString("Collect") function collectBtn() print("test") end net.Receive("Collect",collectBtn) [/code][/QUOTE] Ahh thanks for that, I will try later and get back to you if it works. Thanks!
Sorry, you need to Log In to post a reply to this thread.