problem with newline in textdraw
#1

hello, im confused on how make this newline work. I red on the forums the new line command is "~n~" I'm using it. yet the newline isn't working, its just changing the last string. I want to add string not change completly the last one. (trying to make news feed whenever something happens it will make newline and show the last message + new message)

Please help me figure out whats wrong.
Here is some code:
(textdraw FEED3 is the actual string which needs to be editted)
Код:
FEED3 = TextDrawCreate(407.999938, 346.785186, "%s~n~");
TextDrawLetterSize(FEED3, 0.176000, 0.977777);
TextDrawAlignment(FEED3, 1);
TextDrawColor(FEED3, 8388863);
TextDrawSetShadow(FEED3, 0);
TextDrawSetOutline(FEED3, 1);
TextDrawBackgroundColor(FEED3, 51);
TextDrawFont(FEED3, 1);
TextDrawSetProportional(FEED3, 1);
This is a string for example i want to be in the feed 3.
Код:
new bstring[128];
format(bstring,sizeof(bstring), "%s has connected. (Countery: %s)", GetName(playerid), country);
NewsFeedTextDraw(bstring);
Noting worked so i have made this stock to try another way to add the strings, yet it didn't work.
Код:
stock NewsFeedTextDraw(text[])
{
    new bigstring[1024];
    format(bigstring, sizeof(bigstring), "%s~n~", text);
    TextDrawSetString(FEED3, bigstring);
}
Okay the codes should be enough to explain how im adding new lines to the FEED3 textdraw.
In-game It will show first string, when i need another it will change the last instead of adding new line..
EDIT: It seems like it works this way "string1~n~" when new string come it will change the last string to "string2~n~" but as you can see the ~n~ isn't appliad to the new string. Why?
Reply
#2

Add ~n~ before the text/string?
Reply
#3

Quote:
Originally Posted by Darkwood17
Посмотреть сообщение
Add ~n~ before the text/string?
but then the first textdraw will be with empty space before him.. right?
I want it to be from the top to the bottem and the first string must be in the top and not one space after top..

Here is example of what i want:
Код:
Hello/n
Hello/n
Hello/n
and not
Код:
* SPACE *
/nhello
/nhello
/nhello
Even through i tried this ~n~string now and it didnt work either..
Reply
#4

fairly sure its \n like in most other languages, or even \r\n

so do this (uses \n) :
Код:
format(bstring,sizeof(bstring), "%s has connected.\n(Countery: %s)", GetName(playerid), country);
or possibly this if the first example doesnt work (uses \r\n) :
Код:
format(bstring,sizeof(bstring), "%s has connected.\r\n(Countery: %s)", GetName(playerid), country);
Reply
#5

Quote:
Originally Posted by Suicidal.Banana
Посмотреть сообщение
fairly sure its \n like in most other languages, or even \r\n

so do this (uses \n) :
Код:
format(bstring,sizeof(bstring), "%s has connected.\n(Countery: %s)", GetName(playerid), country);
or possibly this if the first example doesnt work (uses \r\n) :
Код:
format(bstring,sizeof(bstring), "%s has connected.\r\n(Countery: %s)", GetName(playerid), country);
Made this:
Код:
new bstring[128];
format(bstring,sizeof(bstring), "%s has connected. (Countery: %s)\r\n", GetName(playerid), country);
TextDrawSetString(FEED3, bstring);
And when im using this:
Код:
new string[128];
format(string,sizeof(string), "%s has been kicked. (Reason: %s)\r\n", GetName(playerid), reason);
TextDrawSetString(FEED3, string);
The second overwrites the first one. again i want it to be this way:
Код:
%s has connected. (Countery: %s)\r\n
%s has been kicked. (Reason: %s)\r\n
Reply
#6

Sorry, seems i misunderstood the question, now that i've re-read everything, what your actually looking for is a way to combine strings, correct? you'll be needing strcat for that, heres an example:

Код:
new final_string[128],
    temp_string[64];

public addToString(new_string) { // just a quicky helper function to automatically add line breaks
    if(strcmp(final_string, "") != 0) { // if the final_string is not empty
        strcat(final_string, "\n"); // add a line break! again, not sure if \n or \r\n
    }
    strcat(final_string, new_string); // now add whatever new_string we want to add
}

format(temp_string,sizeof(temp_string), "%s has connected. (Countery: %s)", GetName(playerid), country);
addToString(temp_string);

format(temp_string,sizeof(temp_string), "%s has been kicked. (Reason: %s)", GetName(playerid), reason);
addToString(temp_string);

TextDrawSetString(FEED3, final_string);
The above should get you one string (final_string) with both text's, with linebreaks between them, like so:
Код:
%s has connected. (Countery: %s)\n
%s has been kicked. (Reason: %s)
Reply
#7

Guys i think i figured it out! I should use strcat & then the 2 string will be attached thogether with \n and the second string will go to new line
Reply
#8

Correct see my last reply for an example
Reply
#9

Quote:
Originally Posted by Suicidal.Banana
Посмотреть сообщение
Correct see my last reply for an example
oh thanks for thinking about it for me, you are big rep +.
Reply
#10

always a pleasure
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)