View Full Version : Globals?
Marine
07-25-2007, 12:21 PM
Hey,
I was wondering if it is possible to add a variable to gpGlobals, Or how to declare a global variable so it is fully accessible server side.
Cheers
Paul|zero
07-25-2007, 05:27 PM
Add to dlls/cbase.h (or in a globals.h that you #include in dlls/cbase.h):
extern int g_iMyGlobal;
That's a declaration. Code that references g_iMyGlobal will compile, but at link time it will fail if you don't define g_iMyGlobal, which you can do in any .cpp that's compiled in the server project (the linker will find it and sort things out for you):
int m_iMyGlobal;
This method protects you from defining the variable multiple times, and provides the global visibility you want.
Marine
07-26-2007, 02:51 AM
Awesome, cheers Paul :)
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.