SA-MP Forums Archive
small warning, but how to remove it? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: small warning, but how to remove it? (/showthread.php?tid=82446)



small warning, but how to remove it? - smokey104 - 18.06.2009

Does anyone know how to remove this warning??

Код:
	
public OnPlayerText(playerid, text[])
{
if(text[0] == ';')
	{
		new string[256],name[24];
		GetPlayerName(playerid,name,24);
 		format(string, sizeof(string),"*** [TPM] %s(%d): %s", name, playerid, text[1]);
		for (new i = 0; i < MAX_PLAYERS; i++) --> This is line 9462
		{
			if(IsPlayerConnected(i))
			{
            if(gTeam[i] == gTeam[playerid])
			SendClientMessage(i, COLOR_TPM, string);
			}
		}
		return 0;
	}

  return 1;
}
This is the error

Код:
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\WorldTurfFun.pwn(9462) : warning 219: local variable "i" shadows a variable at a preceding level
Thanks for helping!!


Re: small warning, but how to remove it? - Grim_ - 18.06.2009

Search through the rest of the OnPlayerText callback for the same loop. If you don't see it, look through your script for new i; as a global variable. If so, you will have to change the variable you are using (in this case 'i') do something else, like 'j'.


Re: small warning, but how to remove it? - robanswe - 18.06.2009

Quote:
Originally Posted by smokey104
Does anyone know how to remove this warning??

Код:
	
public OnPlayerText(playerid, text[])
{
if(text[0] == ';')
	{
		new string[256],name[24];
		GetPlayerName(playerid,name,24);
 		format(string, sizeof(string),"*** [TPM] %s(%d): %s", name, playerid, text[1]);
		for (new i = 0; i < MAX_PLAYERS; i++) --> This is line 9462
		{
			if(IsPlayerConnected(i))
			{
            if(gTeam[i] == gTeam[playerid])
			SendClientMessage(i, COLOR_TPM, string);
			}
		}
		return 0;
	}

  return 1;
}
This is the error

Код:
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\WorldTurfFun.pwn(9462) : warning 219: local variable "i" shadows a variable at a preceding level
Thanks for helping!!
Try this:
Код:
public OnPlayerText(playerid, text[])
{
  if(text[0] == ';')
  {
  new string[256],name[24];
  GetPlayerName(playerid,name,24);
  format(string, sizeof(string),"*** [TPM] %s(%d): %s", name, playerid, text[1]);
  if(IsPlayerConnected(i))
  {
  if(gTeam[i] == gTeam[playerid])
  SendClientMessage(i, COLOR_TPM, string);
  }
  return 0;
  }
  return 1;
}



Re: small warning, but how to remove it? - Grim_ - 18.06.2009

All you jsut did is delete the loop, meaning it will give him errors saying there is no defined symbol of 'i' and the IsPlayerConnected(i)) and gTeam[i] functions won't work correctly.


Re: small warning, but how to remove it? - robanswe - 18.06.2009

Quote:
Originally Posted by Swift_
All you jsut did is delete the loop, meaning it will give him errors saying there is no defined symbol of 'i' and the IsPlayerConnected(i)) and gTeam[i] functions won't work correctly.
I think he already have the loop...


Re: small warning, but how to remove it? - Grim_ - 18.06.2009

It still wont' be affective unless inside the callback he wishes to use it.


Re: small warning, but how to remove it? - smokey104 - 18.06.2009

Quote:
Originally Posted by Swift_
Search through the rest of the OnPlayerText callback for the same loop. If you don't see it, look through your script for new i; as a global variable. If so, you will have to change the variable you are using (in this case 'i') do something else, like 'j'.
Thanks this worked