SA-MP Forums Archive
1 warning - 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: 1 warning (/showthread.php?tid=562064)



1 warning - Glossy42O - 06.02.2015

for(new i = 0; i <= i; i++)

warning 219: local variable "i" shadows a variable at a preceding level


Re: 1 warning - Luis- - 06.02.2015

You're already using the variable "i" in the same code.

Try this;

pawn Код:
for(new j = 0 j <= j; j++)
Whatever is in the loop you'll need to change them to "j" as well.


Re: 1 warning - Glossy42O - 06.02.2015

C:\Users\sss\Desktop\Scripting tests\filterscripts\AntiCheat.pwn(276) : warning 219: local variable "j" shadows a variable at a preceding level
C:\Users\sss\Desktop\Scripting tests\filterscripts\AntiCheat.pwn(276) : error 001: expected token: ";", but found "-identifier-"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.


PHP код:
       for(new 0 j <= jj++) // <<<<<<<<<<<
       
{
            
GetPlayerWeaponData(playeridjweapons[j][0], weapons[j][1]);
       } 



Re: 1 warning - Luis- - 06.02.2015

Ah, sorry!
pawn Код:
for(new j = 0; j <= j; j++)
Also, it seems you're using "j" for something else as well.


Re: 1 warning - HazardouS - 06.02.2015

Dude, stop comparing the same variable with itself, it's really annoying. I thought you got it from the last topic. By the way, your mistake here is that you forgot another ';' after "j = 0". Here:
pawn Код:
for(new j = 0; j <= 12; j++) // j <= j means infinite loop, that's why i changed it into j <= 12 since there are only 12 weapon slots
       {
            GetPlayerWeaponData(playerid, j, weapons[j][0], weapons[j][1]);
       }
You know what that "for" loop says? It's something like this:
Код:
- Hey, let's set j to 0.
- Is j less or equal to j? Well, yes it is, because 0 is less or equal to 0. Good, then call GetPlayerWeaponData.
- We called GetPlayerWeaponData, now let's increase j by 1. j is 1 now.
- Is j less or equal to j? Well, yes it is, because 1 is less or equal to 1. Good, then call GetPlayerWeaponData.
- We called GetPlayerWeaponData, now let's increase j by 1. j is 2 now.
[...] TO INFINITY AND BEYOND. Never do this, you'll crash your server due to a huge CPU consumption.



Re: 1 warning - Glossy42O - 06.02.2015

local variable "j" shadows a variable at a preceding level


Re: 1 warning - Luis- - 06.02.2015

Where are you using the code? Cause that warning means the variable "j" is being used somewhere else in the same code.


Re: 1 warning - HazardouS - 06.02.2015

Quote:
Originally Posted by Stuun23
Посмотреть сообщение
local variable "j" shadows a variable at a preceding level
Ok, do this:
pawn Код:
for(new qzh = 0; qzh <= 12; qzh ++) // j <= j means infinite loop, that's why i changed it into qzh <= 12 since there are only 12 weapon slots
{
    GetPlayerWeaponData(playerid, qzh, weapons[qzh][0], weapons[qzh][1]);
}
I'm pretty sure you don't have any qzh variable.


Re: 1 warning - Glossy42O - 06.02.2015

fixed, thanks