SA-MP Forums Archive
How to create own function - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to create own function (/showthread.php?tid=262587)



How to create own function - ajwar - 18.06.2011

Hi, need a short tutorial how to make own function.


Re: How to create own function - randomkid88 - 18.06.2011

First, forward it:
pawn Код:
forward FunctionName(parameters);
The parameters are just variable names that you use. Treat them the same as other variables:
pawn Код:
FunctionName (id, message[], Float:radius) //first one is an integer, then string, then a floating point number
Second, declare it:
pawn Код:
public FunctionName(parameters) //Must match the forward line EXACTLY
{
     return 1;
}
Then use it. Make a function for repeated tasks throughout the script to save time.


Re: How to create own function - ajwar - 18.06.2011

thank's, exactly what i needed


Re: How to create own function - ajwar - 18.06.2011

How to use string? Can you give me an example?


Re: How to create own function - Macluawn - 18.06.2011

callbacks and functions aren't the same.
use
pawn Код:
FunctionName(parameters)
{
  return value;
}
or
pawn Код:
stock FunctionName(parameters)
{
  return value;
}
value equals the number (or array) you want to return. Use value as 1, if you dont need to return anything specific. Read on wiki the difference between stock functions and common functions