showing results from files into dialog
#1

I'm having a little problem with this code;
pawn Код:
if(fexist("names.txt"))
    {
        new File:pname = fopen("names.txt");
        new str[128];
        new string[400];
        while(fread(pname, string))
        {
            format(str,sizeof(str), "%s\n", string);
            printf("%s", str);
            ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Players", str, "Ok", "Cancel");
        }
        fclose(pname);
    }
And here's names.txt
Код:
player1
player2
player3
player4
It prints everything perfectly. But it only shows player4 in the dialog.
Reply
#2

pawn Код:
format(str,sizeof(str), "%s%s\n", str, string);
Reply
#3

Nothing changes.
Reply
#4

It should. Because you format str with every name but when you format again, it's deleting the previous names and format with the last name only.

EDIT: try it like so:

pawn Код:
while(fread(pname, string))
{
format(str,sizeof(str), "%s%s\n", str, string);
printf("%s", string);
}
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Players", str, "Ok", "Cancel");
Bad indentation, i am in school!
Reply
#5

Reply
#6

Hmm, i'm not sure why is not working, I did something similar and it worked fine.

I will make few tests when I will be back home.
Reply
#7

Quote:
Originally Posted by ]Rafaellos[
Посмотреть сообщение
It should. Because you format str with every name but when you format again, it's deleting the previous names and format with the last name only.

EDIT: try it like so:

pawn Код:
while(fread(pname, string))
{
format(str,sizeof(str), "%s%s\n", str, string);
printf("%s", string);
}
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Players", str, "Ok", "Cancel");
Bad indentation, i am in school!
That works. Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)