Quote:
Originally Posted by Kindred
You must have that variable defined somewhere else in that area of the script or you have a global variable with that name.
|
He's right, but let me explain it a little better so you'll know what he means for sure.
There are a few ways you could get this error, one is this:
pawn Код:
new idx = 0;
ThisCouldBeAnyFunction(functionparameter)
{
for(new idx = 0; idx < MAX_DOORS; idx++)
{
// It will give that warning because "idx" is already defined as global variable ( A variable which isn't created in any function. )
}
return 1;
}
And this is the 2nd one:
pawn Код:
ThisCouldBeAnyFunction(functionparameter)
{
new idx = 0;
/*
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.
loads of code, but all in the same function.*/
for(new idx = 0; idx < MAX_DOORS; idx++)
{
// It will give that warning because "idx" is already defined as local variable ( A variable which is created in the same function. )
}
return 1;
}
And a little extra information;
This will also give that warning:
pawn Код:
ThisCouldBeAnyFunction(functionparameter)
{
for(new idx = 0; idx < MAX_DOORS; idx++)
{
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
}
return 1;
}
While this won't:
pawn Код:
ThisCouldBeAnyFunction(functionparameter)
{
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
for(new idx = 0; idx < MAX_DOORS; idx++)
{
break;
}
return 1;
}
Simply because in a "for" statement/loop the "new ..." variable is local to that loop, if you use the same variable in a loop/"for" statement as the variable in which the loop/"for" statement is it will also shadow it. But if you have a lot of loops under eachother like in my last example you can use the same variables as the variable is local to the loop so out of that loop the variable isn't created anymore so if you use it in the next loop it will not be shadowed. These parts are quite hard to explain, at least I don't know how to explain it better. I hope you understand haha.
Best regards,
Jesse