local variable "frak" shadows a variable at a preceding level -
deathrunner - 10.07.2013
Hallo, i have a problem, and i dont know what i should do
enum frakcar
{
pd,
cobra,
army,
ira,
sc,
lcn,
suddendeath,
oeamtc,
medic,
orf,
fourseas,
yakuza
};
new Frakcar[frakcar][MAX_VEHICLES];
I define the farkcars with "Frakcar[pd][0] = CreateVehicle.." and so on
I have written a stock which should check if the player is allowed to lock the car
stock CanPlayerLockCar(vehicleid,frak)
{
new carfrakname[64];
new geht;
switch(frak)
{
case 0: {carfrakname = "zivi";}
case 1: {carfrakname = "pc";}
case 2: {carfrakname = "cobra";}
case 3: {carfrakname = "army";}
case 4: {carfrakname = "ira";}
case 5: {carfrakname = "lcn";}
case 6: {carfrakname = "sc";}
case 7: {carfrakname = "suddendeath";}
case 8: {carfrakname = "medic";}
case 9: {carfrakname = "orf";}
case 10: {carfrakname = "oeamtc";}
case 11: {carfrakname = "fourseas";}
case 12: {carfrakname = "yakuza";}
}
for(new i; i<MAX_VEHICLES;i++)
{
if(vehicleid == Frakcar[carfrakname][i])
{
geht = 1;
}
else
{
geht = 0;
}
}
return geht;
}
but der is one error in the line with "if(vehicleid == Frakcar[carfrakname][i])"
warning 219: local variable "frak" shadows a variable at a preceding level
error 033: array must be indexed (variable "carfrakname")
warning 203: symbol is never used: "frak"
pls help
Re: local variable "frak" shadows a variable at a preceding level -
dEcooR - 10.07.2013
try this
Код:
Frakcar[pd][vehicleid] = CreateVehicle...
stock CanPlayerLockCar(vehicleid,frak)
{
new carfrakname[64],geht;
switch(frak)
{
case 0: carfrakname = "zivi";
case 1: carfrakname = "pc";
case 2: carfrakname = "cobra";
case 3: carfrakname = "army";
case 4: carfrakname = "ira";
case 5: carfrakname = "lcn";
case 6: carfrakname = "sc";
case 7: carfrakname = "suddendeath";
case 8: carfrakname = "medic";
case 9: carfrakname = "orf";
case 10 carfrakname = "oeamtc";
case 11: carfrakname = "fourseas";
case 12: carfrakname = "yakuza";
}
for(new i; i<MAX_VEHICLES;i++)
{
if(vehicleid == Frakcar[carfrakname][i]) geht = 1;
else geht = 0;
}
return carfrakname;
}
Re: local variable "frak" shadows a variable at a preceding level -
deathrunner - 10.07.2013
no doesnt work
same error
AW: local variable "frak" shadows a variable at a preceding level -
roym899 - 10.07.2013
For the warning:
make sure you don't have a global variable named frak and if so rename this or rename the local variable frak in the function. (the function paramter)
For the error:
You have to understand what enum actually does. enums aren't strings. They are more like defines where the first word gets assigned a 0 and then then the other words are getting enumerated.
For your example pd equals 0, cobra equals 1, army equals 2, ... So you can't access a certain element by using a string in the brackets.
To fix it replace
new carfrakname[64]; with
new frakcar:carfrakname;
And then instead of assigning strings like "zivi" or "pc" assign the enum values like this:
carfrakname = pc;
carfrakname = cobra;
By doing this you'll get a new error becaues zivi isn't a part of frakcar currently so you should add zivi there.
Re: local variable "frak" shadows a variable at a preceding level -
deathrunner - 10.07.2013
Code:
Код:
stock CanPlayerLockCar(vehicleid,fraktion)
{
new frakcar:carfrakname;
new geht;
switch(fraktion)
{
case 0: carfrakname = zivi;
case 1: carfrakname = pd;
case 2: carfrakname = cobra;
case 3: carfrakname = army;
case 4: carfrakname = ira;
case 5: carfrakname = lcn;
case 6: carfrakname = sc;
case 7: carfrakname = suddendeath;
case 8: carfrakname = medic;
case 9: carfrakname = orf;
case 10: carfrakname = oeamtc;
case 11: carfrakname = fourseas;
case 12: carfrakname = yakuza;
}
for(new i; i<MAX_VEHICLES;i++)
{
if(vehicleid == Frakcar[carfrakname][i])
{
geht = 1;
}
else
{
geht = 0;
}
}
return geht;
}
Errors:
error 091: ambiguous constant; tag override is required (symbol "cobra")
error 091: ambiguous constant; tag override is required (symbol "army")
error 091: ambiguous constant; tag override is required (symbol "sc")
error 091: ambiguous constant; tag override is required (symbol "oeamtc")
error 091: ambiguous constant; tag override is required (symbol "fourseas")
AW: local variable "frak" shadows a variable at a preceding level -
roym899 - 10.07.2013
Add frakcar: before these words. Pretty strange though that it starts with cobra not pd.
Re: local variable "frak" shadows a variable at a preceding level -
deathrunner - 10.07.2013
i dont understand, sry im german.
Ok now i have it so
Код:
enum frakcar
{
zivi,
pd,
cobra,
army,
ira,
sc,
lcn,
suddendeath,
oeamtc,
medic,
orf,
fourseas,
yakuza
};
new Frakcar[frakcar][MAX_VEHICLES];
stock CanPlayerLockCar(vehicleid,fraktion)
{
new frakcar:carfrakname;
new geht;
switch(fraktion)
{
case 0: carfrakname = zivi;
case 1: carfrakname = pd;
case 2: carfrakname = cobra;
case 3: carfrakname = army;
case 4: carfrakname = ira;
case 5: carfrakname = lcn;
case 6: carfrakname = sc;
case 7: carfrakname = suddendeath;
case 8: carfrakname = medic;
case 9: carfrakname = orf;
case 10: carfrakname = oeamtc;
case 11: carfrakname = fourseas;
case 12: carfrakname = yakuza;
}
for(new i; i<MAX_VEHICLES;i++)
{
if(vehicleid == Frakcar[carfrakname][i])
{
geht = 1;
}
else
{
geht = 0;
}
}
return geht;
}
errors:
error 091: ambiguous constant; tag override is required (symbol "cobra")
error 091: ambiguous constant; tag override is required (symbol "army")
error 091: ambiguous constant; tag override is required (symbol "sc")
error 091: ambiguous constant; tag override is required (symbol "oeamtc")
error 091: ambiguous constant; tag override is required (symbol "fourseas")
Pls post what i should change, because i have no idea, what i should change
AW: local variable "frak" shadows a variable at a preceding level -
roym899 - 10.07.2013
Well I assume you have other defines called cobra army or similiar.
So you need to do it like this:
Код:
case 0: carfrakname = frakcar:zivi;
case 1: carfrakname = frakcar:pd;
case 2: carfrakname = frakcar:cobra;
case 3: carfrakname = frakcar:army;
case 4: carfrakname = frakcar:ira;
case 5: carfrakname = frakcar:lcn;
case 6: carfrakname = frakcar:sc;
case 7: carfrakname = frakcar:suddendeath;
case 8: carfrakname = frakcar:medic;
case 9: carfrakname = frakcar:orf;
case 10: carfrakname = frakcar:oeamtc;
case 11: carfrakname = frakcar:fourseas;
case 12: carfrakname = frakcar:yakuza;
Probably it's not needed everywhere but this way it's better style imho.
Re: local variable "frak" shadows a variable at a preceding level -
deathrunner - 10.07.2013
Ok now error anymore.
But wenn im in fraktion 3, i cant lock army cars
the army cars are define with
Код:
Frakcar[army][0] = AddStaticVehicleEx(520,-1691.8257,290.2983,7.9087,180.8720,0,0,-1); // Army Hydra
Код:
stock CanPlayerLockCar(vehicleid,fraktion)
{
new frakcar:carfrakname;
new geht;
switch(fraktion)
{
case 0: carfrakname = frakcar:zivi;
case 1: carfrakname = frakcar:pd;
case 2: carfrakname = frakcar:cobra;
case 3: carfrakname = frakcar:army;
case 4: carfrakname = frakcar:ira;
case 5: carfrakname = frakcar:lcn;
case 6: carfrakname = frakcar:sc;
case 7: carfrakname = frakcar:suddendeath;
case 8: carfrakname = frakcar:medic;
case 9: carfrakname = frakcar:orf;
case 10: carfrakname = frakcar:oeamtc;
case 11: carfrakname = frakcar:fourseas;
case 12: carfrakname = frakcar:yakuza;
}
for(new i; i<MAX_VEHICLES;i++)
{
if(vehicleid == Frakcar[carfrakname][i])
{
geht = 1;
}
else
{
geht = 0;
}
}
return geht;
}
COMMAND:zusperren(playerid,params[])
{
#pragma unused params
new veh = GetNearestVehicle(playerid);
if(Playerinfo[playerid][Fraktion] > 0)
{
if(CanPlayerLockCar(veh,Playerinfo[playerid][Fraktion]))
{
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(veh, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(veh, engine, lights,alarm,1,bonnet,boot,objective);
SendClientMessage(playerid, COLOR_GOLD, "Du hast das Auto abgeschlossen.");
}
else{SendClientMessage(playerid, COLOR_RED, "Du kannst dieses Auto nicht abschlieЯen");}
}
return 1;
}
pls help
//edit: Hab grade gesehen das du aus deutschland kommst kannst gerne auch deutsch antworten
AW: local variable "frak" shadows a variable at a preceding level -
roym899 - 10.07.2013
So first of all this is everything else then well scripted.
Код:
new Frakcar[frakcar][MAX_VEHICLES];
By using MAX_VEHICLES here you could have 2000 vehicles for each fraction. Which is way too much. Something like 20 would be much more fitting for your problem.
Код:
#define MAX_FRAKVEHICLES 20
new Frakcar[frakcar][MAX_FRAKVEHICLES];
Be careful that it's really important that the number is high enough to store the vehicles. (if one fraction has more vehicles then 20 just use a higher value but using MAX_VEHICLES is WAY too much)
// I forgot to mention that when you use MAX_FRAKVEHICLES you also have to it in the for loop instead of MAX_VEHICLES
Now the actual problem: Currently you don't stop after you found the right vehicleid and thus the function will always return 0. So you have to break out the function after finding the correct vehicle:
Код:
if(vehicleid == Frakcar[carfrakname][i])
{
geht = 1;
return geht;
}
else
{
geht = 0;
}
Still not very well scripted and there might be other mistakes.
btw.: ich wьrd auch auf Deutsch antworten, aber fьr andere die das dann hier im Forum lesen und ein дhnliches Problem haben kцnnten sie es nicht verstehen. Wenn du noch eine Frage hast kannst du mir per PM schreiben.