funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for? -
iggy1 - 01.05.2012
Hello i was looking through zcmd and came across this code.
pawn Код:
zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
To me that translates to "zcmd_g_HasOPCS" equals "funcidx("OnPlayerCommandReceived")" doesn't equal -1.
I just don't understand what it is for
i have noticed it in a few other incs too.
I never do this when hooking callbacks. I do use funcidx to check if a func exists but never with -1 after it (when assigning to a var). I'm thinking maybe i should do it this way since all the experienced/pro coders use it.
Is this really necessary? And why?
I've just been doing this.
pawn Код:
g_HasORIL = funcidx("OnRetrieveIpLocation");
Thanks.
Re: funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for? -
zSuYaNw - 01.05.2012
This not necessary,
because this function (funcidx) return's the return of function..
Exemple:
pawn Код:
printf("%d",funcidx("MyPublic"));
MyPublic(); public MyPublic()
{
return 1;
}
Show's "1".
Re: funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for? -
iggy1 - 01.05.2012
It actually returns the index of a function. -1 if the func doesn't exist.
I understand why i would see this code.
pawn Код:
if(funcidx("iploc_OnGameModeInit") != -1)
But not when assigning to a var
pawn Код:
zcmd_g_HasOPCS = funcidx("OnPlayerCommandReceived") != -1;
Re: funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for? -
zSuYaNw - 01.05.2012
for locate value ...?
Re: funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for? -
[HiC]TheKiller - 01.05.2012
That value is assigned to increase the speed on OnPlayerCommandText. Setting zcmd_g_HasOPCS on OnFilterScriptInit / OnGameModeInit only has to be called once rather than multiple times.
Re: funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for? -
iggy1 - 01.05.2012
Quote:
Originally Posted by ******
When you're not sure what an expression does, add the brackets that are implicit in operator precedence:
...
zcmd_g_HasOPCS = (42 != -1);
...
|
Thanks if i had thought of the funcidx call as a number instead of a function i would have got that. I get it now thanks.
@ Killer i get why it's assigned just didn't get the "!= -1" part. Thanks for reply
Re: funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for? -
Dude_Lebowski - 01.05.2012
omg sounds complicated