Escape sequences not working when loading strings from a MySQL table to a dialog? -
FreakaDaDisk - 20.07.2011
Hi.
I've got a table for commands, and fields "id(small int), text(varchar), info(varchar), enable(bool)". Let's say I have this text in field info: "line\nline2\nline3\line4". Unfortunately, there are no new lines in the dialog and it appears exactly like it's in the table, no mater what escape sequence there is. Is there a workaround for this? Because I'd really love to have this feature, since it's very dynamic.
Thanks.
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
Grim_ - 20.07.2011
Could you please show the code where you format the message to show to the player (and any variables associated with it)?
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
FreakaDaDisk - 20.07.2011
pawn Code:
CMD:help(playerid, params[])
{
mysql_query("SELECT `caption`, `info` FROM `cmd_help` WHERE `enable` = '1'", -1, -1, ssys);
mysql_store_result(ssys);
if (mysql_num_rows(ssys)) {
new data[348], caption[64], help[256];
mysql_fetch_row_format(data, "|", ssys);
sscanf(data, "p<|>s[64]s[256]", caption, help);
ShowPlayerDialog(extraid, DIALOG_CMD_HELP_S, DIALOG_STYLE_MSGBOX, caption, help, "Close", "");
mysql_free_result(ssys);
}
else {
ShowPlayerDialog(extraid, DIALOG_CMD_HELP_F, DIALOG_STYLE_MSGBOX, "Help", "We're sorry, this command is currently unavailable", "Cancel", "");
mysql_free_result(ssys);
}
}
That's it. I'm not formatting it, never thought of doing it.
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
Grim_ - 20.07.2011
Does the string that you send to the dialog contain the escape characters in it?
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
FreakaDaDisk - 20.07.2011
Database:
http://imageshack.us/f/194/40180809.png/
Server:
http://imageshack.us/f/34/samp808g.png/
Yes, it does.
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
Grim_ - 20.07.2011
Interesting, they must be escaped by one of the plugins. Try this code in order to re-insert them:
pawn Code:
// Not tested (couldn't think of a decent name >.>)
Fix( string[ ] )
{
for( new i = 0, j = strlen( string ); i < j; i++ )
{
if( string[ i ] == '\n' )
{
strdel( string, i, i + 1 );
strins( string, "\n", i );
}
}
return string;
}
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
FreakaDaDisk - 20.07.2011
It threw a warning,
Code:
warning 224: indeterminate array size in "sizeof" expression (symbol "maxlength")
at the line where strins is, so I've modified it to
pawn Code:
strins( string, "\n", i, strlen(string));
but it didn't work unfortunately

.
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
Grim_ - 20.07.2011
Interesting, I got it working when I tested with this code:
pawn Code:
new str[ 128 ];
strins( str, "hello\nthere", 0 );
Fix( str );
printf( "STRING: %s", str );
However, but not when using the shortcut
pawn Code:
printf( Fix( "hello\nthere" ) );
So using, in your code, Fix(caption), it should work correctly. Try printing that in the console too, when you put it into the dialog, and see if it shows a line in the console.
Here is the stock function I tested with:
pawn Code:
Fix( string[ ] )
{
for( new i = 0, j = strlen( string ); i < j; i++ )
{
if( string[ i ] == '\n' )
{
strdel( string, i, i + 1 );
strins( string, "\n", i, 1 );
}
}
return string;
}
Re: Escape sequences not working when loading strings from a MySQL table to a dialog? -
FreakaDaDisk - 21.07.2011
I've tested with this version too, but it didn't work. It printed in the console:
Code:
STRING: /givecash <id> <amout>\n/pm <id> <message> ; no new line