local variable "idx" shadows a variable at a preceding level -
Stanford - 25.05.2013
pawn Код:
D:\STRUCTURE\TEST(38527) : warning 219: local variable "idx" shadows a variable at a preceding level
D:\STRUCTURE\TEST(39132) : warning 219: local variable "idx" shadows a variable at a preceding level
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
2 Warnings.
Lines:
38527:
pawn Код:
for(new idx=0; idx<MAX_DOORS; idx++) // Dynamic Doors
39132:
pawn Код:
for(new idx=0; idx<MAX_DOORS; idx++) // Dynamic Doors
Alright a guy told me that I need to change the idx to something else, I changed it to idxB and it compiled well, but when I wanted to enter the dynamicdoors it didn't enter, here's the load of it:
pawn Код:
stock LoadDoors()
{
new dinfo[16][128];
new string[256];
new File:file = fopen("doors.cfg", io_read);
if(file)
{
new idx = 0;
while(idx < MAX_DOORS)
{
fread(file, string);
split(string, dinfo, '|');
DoorInfo[idx][dType] = strval(dinfo[0]);
DoorInfo[idx][dOX] = floatstr(dinfo[1]);
DoorInfo[idx][dOY] = floatstr(dinfo[2]);
DoorInfo[idx][dOZ] = floatstr(dinfo[3]);
DoorInfo[idx][dIX] = floatstr(dinfo[4]);
DoorInfo[idx][dIY] = floatstr(dinfo[5]);
DoorInfo[idx][dIZ] = floatstr(dinfo[6]);
DoorInfo[idx][dOInt] = strval(dinfo[7]);
DoorInfo[idx][dOVW] = strval(dinfo[8]);
DoorInfo[idx][dIInt] = strval(dinfo[9]);
DoorInfo[idx][dIVW] = strval(dinfo[10]);
DoorInfo[idx][dCInt] = strval(dinfo[11]);
DoorInfo[idx][dCExt] = strval(dinfo[12]);
DoorInfo[idx][dIA] = floatstr(dinfo[13]);
format(DoorInfo[idx][dText], 128, "%s", dinfo[14]);
DoorInfo[idx][dOA] = floatstr(dinfo[15]);
if(DoorInfo[idx][dType]) // If door exists
{
DoorInfo[idx][dPickup] = CreateDynamicPickup(DoorInfo[idx][dType], 1, DoorInfo[idx][dOX], DoorInfo[idx][dOY], DoorInfo[idx][dOZ], DoorInfo[idx][dOVW], DoorInfo[idx][dOInt]);
format(string, sizeof(string), "ID: %d\n%s", idx, DoorInfo[idx][dText]);
DoorInfo[idx][dTextID] = CreateDynamic3DTextLabel(string, COLOR_DCHAT, DoorInfo[idx][dOX], DoorInfo[idx][dOY], DoorInfo[idx][dOZ]+0.3, 15);
}
idx++;
}
}
print("~~~~");
return 1;
}
Save:
pawn Код:
stock SaveDoors()
{
new idx = 0, File:file;
new string[256];
while(idx < MAX_DOORS)
{
format(string, sizeof(string), "%d|%f|%f|%f|%f|%f|%f|%d|%d|%d|%d|%d|%d|%f|%s|%f\r\n",
DoorInfo[idx][dType],
DoorInfo[idx][dOX],
DoorInfo[idx][dOY],
DoorInfo[idx][dOZ],
DoorInfo[idx][dIX],
DoorInfo[idx][dIY],
DoorInfo[idx][dIZ],
DoorInfo[idx][dOInt],
DoorInfo[idx][dOVW],
DoorInfo[idx][dIInt],
DoorInfo[idx][dIVW],
DoorInfo[idx][dCInt],
DoorInfo[idx][dCExt],
DoorInfo[idx][dIA],
DoorInfo[idx][dText],
DoorInfo[idx][dOA]);
if(idx == 0)
{
file = fopen("doors.cfg", io_write);
}
else
{
file = fopen("doors.cfg", io_append);
}
fwrite(file, string);
fclose(file);
idx++;
}
print("~~~~.");
}
Can someone tell me what to do? and post the new code?
Re: local variable "idx" shadows a variable at a preceding level -
TheArcher - 25.05.2013
Because you've put the variable "idx" twice.
A classic example that you can't do is
main() { new idx; new idx; }
makes no sense. :S
Re: local variable "idx" shadows a variable at a preceding level -
Vince - 25.05.2013
It's perfectly feasible to use the same variable name in two different functions. Those warnings mean that idx is defined on a higher level, probably global.