Invalid Function or Declaration - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Invalid Function or Declaration (
/showthread.php?tid=230250)
Invalid Function or Declaration -
Th3Angel - 23.02.2011
I'm trying my hands on a anti-weapon hack system and I'm getting this nasty error I can't seem to fix. I know there's an unmatched closing brace somewhere, but my eyes can't seem to find it... -.- Maybe someone else can spot it.
pawn Код:
(2161): error 010: invalid function or declaration
Re: Invalid Function or Declaration -
THE_KNOWN - 23.02.2011
erm i dont know it it will work but i just replaced the switch(weapon) to if(weapon) and it compiled without errors =P
give it a try.(my first try to solve =P)and its not a missing brace
Re: Invalid Function or Declaration -
Th3Angel - 23.02.2011
Quote:
Originally Posted by THE_KNOWN
erm i dont know it it will work but i just replaced the switch(weapon) to if(weapon) and it compiled without errors =P
give it a try.(my first try to solve =P)and its not a missing brace
|
It compiled without errors because it has the "stock" initialiser. So the compiler just skips that area of code unless it is used. And a switch is far more efficient than an if, else if structure.
Re: Invalid Function or Declaration -
THE_KNOWN - 23.02.2011
but i dont get it it had a stock tag b4 too. so all i did was replace the word "swtch" with "if". so if it doesnt check the code how did the error dissappear. just give it a try
Re: Invalid Function or Declaration -
(SF)Noobanatior - 23.02.2011
what is line 2160-2162?
Re: Invalid Function or Declaration -
Th3Angel - 23.02.2011
Quote:
Originally Posted by THE_KNOWN
but i dont get it it had a stock tag b4 too. so all i did was replace the word "swtch" with "if". so if it doesnt check the code how did the error dissappear. just give it a try
|
Quote:
Originally Posted by SA-MP Wiki
stock is used to declare variables and functions which may not be used but which you don't want to generate unused warnings for.
|
Basically its saying that if you don't use the function with the stock initialiser, the compiler won't generate warnings or errors for it so it "skips" over the code.
Re: Invalid Function or Declaration -
Th3Angel - 23.02.2011
Quote:
Originally Posted by (SF)Noobanatior
what is line 2160-2162?
|
Line 2161 is commented on stock SetPlayerAmmoEx
Re: Invalid Function or Declaration -
THE_KNOWN - 23.02.2011
Quote:
Originally Posted by Th3Angel
Basically its saying that if you don't use the function with the stock initialiser, the compiler won't generate warnings or errors.
|
well i feel its only stating abt the declaration of vars.
Why dont you just try you gm replacing it -.- im eagry for the results ;(
Re: Invalid Function or Declaration -
Th3Angel - 23.02.2011
Quote:
Originally Posted by THE_KNOWN
well i feel its only stating abt the declaration of vars.
Why dont you just try you gm replacing it -.- im eagry for the results ;(
|
Its not going to work... Because if you just replaced the switch with if, there's still part of the switch structure. And if I changed it to and if, else if structure, there's no point because they're really both the same thing...
Re: Invalid Function or Declaration -
[WF]Demon - 23.02.2011
pawn Код:
stock SetPlayerAmmoEx(playerid, weapon, ammo) //Line 2161
{
new slot;
switch(weapon)
{
case 0..1: slot = 0;
case 2..9: slot = 1;
case 22..24: slot = 2;
case 25..27: slot = 3;
case 28..29: slot = 4;
case 30..31: slot = 5;
case 33..34: slot = 6;
case 35..38: slot = 7;
case 16..18, 39: slot = 8;
case 41..43: slot = 9;
case 11..15: slot = 10; // YOU MISSED THE =
case 44..46: slot = 11;
case 40: slot = 12;
}
pAmmo[playerid][slot] = ammo;
SetPlayerAmmo(playerid, weapon, ammo);
}