New line in a file (with dini)
#1

Hi, I'd like to know if there's a way to put a new line in a string that is inside a file.

For example, I was trying to create a dialog with a big text, but I got an error saying that the line was too long. Then, I put this same text in a file and it worked:

This way:
Код:
ShowPlayerDialog(playerid, 2, 0, "Title:", dini_Get("File.ini", "F_1"), "Ok", "Back");
But, this:
Код:
\n\r
doesn't have any effect. The text keeps in the same line.

Does anyone know the solution for this? Thanks!

P.S.: sorry about my english...
Reply
#2

Just use \n if you're putting it into a dialog.
Reply
#3

Tryed both ways: \n and \n\r. And the texts looks like this: blablablabla\n\rblablabla.
I'd like it was:
blablablabla
blablabla

BTW, ty for the quick reply.
Reply
#4

For some reason the \n and \r don't work if you save them to a file using the script then getting them back.
Have you tried putting the text in File.ini using notepad?
Reply
#5

Quote:

For some reason the \n and \r don't work if you save them to a file using the script then getting them back.
Have you tried putting the text in File.ini using notepad?

Yes, I've put it manually since the first time. I was trying to save parts of the text in differents variables and after that useing format to concatenate them, but as I have a looooot of text it would be very hard work.
Reply
#6

How about storing each line in a variable and making the dialog load its text like
"%s\n\r%s", var1, var2
Reply
#7

Do not use dini for this, instead use the normal SA:MP natives (fopen, fread, ...)

pawn Код:
static dialogText[256]; //Change size if needed
new File:DFile = fopen("Dialogs/Dialog1.txt", io_read), _tmpstr[64];
dialogText[0] = 0x0;
if(DFile)
{
    while(fread(DFile, _tmpstr)) //Reads the file line-by-line
    {
        strcat(dialogText, _tmpstr); //Adds the line to the end of the dialogText string
    }
}
ShowPlayerDialog(playerid, 2, 0, "Title:", dialogText, "Ok", "Back");
-------------------------

Quote:
Originally Posted by iRage
Посмотреть сообщение
For some reason the \n and \r don't work if you save them to a file using the script then getting them back.
Have you tried putting the text in File.ini using notepad?
That's because \r and \n are some type of "special characters", when you use them in PAWN it gets converted to 0xD (\r) and 0xA (\n) but if you type it in a file it will stay "as is" (Just a simple \ and a "r" or "n"). If you use notepad++ with "Show all characters" enabled it will show a "CR" and "LF" at the end of each line, that's \r\n
Reply
#8

Quote:
Originally Posted by OPremium
Посмотреть сообщение
That's because \r and \n are some type of "special characters", when you use them in PAWN it gets converted to 0xD (\r) and 0xA (\n) but if you type it in a file it will stay "as is" (Just a simple \ and a "r" or "n"). If you use notepad++ with "Show all characters" enabled it will show a "CR" and "LF" at the end of each line, that's \r\n
That's a thing I didn't know, thanks .
Reply
#9

man its small bug but tell me the code
Reply
#10

Why are you doing this?
Is other way to do it,if the text is big the dialog will not reading it but you can create a string like this.
Код:
new string[32];
format(string,sizeof(string), "Text\nText....");
ShowPlayerDialog(playerid, 2, 0, "Title:", string, "Ok", "Back");
Make the string biger if you have a big text.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)