SA-MP Forums Archive
Trouble with Global Values - 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: Trouble with Global Values (/showthread.php?tid=282295)



Trouble with Global Values - henry jiggy - 10.09.2011

So, i have this global value outside all functions to make it a global one

Code:
new carguyid;
And some codes to get the carguy's position and set players positions to there when they spawn:

Code:
if (GetPlayerTeam(playerid) == 2)
	{
		new Float:x;
		new Float:y;
		new Float:z;
	    GetPlayerPos(carguyid,x,y,z);
	    SetPlayerPos(playerid,x,y,z + 100);
		SendClientMessage(playerid,COLOR_WHITE,"You are now skidiving over the Carguy, do /Getcar when you want your vehicle!");
	}
Which are fine. I also have a code to set the value of that global var so my server works propperly:

Code:
if (GetPlayerTeam(playerid) == 1)
	{
	    new carguyid = playerid;
               .....................
But pawno gives me these warnings:

Code:
C:\Users\Henrique\Desktop\SAMP - The Project\Dir\gamemodes\Carguy.pwn(204) : warning 219: local variable "carguyid" shadows a variable at a preceding level
C:\Users\Henrique\Desktop\SAMP - The Project\Dir\gamemodes\Carguy.pwn(204) : warning 204: symbol is assigned a value that is never used: "carguyid"
Problem: I dont want the carguyid to be a local var when i do "new carguyid = playerid", i want it to set the value of the global var i created back there to the playerid value.

So... little help here?


Re: Trouble with Global Values - Vince - 10.09.2011

Remove the new in front of it? Or am I missing something?


Re: Trouble with Global Values - andrew4699 - 10.09.2011

Change

Code:
new carguyid = playerid;
to

Code:
carguyid = playerid;
and you have to use the carguyid variable somewhere for it to stop the second warning or add

Code:
#pragma unused carguyid
at the bottom of your script.


Re: Trouble with Global Values - Kush - 10.09.2011

Quote:
Originally Posted by andrew4699
View Post
Change

Code:
new carguyid = playerid;
to

Code:
carguyid = playerid;
and you have to use the carguyid variable somewhere for it to stop the second warning or add

Code:
#pragma unused carguyid
at the bottom of your script.
Uh, I think Vince just explained that.


Re: Trouble with Global Values - henry jiggy - 10.09.2011

Thanks all ^^ givin reps.