strcmp Help!
#1

I'm really confused right now...
I've seen many people use the strcmp with different numbers, for e.g:

Код:
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
And some write like:-

Код:
if (strcmp("/mycommand", cmdtext, true, 5) == 0)
so what does the number represents? and what does it do when you reduce or increase it?

Thank you.
Reply
#2

It just checks the first x characters.
Reply
#3

Quote:
Originally Posted by Jamester
Посмотреть сообщение
It just checks the first x characters.
Can you please explain in simpler term? sorry I'm new in all this..
Reply
#4

hello -> 6 characters -> x = 4
hell -> 4 characters -> strcmp thinks it's valid
Reply
#5

Quote:
Originally Posted by Jamester
Посмотреть сообщение
hello -> 6 characters -> x = 4
hell -> 4 characters -> strcmp thinks it's valid
so it's like optional? or mandatory to change the numbers while creating a cmd?
Reply
#6

If you do something like /gset and then have something like /gsettings and your length is 5, it'll think /gsettings = gset so yes I would say it's mandatory, but it's optional I've never tested without the optional paramater.
Reply
#7

Ahh, got it.

Thank you so much.
Reply
#8

When a command (using the default way - strcmp checking) has no parameters and you compare "cmdtext", then you don't need to check for a length. If a command has parameters, you need to specify a length so it will compare only the command name with the given command and not the parameters.

If it's not just a question for learning something new and it's about creating commands, don't bother to use OnPlayerCommandText + strcmp as they're slow. Check for "zcmd" and "sscanf" for parameters (string splitter).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)