Trouble with array - 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: Trouble with array (
/showthread.php?tid=525240)
Trouble with array -
cnoopers - 10.07.2014
Код:
new playermail[256][MAX_PLAYERS];
Код:
stock SendPlayerMail(playerid, text[])
{
if(IsPlayerConnected(playerid))
{
playermail[playerid] = text; //error 047: array sizes do not match, or destination array is too small
}
}
after used that:
Код:
SendPlayerMail(playerid, "asdf123");
Re: Trouble with array -
Vince - 10.07.2014
1) You have your array dimensions in the wrong order. Swap them (MAX_PLAYERS <-> 256).
2) Use strcpy to copy strings.
Re: Trouble with array -
cnoopers - 10.07.2014
first, changed but still.
second, how exactly?
Re: Trouble with array -
cnoopers - 11.07.2014
who is know?
Re: Trouble with array -
NewerthRoleplay - 11.07.2014
Just include string into the gamemode and as Vince put on another post for copying strings:
pawn Код:
stock strcpy(dest[], const source[], maxlength=sizeof dest)
Re: Trouble with array -
cnoopers - 11.07.2014
just like this? still error.
Код:
stock SendPlayerMail(playerid, text[])
{
if(IsPlayerConnected(playerid))
{
playermail[playerid] = text;
strcpy(playermail[playerid], text, 256);
}
}
stock strcpy(dest[], const source[], maxlength=sizeof dest)
{
strcat((dest[0] = EOS, dest), source, maxlength);
}
Re: Trouble with array -
Jefff - 11.07.2014
for huge arrays with text use strpack and unpack
pawn Код:
new playermail[MAX_PLAYERS][128 char];
stock SendPlayerMail(playerid, text[])
{
if(IsPlayerConnected(playerid))
strpack(playermail[playerid],text,sizeof(playermail[]));
}
and after if you want to 'decode'
pawn Код:
new Mail[128];
strunpack(Mail,playermail[playeris]);
SendClientMessage(playerid,-1,Mail); // Mail is now your playermail[playerid]
Re: Trouble with array -
cnoopers - 11.07.2014
work, thank you