[Tutorial] ALS Hook Method 7
#4

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Код:
public OnPlayerConnect(playerid)
{
    #if defined MyLib_OnPlayerConnect
        MyLib_OnPlayerConnect(playerid);
    #endif
    return 1;
}
#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect MyLib_OnPlayerConnect
#if defined MyLib_OnPlayerConnect
    forward MyLib_OnPlayerConnect(playerid);
#endif
You should add an else statement in case of returning 1 in callbacks; Because we don't always have to return 1 in callbacks.

Код:
public OnPlayerConnect(playerid)
{
    #if defined MyLib_OnPlayerConnect
        MyLib_OnPlayerConnect(playerid);
    #else
   	 	return 1;
	#endif

}
#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect MyLib_OnPlayerConnect
#if defined MyLib_OnPlayerConnect
    forward MyLib_OnPlayerConnect(playerid);
#endif
Even this needs modification.This is the correct way.

Код:
public OnPlayerConnect(playerid)
{
    #if defined MyLib_OnPlayerConnect
         return MyLib_OnPlayerConnect(playerid);
    #else
   	 	return 1;
	#endif

}
#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect MyLib_OnPlayerConnect
#if defined MyLib_OnPlayerConnect
    forward MyLib_OnPlayerConnect(playerid);
#endif
You must return what MyLib_OnPlayerConnect returns.Must return 1 only if the callback is not defined.
Returning 1 will allow the callback to be called in other scripts.If you don't return anything, I don't know what will happen.I guess what ever was stored in pri just before returning will be returned.Or maybe pri is zeroed before returning.

Someone please let me know.
Reply


Messages In This Thread
ALS Hook Method 7 - by !damo!spiderman - 18.05.2015, 03:51
Re: ALS Hook Method 7 - by Crayder - 18.05.2015, 03:56
Re: ALS Hook Method 7 - by Gammix - 18.05.2015, 08:36
Re: ALS Hook Method 7 - by Yashas - 18.05.2015, 08:59
Re: ALS Hook Method 7 - by Jonny5 - 07.06.2015, 14:33

Forum Jump:


Users browsing this thread: 1 Guest(s)