Could you explain me something?
#1

I never really understand a difference between a Stock and a public function?Though im kinda ashamed to ask.

Could you please help me understand them in a easy way. Will rep everyone who will help me.

Thanks for reading.
Ballu Miaa
Reply
#2

It's simple really...

A stock:
pawn Код:
stock hellosir()
{

}
and a standard function:
pawn Код:
hellosir()
{

}

Are local functions only. They are like... base level functions. There is nothing more to them than what meets the eye

Public functions:
pawn Код:
public hellosir()
{

}
Are much more useful. You can set them to recur after a certain amount of time:
pawn Код:
SetTimer(hellosir, 20000, true);
call them from other filterscripts/gm's
pawn Код:
CallRemoteFunction(hellosir,format,float)
and various other added functionality.

Stocks / Functions do NOT require a forward declaration, because they are only included into the script @ compile-time if they are used within the script.

Publics ARE included inside the AMX @ compile time.

Also, creating a prototype for the public function ie. forward hellosir(arg1, arg2) allows the compiler to check your use of that command for errors/variations later
Reply
#3

"stock" defines that a function may not be used, and if it isn't don't give a warning at compile time. This is used for library functions, you don't need it for writing normal modes.

"public" saves the name of the function in the amx (normally functions are just called be address, the human-readable name is not important). Saving the name means that the function can be found by name later on. When you specify a function in "SetTimer", "SetTimerEx", "CallLocalFunction" or "CallRemoteFunction" you specify it by name so these can only call public functions. Callbacks such as "OnPlayerConnect" are also public for the same reason.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)