sscanf not writing data into enum.
#1

Hey i need some help with sscanf im trying to learn it but i get stuck with a problem .I'm trying to write my data from Mysql to my enumeration but it doesn't work I try ed another methods to do it and it worked so i solved to post here for a little help

pawn Код:
sscanf(query,"e<{ii}iiifffi>",
playerdb[playerid][money],playerdb[playerid][score],
playerdb[playerid][key],playerdb[playerid][x],
playerdb[playerid][y],playerdb[playerid][z],
playerdb[playerid][model);
Reply
#2

'e' indicates an enumerator, what means you just place the enum instead of a variable for everything
[pawn]sscanf(query,"e<{ii}iiifffi>", playerdb[playerid]);
Reply
#3

Thanks for help, but this is not working, I'm using sscanf in other things and them are working and with this enumeration is a FAIL lol , I try ed to improve it making a stock , someone take a look to see what is wrong.Thanks
pawn Код:
stock LoginPlayer(playerid,const playername[],const playerpassword[])
{
    new query[256];
    new string[124];
    if(sscanf(playerpassword,"s[32]",playerdb[playerid][password])) return ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_INPUT,"{FF0034}Login","{FF0034}Enter your password below:","Login","Cancel");
    format(query,sizeof(query),"SELECT * FROM playerdb WHERE username='%s' && password='%s'",playername,playerpassword);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows())
    {
        if(mysql_fetch_row(query, "|"))
        {
            sscanf(query, "e<s[25]s[25]iiifffi>", playerdb[playerid]);
            format(string, sizeof(string),"You have loged into your account %s",playerdb[playerid][username]);
            SendClientMessage(playerid,COLOR_WHITE,string);
        }
    }
    else
    {
        ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_INPUT,"{FF0034}Wrong password!","{FF0034}Enter your password below:","Login","Cancel");
    }
    return 1;
}
The rest of the code is working fine, i tested another ways and they resulted, i need to use sscanf because I'm using it in another things in my script
Reply
#4

Print the contents of "query" after you do mysql_fetch_row and also show us where you create the playerdb enumeration.
Reply
#5

pawn Код:
enum pdb
{
    username[MAX_PLAYER_NAME],
    password[50],
    money,
    score,
    key,
    Float:lastx,
    Float:lasty,
    Float:lastz,
    model,
}
new playerdb[MAX_PLAYERS][pdb];
That's the enumeration I use it under the main().. I printed the query and its getting the right values that i have on Mysql database.
Reply
#6

StuffBoy, this is not related to your issue but you should really be using mysql_free_result(); after using the data from your select query.
Reply
#7

Thanks i will use but that's only to calculate the memory used by the query

I printed my string and this is weird
Quote:

You have logged into your account StuffBoy|mypass|15000|1|2|3|4|5|6

something is mixing sscanf with the string the values are all there
Reply
#8

You're not telling sscanf to split the string by the | delimiter, you need to tell it to do so, otherwise it will split by spaces by default. Here is an example:

pawn Код:
sscanf(query, "e<p<|>s[25]s[25]iiifffi>", playerdb[playerid]);
Reply
#9

Thanks JaTochNietDan it solved the string but the enumeration stills without the data, seems something is wrong with sscanf or another thing i can't figure out, some help?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)