Stocks or Forwards ?
#1

can somebody explain to me how can i use this thing correctly, i want to make all lines in one function. what to put "stock or forward" ?

example:
this 1 is the forward method:

pawn Код:
public OnGameModeInit()
{
    GameModeTextDraws();
   
    return 1;
}

forward GameModeTextDraws();
public GameModeTextDraws()
{
    let's say it's about 300 lines.
    return 1;
}

and this 1 is the stock method

pawn Код:
public OnGameModeInit()
{
    GameModeTextDraws();

    return 1;
}

stock GameModeTextDraws()
{
    let's say it's about 300 lines.
    return 1;
}
what should i use ?
Reply
#2

Quote:
A function should be public whenever "the server" must be able to call the function at run time.
Always add public to your function when it is called by
  • a timer, (see also SetTimer and SetTimerEx),
  • CallLocalFunction,
  • CallRemoteFunction.
If none of those functions above are used to call it, then there's not point of using it. Use stock instead.
Reply
#3

thank you
Reply
#4

I agree with Konstantinos and would like to add not to ignore the "static" type as well when your using includes this will help encapsulate your code I'll give a quick example.

pawn Код:
#include <YSI\y_hooks>

hook OnPlayerConnect()
{
    DoSomething(playerid);
    return 1;
}

static DoSomething()
{
    return 1;
}
Now the function DoSomething() would only work in this specific include the rest of the script can't see the DoSomething() function. So why would anyone want to hide parts of the script? In short it's good practice always do the right thing when it makes sense and if a function doesn't need to be used anywhere else it makes sense to hide it.

Read more here.

http://en.wikipedia.org/wiki/Encapsu...ed_programming)

Yes PAWN is not object oriented programming but the concept is still has the same fundamental reasons.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)