SA-MP Forums Archive
New line in a file (with dini) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: New line in a file (with dini) (/showthread.php?tid=342764)



New line in a file (with dini) - Dehumanizer - 15.05.2012

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...


Re: New line in a file (with dini) - SuperViper - 15.05.2012

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


Re: New line in a file (with dini) - Dehumanizer - 15.05.2012

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.


Re: New line in a file (with dini) - iRage - 15.05.2012

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?


Re: New line in a file (with dini) - Dehumanizer - 15.05.2012

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.


Re: New line in a file (with dini) - iRage - 15.05.2012

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


Respuesta: New line in a file (with dini) - OPremium - 15.05.2012

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


Re: Respuesta: New line in a file (with dini) - iRage - 15.05.2012

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 .


Re: New line in a file (with dini) - john_jenkins - 15.05.2012

man its small bug but tell me the code


Re: New line in a file (with dini) - TzAkS. - 15.05.2012

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.