SA-MP Forums Archive
What make public and . . . Different - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What make public and . . . Different (/showthread.php?tid=547050)



What make public and . . . Different - Raefal - 20.11.2014

Hey guys, i want to ask to you, what make forward BlaBla(); public BlaBla() and BlaBla() (( Without public tag )) different?


Re : What make public and . . . Different - Dutheil - 20.11.2014

I don't know if I understood.
You want to make something like that : ?
pawn Код:
Thing:Blabla(playerid)
{
}



Re: What make public and . . . Different - Affan - 20.11.2014

pawn Код:
forward SayHello(playerid);
public SayHello(playerid)
{
    SendClientMessage(playerid, -1, "Hello!");
    return 1;
}

// You can use this on timers and etc.

SayHello(playerid)
{
    SendClientMessage(playerid, -1, "Hello!");
    return 1;
}

// or

stock SayHello(playerid)
{
    SendClientMessage(playerid, -1, "Hello!");
    return 1;
}

// cannot be used in timers and etc.



Re: What make public and . . . Different - Vince - 20.11.2014

A public function is "visible" to the server. Its name is stored as a literal string in the compiled gamemode so the server can find it by name, whereas regular functions are converted to addresses. The server knows it needs to execute thing X at address Y, but names aren't important. A function need only be public if the server itself needs to find it. This includes the callbacks and timers.

stock is a modifier that hides a variable or function from the compiler if it's not used. There is zero need to use stock in a normal gamemode. It is only useful in included files because the person using those files may or may not use all the features.


Re: What make public and . . . Different - PowerPC603 - 20.11.2014

Also CallRemoteFunction is used with public functions.
That way you can execute a function in a filterscript with code inside your gamemode for example.
This makes it possible to allow 2 separate scripts to exchange data between them.

You may have a filterscript which controls fuel for your vehicles.
Your gamemode could also create vehicles, but will require a function call to your filterscript to set/get fuel values for that vehicle.

If you don't use publics, you can't do this, as the function isn't "public" to the server and/or other scripts.