funcidx("OnPlayerCommandReceived") != -1; Whats != -1 for?
#1

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

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

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;
Reply
#4

for locate value ...?
Reply
#5

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

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

omg sounds complicated
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)