View Single Post
Old 17/02/2015, 09:40 PM   #2
HazardouS
Huge Clucker
 
HazardouS's Avatar
 
Join Date: Aug 2014
Posts: 255
Reputation: 26
Default Re: Creating a function

Your function is created correctly (unless you placed that code inside a callback). There are, however, some errors in your code. First of all, you are missing the "playerid" parameter, so the SendClientMessage in your function doesn't know who to send the message to. The second thing that you should know is that function parameters don't have to be declared globally, because they are automatically declared locally, strictly for that function call (so remove the "new bizid, ...;" line). The third error is the size of your bizname parameter. Because it is not any string and you want to copy it in another one, you have to specify its size. Change bizname[] to bizname[size_of_bName_field]. Of course, size_of_bName_field is actually the size that you declared in your biz Info enum. The rest of your function is fine, probably, except you didn't declare BizLabel array anywhere. Make sure you do that.

Now, a short (very very short) lesson about how to declare a function. There are 3 ways to declare a function, at least I think so.
First one, public function (has to be forwarded):
pawn Code:
forward MyPublicFunction(param1, param2[], Float:param3);
public MyPublicFunction(param1, param2[], Float:param3)
{
//code
//return some_value;
}
Notice how I wrote the parameters in the exact same order and without messing their types (int, string, float).

The second method, your method:
pawn Code:
MyRandomFunction(param1, param2[], Float:param3)
{
//code
}
Notice that this function doesn't have that "public" or "forward" keyword in front of it, you write that anywhere in your script and it will work fine. It will give a warning if it's not used in the script.

The third method, which is very similar to the second one:
pawn Code:
stock MyRandomFunction(param1, param2[], Float:param3)
{
//code
}
Notice the keyword "stock" in front of it. The third method is actually the same as the second one, except it won't give any warnings if it's not used. It doesn't have to be forwarded, just place it somewhere and you're good to go.

The advantage of public functions? They can be called from other scripts (filterscripts) via CallRemoteFunction.
HazardouS is offline   Reply With Quote