need help with #error -
System64 - 04.11.2011
Hi guys
I have a small problem again, so basicly I made a function with slot balbalbal maximum slot is 3 and I want to make if user put slot on 4 or -1 or smaller he get error in pawn complier but I always get an error
pawn Код:
stock IsHouseWeaponSlotFree(houseid, slot)
{
if(slot >= 4)
{
#error weapon slot can be beetwen 0 and 3!
return 0;
}
switch(slot)
{
case 1:
{
if(HouseInfo[houseid][hWeaponID1] < 1) return 1;
else return 0;
}
case 2:
{
if(HouseInfo[houseid][hWeaponID2] < 1) return 1;
else return 0;
}
case 3:
{
if(HouseInfo[houseid][hWeaponID3] < 1) return 1;
else return 0;
}
}
return slot;
}
//test command
YCMD:htest(playerid, params[], help)
{
#pragma unused help
new houseid1, dure[128];
if(sscanf(params, "i", houseid1)) return SendClientMessage(playerid, -1, "Usage: /hprice [House ID]");
/*format(dure, sizeof(dure), "Weapon ID of house ID %d is %d", houseid1, GetHouseWeaponID2Ammo(houseid1));
SendClientMessage(playerid, COLOR_ORANGE, dure);*/
if(IsHouseWeaponSlotFree(houseid1, 2)) return SendClientMessage(playerid, -1, "House slot is free!");
else SendClientMessage(playerid, -1, "House slot is not free!");
return 1;
}
Re: need help with #error -
Simon - 04.11.2011
#error is a pre-processor directive. It works with the pre-processor and is stripped out at run-time i.e. it's not compiled into your code.
If you want to use #error with a condition then you'll have to use #if, which again is done at compiling time (not while the gamemode is running). An example of using #error with conditions is to do the following:
pawn Код:
#define MY_THING true
#if MY_THING == true
#error Yar, MY_THING be true.
#endif
Not extremely useful. It's perhaps more of a tool for library writers (when there's invalid combinations of #defines)
Re: need help with #error -
System64 - 04.11.2011
oh thanks, simone, I got an error, I don't understand why
pawn Код:
#if slot >= 4 //this line
#error weapon slot can be beetwen 0 and 3!
#endif
D:\A lot of shit\iStunt\pawno\include\SSR\S32_House.inc(275) : error 008: must be a constant expression; assumed zero
Re: need help with #error -
Simon - 04.11.2011
Quote:
Originally Posted by System64
oh thanks, simone, I got an error, I don't understand why
pawn Код:
#if slot >= 4 //this line #error weapon slot can be beetwen 0 and 3! #endif
D:\A lot of shit\iStunt\pawno\include\SSR\S32_House.inc(275) : error 008: must be a constant expression; assumed zero
|
The variable "slot" is not a constant. It's not possible for the compiler to know what its value is when you compile your script.
Re: need help with #error -
Calgon - 04.11.2011
'slot' is a dynamic number variable, you can't use #if with them, you can only use #if with constants.
What ****** and Simon are trying to say is that #error is not the appropriate prompt here, a client message or maybe a print() could be. #error is only to bring up errors in the compiler when required, not for errors in the client, for example when someone tries to load a weapon in to a slot that doesn't exist.
In short:
Quote:
Originally Posted by EvgeN 1137
"slot" is not define
|
Sorry for jumping in, may seem rude.
Re: need help with #error -
EvgeN 1137 - 04.11.2011
"slot" is not define
Re: need help with #error -
System64 - 04.11.2011
oaky than, thanks guys!