SA-MP Forums Archive
Return an array in public - 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: Return an array in public (/showthread.php?tid=290759)



Return an array in public - Homerman - 16.10.2011

Hello. I'm working on a function for my server, however I always get an error, telling me I can't return a string in a public function. I tried to put the string into strlen(), which showed no result at all, so I'm asking for a help here.
Thanks!

Код:
public OnPlayerText(playerid, text[])
{
	new string[160], pName[32];
	GetPlayerName(playerid, pName, sizeof(pName));
	if(GetPVarInt(playerid, "Infected") == 1)
	{
		format(string, sizeof(string), "[Person %d]: %s", GetNumber(pName), text);
		return string;
	}
	else return 1;
}
The errors are:
Код:
C:\Users\Viktor\Desktop\lol.pwn(18) : error 090: public functions may not return arrays (symbol "OnPlayerText")
C:\Users\Viktor\Desktop\lol.pwn(20) : error 079: inconsistent return types (array & non-array)



Re: Return an array in public - AeroBlast - 16.10.2011

pawn Код:
public OnPlayerText(playerid, text[])
{
    new string[160], pName[32];
    GetPlayerName(playerid, pName, sizeof(pName));
    if(GetPVarInt(playerid, "Infected") == 1)
    {
        format(string, sizeof(string), "[Person %d]: %s", GetNumber(pName), text);
            SendClientMessageToAll(0xFFFFFFFF,string);
        return 0;
    }
    else return 1;
}
Try this.


Re: Return an array in public - Homerman - 17.10.2011

I don't want a SendClientMessage there, I want to return that value.
You know, somebody might be using ProxDetector or his own SendClientMessage in OnPlayerText, so he will need to change it, I just want the public to return THAT format I have.


Re: Return an array in public - [Diablo] - 17.10.2011

public function cannot return a string, you need a stock.