strfind problem -
TiXz0r - 04.05.2015
Hello, i have command , /checkgarage and can type,1,2,3,4,5,6,7,8,9+, but, i have problem.
I use this of part in command:
Код:
if(strfind(garageid, "1", true))
compile error:
error 035: argument type mismatch (argument 1)
Re: strfind problem -
Gammix - 05.05.2015
Why do you use
strfind?
You must use strcmp (for exact locating of command), but maybe your code work that way!
Here is the wiki link:
https://sampwiki.blast.hk/wiki/Strfind (try searching before posting)
Actually if the param
garageid is just integer type, you can have a better way of performing those checks:
pawn Код:
switch(strval(garageid))
{
case 1://player have typed 1
{
//your code
}
case 2://player have typed 2
{
//your code
}
default://mkae use of this when the player have typed an invalid number
}
Strval:
https://sampwiki.blast.hk/wiki/Strval
Re: strfind problem -
Threshold - 05.05.2015
Or use sscanf.
AW: strfind problem -
NaS - 05.05.2015
Assuming garageid is an integer this:
Код:
switch(strval(garageid))
{
case 1://player have typed 1
{
//your code
}
case 2://player have typed 2
{
//your code
}
default://mkae use of this when the player have typed an invalid number
}
would not work because strval is reading an int value out of a string (array) - which garageid just isn't.
A proper way would be getting the int value from the delimited cmdtext (strtok, dcmd) and put that value into the switch (so basically
strval(cmd) instead of
strval(garageid) - assuming strtok or dcmd and "cmd" containing the value as string).
Theoretically strfind does work for this too, just that it would detect "/checkgarageaddrandomtexthere" as "/checkgarage", since it contains "/checkgarage".
TiXz0r, look for command processors on the forums and maybe some tutorials, they explain the differences between the methods very well.
Re: AW: strfind problem -
Gammix - 05.05.2015
Quote:
Originally Posted by NaS
Assuming garageid is an integer this:
Код:
switch(strval(garageid))
{
case 1://player have typed 1
{
//your code
}
case 2://player have typed 2
{
//your code
}
default://mkae use of this when the player have typed an invalid number
}
would not work because strval is reading an int value out of a string (array) - which garageid just isn't.
A proper way would be getting the int value from the delimited cmdtext (strtok, dcmd) and put that value into the switch (so basically strval(cmd) instead of strval(garageid) - assuming strtok or dcmd and "cmd" containing the value as string).
Theoretically strfind does work for this too, just that it would detect "/checkgarageaddrandomtexthere" as "/checkgarage", since it contains "/checkgarage".
TiXz0r, look for command processors on the forums and maybe some tutorials, they explain the differences between the methods very well.
|
Why would you suggest him a command processor. I don't think that piece of code is even related to any command processor or even sscanf.
He's just asking a method to detect what values a player typed (known as params in YCMD, ZCMD..).
My code will work because you can't have direct integers from a command, you always have to convert it using strval, strtok, sscanf...
And strval don't read int values, they convert
https://sampwiki.blast.hk/wiki/Strval
Re: strfind problem -
TiXz0r - 05.05.2015
Thanks Gammix,NaS,Threshold for answering.
I will use your methode Gammix,thank you, rep+, and for you rep+ NaS
AW: Re: AW: strfind problem -
NaS - 05.05.2015
Quote:
Originally Posted by Gammix
Why would you suggest him a command processor. I don't think that piece of code is even related to any command processor or even sscanf.
He's just asking a method to detect what values a player typed (known as params in YCMD, ZCMD..).
My code will work because you can't have direct integers from a command, you always have to convert it using strval, strtok, sscanf...
And strval don't read int values, they convert https://sampwiki.blast.hk/wiki/Strval
|
No, your code was not working how you posted it. You tried to convert an integer (garageid) to integer (using strval).
Thanks for repeating my words.
I'm just trying to help him, with whatever method he chooses and prevent him running into another invalid code.
Look at this (what you posted):
switch(strval(garageid))
garageid is integer. strval converts a string into integer.
The use of strval isn't wrong here (in the switch), but garageid is not a string that can be converted by strval.
Re: strfind problem -
TiXz0r - 05.05.2015
I have problem with coverting int to string.
Код:
new type2[4];
type2[4] = strval(type);
Код:
error 032: array index out of bounds (variable "type2")
Quote:
Originally Posted by NaS
No, your code was not working how you posted it. You tried to convert an integer (garageid) to integer (using strval).
Thanks for repeating my words.
I'm just trying to help him, with whatever method he chooses and prevent him running into another invalid code.
Look at this (what you posted):
switch(strval(garageid))
garageid is integer. strval converts a string into integer.
The use of strval isn't wrong here (in the switch), but garageid is not a string that can be converted by strval.
|
can you explain me more for your method of my command ?
Re: strfind problem -
MP2 - 05.05.2015
You're trying to access the 5th element (0, 1, 2, 3,
4) of a 4-element array (valid index are 0-3).
Re: strfind problem -
TiXz0r - 05.05.2015
Quote:
Originally Posted by MP2
You're trying to access the 5th element (0, 1, 2, 3, 4) of a 4-element array (valid index are 0-3).
|
again got error :/