Displaying Data in dialogues fetched from the SQL Database
#1

Hello, everyone. Well I'm in the process of scripting a character system and it's pretty much done now which I am amazed to have gotten this far without a single error, right up until I look at my characters through the in game dialog...

I currently have two characters in the database named Test_Char1 & Test_Char2.

Now I was hoping to display a list dialogue that displays these two characters and the player can choose between which one they wants to play as. Problem is, it only shows Test_Char1 in the list dialogue and Test_Char2 is no where to be found on the dialog.

When the dialog appears I have this code to send a query to the pCharacters table where I store all of the characters.

pawn Код:
else if(dialogid == DIALOG_UCP)
    {
        if(listitem == 0)
        {
            //Displaying the players character menu
            new query[128];


            format(query, sizeof(query), "SELECT * FROM `pCharacters` WHERE cOwnerID='%d'", PlayerInfo[playerid][uniqID]);
           
            mysql_function_query(dbHandle, query, true, "FindCharacters", "i", playerid);
           
        }
What I have under public FindCharacters

pawn Код:
forward FindCharacters(playerid);
public FindCharacters(playerid)
{
    new rows,
        fields,
        temp[100],
        charname[32],
        charlist[200],
        previousid[100];
       
    cache_get_data(rows, fields);
   
    if(rows)
    {
           
        cache_get_row(0, 1, temp);

        if(PlayerInfo[playerid][uniqID] == strval(temp))
        {
            for(new i = 0; i < 5; i++)
            {

                cache_get_row(0, 2, charname);

                cache_get_row(0, 0, previousid);

                format(charlist, sizeof(charlist), "%s%s (CID: %d)\n", charlist, charname, strval(previousid));
            }
        }
        ShowPlayerDialog(playerid, DIALOG_MYCHARACTERS, DIALOG_STYLE_LIST, "{FF0000}My Characters", charlist, "Play", "UCP");
       
    }
    else
    {
        format(charlist, sizeof(charlist), "{FFFFFF}No Available Characters!");
       
        ShowPlayerDialog(playerid, DIALOG_NOCHARACTERS, DIALOG_STYLE_MSGBOX, "{FFFFFF}You don't own any characters!", charlist, "Back", "");
    }


    return 1;
}
I've tried loops, i've tried not using loops... I just can't seem to get it right! Since placing the loop in the public sub it's began looping the character five times on the dialog so it appears as

Test_Char1 (CID: %d)
Test_Char1 (CID: %d)
Test_Char1 (CID: %d)
Test_Char1 (CID: %d)
Test_Char1 (CID: %d)

Any ideas people? Cheers

~Liam
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
It prints things 5 times because you told it to print things 5 times:

pawn Код:
for(new i = 0; i < 5; i++)
That means "do this code 5 times", each time adding the same string on to the end of the previous ones.
I figured as much when I looked at it for a while... The idea of doing the loop was to loop through all possible characters but that never worked. I tried it without the loop and it simply printed the one character which was Test_Char1.

My queries work off looking for a character that has the same 'Owner ID' as the master account... but for some reason it just finds the first character in the database and stops looking for others.. so it would seem.
Reply
#3

Could you supply with me an example on a simple loop through rows? Doesn't have to be related to what i'm asking for, just an example that I could learn and work off.
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
Have you looked up the documentation on cache_get_row?
To a degree from the plugin topic and the tutorial provided by AndreT a number of months ago... It still doesn't exactly leave me any closer to figuring a way around this.. Unless it's the use of the idx syntax??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)