• Making network functions in shared lua file?
    2 replies, posted
I don't know if this will work: [LUA] util.AddNetworkString("playerNotifyAll") util.AddNetworkString("playerNotify") function postPlayerNotificationAll( message ) net.Start("playerNotifyAll") net.WriteString(message) net.Broadcast() end function postPlayerNotification( ply, message ) net.Start("playerNotify") net.WriteString(message) net.Send(ply) end [/LUA] Basically this is in my shared.lua file for my gamemode, and I want to be able to call one of these two functions from any of the server-side files that include shared.lua. But I don't know if you can add functions in the shared file, and then call them from another file directly. This is just to make my life easier. But will it work? I am not in a position were I can test in in-game. I can only code it... - silly me. Any help is appriciated :D - Fillipuster
[QUOTE=Fillipuster;45570292]from any of the server-side files that include shared.lua.[/QUOTE] This is not how GLua works. The term "to include" in, GLua refers, to executing a file. Said file can then, for example, contribute to the global scope of any instance of Lua (such as declaring a global function, which is what you're trying to do). It is [I]not[/I] like C/C++ where if you include a header, its prototypes are only valid within the compilation unit of the file that included said header. What it seems to me that you're trying to do makes no sense in a clientside environment, so I don't get why you insist on running it in a shared environment (shared meaning that it is run on both the server and the client). You should move it to a file that's only included on the server.
Thanks a lot, this did the trick for me ;) I am adding it to shared because I want all the serverside files to be able to access the global function. I know I could make a sv_globalfunctions.lua and place them there, followed by me including the file in all the other server-side files. But I want to keep the file-count to a minimum for this one. Thanks alot :D + rep, or whatever you call it xD - Fillipuster
Sorry, you need to Log In to post a reply to this thread.