#if directive problem -
RajatPawar - 13.03.2013
I have got this code:
pawn Код:
#define fX InfoBox[boxid][iX];
#define fY InfoBox[boxid][iY];
#if fX - fY > 71
#error BlaBla
#endif
So, it gives me the "constant" error.
Is there any way I can do this? I know the defination has to be constant, but I tried making it in different ways without any results.
It would be awesome if someone could help!
Re: #if directive problem -
Vince - 13.03.2013
Didn't you ask a similar question just a few days ago? The compiler cannot calculate the values of fX and fY because they are runtime variables. They are initialized only when the script is run. I recommend you use assert(); this evaluates the expression at runtime and will exit the server with runtime error 1 if the expression evaluates to false.
Re: #if directive problem -
RajatPawar - 13.03.2013
Quote:
Originally Posted by Vince
Didn't you ask a similar question just a few days ago? The compiler cannot calculate the values of fX and fY because they are runtime variables. They are initialized only when the script is run. I recommend you use assert(); this evaluates the expression at runtime and will exit the server with runtime error 1 if the expression evaluates to false.
|
Oh yes, I did, but this is a different one (not quite, actually)
Anyways, I tried what you said:
pawn Код:
new fX = InfoBox[boxid][iX];
new fY = InfoBox[boxid][iY];
new s = fX - fY;
#assert s < 71
Gives me an error even if I equated fX = 240 and fY = 220.
Re: #if directive problem -
Vince - 13.03.2013
I said assert() as in statement, not #assert as a directive.
Re: #if directive problem -
RajatPawar - 13.03.2013
Quote:
Originally Posted by ******
Just use "if" instead of "#if" (and don't use "assert").
|
Nah, wanted to give a compiler error or run time error.. I'll check out assert();
Re: #if directive problem -
LarzI - 13.03.2013
Compiler error is impossible if the value is set after compiling, obviously. This is why it won't work with
#if #error #endif. The assert function is a "solution", although I don't see why you don't just use normal prints instead to "simulate" an error, as assert won't tell you anything else but "Assertion failed".
Re: #if directive problem -
RajatPawar - 13.03.2013
Well, since there's no other option.. Basically, it's this textdraw string I don't want a scripter to exceed by 33 characters which I need to check. I tried inserting the newline character after the 33rd character, but it messed up the if the scripter had used it before the 33rd character. I guess I'll use a loop like:
pawn Код:
for ( new i; .. ) { if(strfind ( string.. '~' && ch[i+1] == n && ch [i+2] == '~') break, else strins ( deststr, ''~n~'', 33)
It's a typing problem here, so try to understand what I am conveying ! This should work, yes?
Re: #if directive problem -
RajatPawar - 13.03.2013
No, that would in a way defeat the purpose of my FS ! It's a textdraw menu FS, so menu options can vary from '1. Buy happiness' to '1. Buy prosperity along with happiness.' !
Re: #if directive problem -
RajatPawar - 13.03.2013
Okay ! This is what I am gonna do:
pawn Код:
function CreateMyInfoBox(string[])
{
..
}
function ShowInfoBoxToPlayer ( playerid, box )
{
if(strfind( box_enum[box][boxstring], "~n~" ) > 33 )
{
strins( box_enum[box][boxstring], "~n~", 30 );
}
}
So you are saying I could do something like this?