warning 219: local variable
#1

pawn Код:
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):
pawn Код:
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;
}
Reply
#2

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).
Reply
#3

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)