PDA

View Full Version : Dialog list showing strange character


MotherDucker
09/05/2016, 05:07 PM
Hello guys,

Just got a small problem which has only just started to appear, I am trying to display the character names and if there is no row, then it just shows "Create Character" however it shows a strange character for the middle item.

public OnPlayerCharacterSelection(playerid)
{
Debug(DEBUG_CALLBACK_SQL, "OnPlayerCharacterSelection(%i)", playerid);
print("OnPlayerCharacterSelection Called.");

MySQL::getData(rows, fields);

for(new i = 0; i < rows+1; i++)
{
MySQL::storeString(i, 0, Temp[i]);
if(strfind(Temp[i], "null", true) != -1) strcat((Temp[i][0] = EOS, Temp[i]), "Create Character", 17);
}

format(str, sizeof(str), "%s\n%s\n%s", Temp[0], Temp[1], Temp[2]);
ShowPlayerDialog(playerid, DIALOG_ACCOUNT, DIALOG_STYLE_LIST, ""SVR_NAME" - Account", str, DIALOG_BUTTON_SELECT, DIALOG_BUTTON_EXIT);
}

http://i.imgur.com/GIBssXF.jpg

MotherDucker
10/05/2016, 03:18 PM
Bump

jlalt
10/05/2016, 03:29 PM
public OnPlayerCharacterSelection(playerid)
{
Debug(DEBUG_CALLBACK_SQL, "OnPlayerCharacterSelection(%i)", playerid);
print("OnPlayerCharacterSelection Called.");

MySQL::getData(rows, fields);

for(new i = 0; i < rows; i++)
{
MySQL::storeString(i, 0, Temp[i]);
if(strfind(Temp[i], "null", true) != -1) strcat((Temp[i][0] = EOS, Temp[i]), "Create Character", 17);
}

format(str, sizeof(str), "%s\n%s\n%s", Temp[0], Temp[1], Temp[2]);
ShowPlayerDialog(playerid, DIALOG_ACCOUNT, DIALOG_STYLE_LIST, ""SVR_NAME" - Account", str, DIALOG_BUTTON_SELECT, DIALOG_BUTTON_EXIT);
}

as you started from 0 here

for(new i = 0; i < rows+1; i++)

You don't need +1 thingy so it should be

for(new i = 0; i < rows; i++)

Dayrion
10/05/2016, 03:30 PM
Put a print under format(str, sizeof(str), "%s\n%s\n%s", Temp[0], Temp[1], Temp[2]); and check if it's same thing on the console. (print : printf("%s - %s - %s", Temp[0], Temp[1], Temp[2]);

EDIT : Don't do that if jlalt solved the problem. :$

Konstantinos
10/05/2016, 03:45 PM
There are few things that can be improved though:

- Getting fields when not used (not necessary).
- Using isnull instead of strfind.
- Using strcat instead of format (jlalt used it).

I find this way better:

new tmp_str[MAX_PLAYER_NAME + 1];

rows = cache_num_rows();

if (!rows) str = "Create Character";
else
{
str[0] = EOS;

for (new i = 0; i < rows; i++)
{
cache_get_row(i, 0, tmp_str);
strcat(str, tmp_str, sizeof str);
strcat(str, "\n", sizeof str);
}
}

ShowPlayerDialog(...);

MotherDucker
10/05/2016, 09:18 PM
Thanks guys, I don't really know why I had rows+1 :/ I must have done it by accident or something, but yeah; I've also adapted it differently and took into consideration Konstantinos' reply.