strfind problem
#1

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)
Reply
#2

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
Reply
#3

Or use sscanf.
Reply
#4

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.
Reply
#5

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
Reply
#6

Thanks Gammix,NaS,Threshold for answering.


I will use your methode Gammix,thank you, rep+, and for you rep+ NaS
Reply
#7

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.
Reply
#8

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 ?
Reply
#9

You're trying to access the 5th element (0, 1, 2, 3, 4) of a 4-element array (valid index are 0-3).
Reply
#10

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 :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)