Annoying errors.. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Annoying errors.. (
/showthread.php?tid=173541)
Annoying errors.. -
DiddyBop - 02.09.2010
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?
Re: Annoying errors.. -
LarzI - 02.09.2010
pawn Код:
stock MakeDrugs(playerid, name[])
{
new drugslol[ 11 ];
if( !strcmp( name, "PurpleHaze" ))
{
return format( drugslol, 11, "PurpleHaze" );
}
return 1;
}
Re: Annoying errors.. -
DiddyBop - 02.09.2010
duh, thanks. Btw, is there another way the strcmp? will sscanf work?
Re: Annoying errors.. -
LarzI - 02.09.2010
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.
Re: Annoying errors.. -
DiddyBop - 02.09.2010
i knew it compaired 2 strings, i just didnt know all the features of sscanf :P
Re: Annoying errors.. -
Toni - 02.09.2010
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.
Re: Annoying errors.. -
DiddyBop - 02.09.2010
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.
Re: Annoying errors.. -
LarzI - 03.09.2010
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)