PDA

View Full Version : warning 219: local variable


Barnwell
07/07/2017, 04:01 AM
wcrp\utils.pwn(1017) : warning 219: local variable "vid" shadows a variable at a preceding level

How to fix this

Here is the line of utils problem (VID):
forward TPEntireCar(vid,interior,vw);// for setting players vw, and interior.
public TPEntireCar(vid,interior,vw) {
LinkVehicleToInterior(vid,interior);
SetVehicleVirtualWorld(vid,vw);
foreach(Player, i) {
if(IsPlayerConnected(i)) {
if(GetPlayerVehicleID(i)==vid) {
SetPlayerVirtualWorld(i,vw);
SetPlayerInterior(i,interior);
}
}
}
return 1;
}

NaS
07/07/2017, 06:49 AM
There's already a variable with the name "vid" defined (probably global).

Actually this is not a problem, and everything will work fine (the global variable will be shadowed, as the warning suggests, and the local one will be used until the function ends). The only consequence is that the global variable is unaccessible in this function.

To resolve the warning, you can change "vid" of the function to something else, or change the global variable (which I would recommend, since "vid" is a too generic name for a global variable).

Freedom.
07/07/2017, 09:18 AM
Do not use IsPlayerConnected when you are using foreach.

forward TPEntireCar(veh_id, interior, vw);// for setting players vw, and interior.
public TPEntireCar(veh_id, interior, vw)
{
LinkVehicleToInterior(vid, interior);
SetVehicleVirtualWorld(vid, vw);
foreach(Player, i)
{
if(GetPlayerVehicleID(i)==vid)
{
SetPlayerVirtualWorld(i, vw);
SetPlayerInterior(i, interior);
}
}
return 1;
}