SA-MP Forums Archive
Sharing variables between scripts - 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 between scripts (/showthread.php?tid=284884)



Sharing variables between scripts - vivec45 - 21.09.2011

Hey,
I'm trying to script but I have a question.

Ok, say I have 2 filterscripts.
test1 and test2

test1.pwn:
new testvar = 0;

test2.pwn:
stock changevar()
{
testvar = 1;
}

changevar();
if(testvar == 1)
dothis();

I noticed if I declare variables in a .inc it can share them, but they seem to be loaded as 2 seperate instances, because if I modify the variable in 1 script it doesn't change in the other one.

Basically my question is: Is it possible to share variables between filterscripts? Like if I have an admin script and a seperate stats script, and I wanted to share the same enum for all of them. If this isn't possible, what can I do instead?

Thanks.


Re: Sharing variables between scripts - Kingunit - 21.09.2011

You cannot use the same vars as the Gamemode. You better remove the filterscript and build it inside the gamemode.


Re: Sharing variables between scripts - vivec45 - 21.09.2011

Quote:
Originally Posted by Kingunit
Посмотреть сообщение
You cannot use the same vars as the Gamemode. You better remove the filterscript and build it inside the gamemode.
These are both filterscripts, so it's not possible to share variables through all your filterscripts? Like if I want a filterscript to change a players money, and keep all the filterscripts able to read that variable too.


Re: Sharing variables between scripts - Kingunit - 21.09.2011

Quote:
Originally Posted by vivec45
Посмотреть сообщение
These are both filterscripts, so it's not possible to share variables through all your filterscripts? Like if I want a filterscript to change a players money, and keep all the filterscripts able to read that variable too.
Not really. Never found a solution. Honestly the best solution is building those filterscript in one gamemode.


Re: Sharing variables between scripts - vivec45 - 21.09.2011

Quote:
Originally Posted by Kingunit
Посмотреть сообщение
Not really. Never found a solution. Honestly the best solution is building those filterscript in one gamemode.
Okay, thanks. I understand now.

E: If I'm starting a new script, would it be better to start writing it in 0.3d scripting?


Re: Sharing variables between scripts - BloodMaster - 21.09.2011

Quote:
Originally Posted by vivec45
Посмотреть сообщение
E: If I'm starting a new script, would it be better to start writing it in 0.3d scripting?
Yes, because RC phase soon will be over, and 0.3d R1 comes


Re: Sharing variables between scripts - Amit_B - 21.09.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
For global data use properties (instead of the GVar plugin, frankly the most pointless plugin ever).
I'm really appreciate you for writing this line.