question about compare
#1

what is more faster then strcmp?
and please show me an exemple on my loading system
pawn Код:
if(!strcmp(temp[0], "Score", true))
        {
            PlayerInfo[playerid][pScore] = strval(temp[1]);
            SetPlayerScore(playerid,PlayerInfo[playerid][pScore]);
        }
        else if(!strcmp(temp[0], "Admin", true))
        {
            SetPlayerAdminLevel(playerid,strval(temp[1]));
        }
        else if(!strcmp(temp[0], "Job", true))
        {
            SetPlayerJobID(playerid, strval(temp[1]));
        }
        else if(!strcmp(temp[0], "Cash", true))
        {
            SetPlayerCash(playerid,strval(temp[1]));
        }
        else if(!strcmp(temp[0], "health", true))
        {
            PlayerInfo[playerid][healthP] = strval(temp[1]);
        }
        else if(!strcmp(temp[0], "x", true))
        {
            PlayerInfo[playerid][PosX]  = strval(temp[1]);
        }
        else if(!strcmp(temp[0], "y", true))
        {
            PlayerInfo[playerid][PosY] = strval(temp[1]);
        }
        else if(!strcmp(temp[0], "z", true))
        {
            PlayerInfo[playerid][PosZ]  = strval(temp[1]);
        }
        else if(!strcmp(temp[0], "Interior", true))
        {
            PlayerInfo[playerid][Inter]  = strval(temp[1]);
        }
Reply
#2

You could hash the string and compare the outputs inside a switch statment
Or you use CallLocalFunction like zcmd, y_cmd does it

pawn Код:
//
    new
        func[32]
    ;
    format(func, sizeof func, "Loading_%s", temp[0]);
    CallLocalFunction(func, "is", playerid, temp[1]); // if temp[1] is empty this part will crash
pawn Код:
#define function%0(%1) forward%0(%1);public%0(%1)

function Loading_Score(playerid, params[]) {
    PlayerInfo[playerid][pScore] = strval(params);
    SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
}

function Loading_Admin(playerid, params[]) {
    SetPlayerAdminLevel(playerid,strval(params));
}
But I cant tell you how efficient this is for only ~10 strcmp
Reply
#3

well, I have a long list of players stuff, I need one fast and easy to use a compare, the strcmp a bit slow for me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)