What make public and . . . Different
#1

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)