Annoying errors..
#1

This function is giving problem..

pawn Код:
stock MakeDrugs(playerid, name[])
{
    new drugslol;  
    if(name[] == "PurpleHaze")
    {      
        return drugslol = "Purple Haze";
    }
         return 1;
}
pawn Код:
if(name[] == "PurpleHaze")
Gives error error 029: invalid expression, assumed zero
pawn Код:
return drugslol = "Purple Haze";
Gives error error 006: must be assigned to an array

Any dieas?
Reply
#2

pawn Код:
stock MakeDrugs(playerid, name[])
{
    new drugslol[ 11 ];  
    if( !strcmp( name, "PurpleHaze" ))
    {      
        return format( drugslol, 11, "PurpleHaze" );
    }
    return 1;
}
Reply
#3

duh, thanks. Btw, is there another way the strcmp? will sscanf work?
Reply
#4

Sscanf and strcmp are two extremely different functions.
Strcmp (aka String Compare) is used to compare two strings.
Sscanf is way more advanced, and is not used for string comparison.
Reply
#5

i knew it compaired 2 strings, i just didnt know all the features of sscanf :P
Reply
#6

Quote:
Originally Posted by DiddyBop
Посмотреть сообщение
i knew it compaired 2 strings, i just didnt know all the features of sscanf :P
sscanf is more of a strlen, tmp, and strtok sort of thing all in one.

You can do multiple things with it, not only using it to check if they typed the cmd with params, but also to get information -- even from MySQL data.
Reply
#7

Quote:
Originally Posted by The Toni
Посмотреть сообщение
sscanf is more of a strlen, tmp, and strtok sort of thing all in one.

You can do multiple things with it, not only using it to check if they typed the cmd with params, but also to get information -- even from MySQL data.
Yeah i know that, i use it for my mySQL system, but thought it did strcmp also.
Reply
#8

It kinda does, but it does as the same time (not optional) many other things, which are unecaserry in your case.
That is why you should just use strcmp
You could also do something like this though:
pawn Код:
if( name[ 0 ] == "P" && name[ 1 ] == "u" && name[ 2 ] == "r" && name[ 3 ] == "p" && name[ 4 ] == "l" && name[ 5 ] == "e" && name[ 6 ] == "H" && name[ 7 ] == "a" && name[ 8 ] == "z" && name[ 9 ] == "e" )
But as you see, that is way slower than just using strcmp (slower to write that is.. Dunno if it's faster to check each cell manually, but I think that's just what strcmp does)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)