A new line in dialog
#1

In my clan system the owner can set the 'news' text. Everybody can look at the news of that clan.
The owner types the news into a input dialog and then when other people look the news, they see what he typed.

But the problem is.. how can I make a new line in dialog?

Example: Owner wants the news to look like this:

Код:
Todays news:
1) New member
2) Leader change
But if he types
Код:
Todays news:\n1) New member\n2) Leader change
into the dialog when typing the news.. then the people who look at the news dialog will not see the new lines, they will see the \n!
Reply
#2

"Today News", "1) New Member\n 2) Leader Change", "Okay" ""
Reply
#3

No you don't understand me. The owner sets the message as
Код:
1) New Member\n 2) Leader Change
But when other players look at the message (DIALOG_STYLE_MSGBOX)
then it will show as:
Код:
1) New Member\n 2) Leader Change
No new lines.
Reply
#4

Send me full code!
Reply
#5

Код:
new string[1024];
                        format(string, sizeof(string), "%s", ClanInfo[PlayerInfo[playerid][pClan]][cMessage]);
                        ShowPlayerDialog(playerid, D_SHOWCLANMENU, DIALOG_STYLE_MSGBOX, "Clan news", string, "Ok", "");
ClanInfo[PlayerInfo[playerid][pClan]][cMessage] is:
Код:
1) New Member\n 2) Leader Change
but when the dialog is shown, no new lines.
Reply
#6

PHP код:
new string[1024],clan_id PlayerInfo[playerid][pClan];
for(new 
i,j=strlen(ClanInfo[clan_id][cMessage]);i<j;i++)
{
    if(
ClanInfo[clan_id][cMessage][i] == '~')ClanInfo[clan_id][cMessage][i] = '\n';
}
format(string,sizeof string,ClanInfo[clan_id][cMessage]);
ShowPlayerDialog(playerid,D_SHOWCLANMENU,DIALOG_STYLE_MSGBOX,"Clan news",string,"Ok",""); 
If a clan owner writes in his news:
PHP код:
Today news:~1.)New Member~2.)Leader Change 
It will show in the dialog:
PHP код:
Today news:
1.)New Member
2.
)Leader Change 
You have to use ingame this letter ~ for a new line.
Reply
#7

That's because "\n" is not the same as '\n'. Notice how I use different sets of quotes. Double quotes denote a string, where single quotes denote a single character. "\n" is actually made up of the two literal characters \ with character code 92, and n with character code 110. However '\n' is just a single character with character code 10. Refer to the ASCII table: http://www.asciitable.com/

To correct this apparent issue you will need to do string replacing yourself.
pawn Код:
for(new i, j = strlen(inputtext) - 1; i < j; i++)
{
    if(inputtext[i] == '\' && inputtext[i + 1] == 'n')
    {
        inputtext[i] = '
';
        inputtext[i + 1] = '
\n';
    }
}
That will find the sequence "\n" and replace the \ with a space and the n with the newline character. You will have an extra space after each line, but this shouldn't be noticeable and I reckon this method is easier than messing with strfind, strdel and whatnot.
Reply
#8

Thanks for your help, I understand what you're saying. I used this in my code (indendation messed up here):

Код:
for(new i, j = strlen(inputtext) - 1; i < j; i++)
                {
                    if(inputtext[i] == '\' && inputtext[i + 1] == 'n')
                    {
                        inputtext[i] = ' ';
                        inputtext[i + 1] = '\n';
                    }
                }

                format(string, sizeof(string), "%s", inputtext);
ClanInfo[PlayerInfo[playerid][pClan]][cMessage] = string;
The line
Код:
if(inputtext[i] == '\' && inputtext[i + 1] == 'n')
gives me the error: error 027: invalid character constant

I am using Sublime Text.
Reply
#9

It should be '\\' instead of '\'
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)