Sharing Variables Across Includes - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Sharing Variables Across Includes (
/showthread.php?tid=351373)
Sharing Variables Across Includes -
ReneG - 15.06.2012
There was a lot of saving code cluttering my mode, so I decided I would move all code that interacts with the database into an include file.
This is at the top the of gamemode.
pawn Код:
new PlayerInfo[MAX_PLAYERS][pInfo];
I am trying to access that PlayerInfo variable in my include to save/load data. How do I do that? It was to my understanding that global variables are easily accessible throughout scripts, but my compiler whines that the variable is undefined in the include. Before you say, I have already looked at the scopes of variable, still haven't found a solution.
Re: Sharing Variables Across Includes -
FireCat - 15.06.2012
Show me what you have in that include.
Re: Sharing Variables Across Includes -
iggy1 - 16.06.2012
Simply include your file after you have declared your global variables.
pawn Код:
new somevar;
#include <yourinclude>
When you include a file, the include line is replaced by the code in the include, so if you define global variables after including then they are not in scope of the include.
Re: Sharing Variables Across Includes -
ReneG - 16.06.2012
Quote:
Originally Posted by FireCat
Show me what you have in that include.
|
It's just like over 500 lines of irrelevant SQL code.
Quote:
Originally Posted by iggy1
Simply include your file after you have declared your global variables.
pawn Код:
new somevar; #include <yourinclude>
When you include a file, the include line is replaced by the code in the include, so if you define global variables after including then they are not in scope of the include.
|
Learned something new today, thanks. It worked by the way.