How do I do this? Check the length at compile time? -
RajatPawar - 08.03.2013
Hello ! I made a text draw system for myself, with custom stocks - CreateTextBoxForPlayer and I want to add "\n" to the given string when I want to bring the textdraw to the next line. But for that, I gotta check the strlen, which I am doing using this:
pawn Код:
stock ShowTextInfoBoxToPlayer(playerid, title[], titlecolor, string[])
{
TextDrawSetString(Textdraw1, title);
#define strl strlen(string)//Problem's here !
#if (20 > strl) //Problem's here !
strins(string, "\n", 20); //Problem's here !
#endif //Problem's here !
TextDrawColor(Textdraw1, titlecolor);
TextDrawSetString(Textdraw3, string);
TextDrawShowForPlayer(playerid, Textdraw0);
TextDrawShowForPlayer(playerid, Textdraw1);
TextDrawShowForPlayer(playerid, Textdraw2);
TextDrawShowForPlayer(playerid, Textdraw3);
return 1;
}
So whenever I remove the ""//Problem's here !"" lines, it works, but ofcourse, the string goes out of the td box I have made. Any help?
Re: How do you return IDs through stocks? -
Threshold - 08.03.2013
I think you might be looking at this the wrong way... if I'm correct, should the line be saying this:
Rather than 20 < strl ??
Also, remove all //Problem's here ! from the code if you think it might be disrupting it's effect.
Not to mention, you should change the line from \n to ~n~.
pawn Код:
strins(string, "~n~", 20);
Re: How do you return IDs through stocks? -
L.Hudson - 08.03.2013
Benzo tell me what's the difference between strl > 20 and 20 < strl... also if can't get to a solution try putting ~n~ in game in order to make a new line or sth
Re: How do you return IDs through stocks? -
Threshold - 08.03.2013
Quote:
Originally Posted by L.Hudson
Benzo tell me what's the difference between strl > 20 and 20 < strl... also if can't get to a solution try putting ~n~ in game in order to make a new line or sth
|
It was a typo... it was meant to say 20 > strl.
Re: How do you return IDs through stocks? -
RajatPawar - 08.03.2013
Oh, yes, Benzo, I tried it all, and yes, my mistake, the ~n~ should be there. I just want to make it so that it returns an error when the string is longer than 33 without a ~n~ so that the given string doesn't go out of the textdraw box.
Here's my loop:
pawn Код:
for(new s; s<strlen(string); s++)
{
if ( string[s] != '~')
{
if(string[s+1] == 'n')
{
if(string[s+2] == '~')
{
break;
}
}
}
count++;
}
#if(count > 33) #error You must use ~n~ at the 33rd character for the .. to not go outta the box
#endif
Re: How do you return IDs through stocks? -
RajatPawar - 08.03.2013
Yeah, I figured that out due to the warning I was getting! But is there any other way of doing this? One way is to have a stock for creating and another for showing, so that you can check the string. But that's where my problem is, I do not know how to go on with assigning IDs to created ''Textdraw menus'' (the FS I am creating.)
Re: How do you return IDs through stocks? -
RajatPawar - 08.03.2013
Because that will compile perfectly and send the error ingame/on it's use. I want it not to compile at all, I wanted to have a precompiler check, but I guess that's not possible !