SA-MP Forums Archive
2D Array (1st playerid, 2nd string) - 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: 2D Array (1st playerid, 2nd string) (/showthread.php?tid=109079)



[SOLVED] Arrays with strings - TMasters - 17.11.2009

iok.. what i need is this
Код:
new pText[MAX_PLAYERS][256];
Two-dimensional array string
Код:
new twodimensionalarraystring[ROWS][COLUMNS][256]; //for a string with a max length of 255, excluding NULL byte
I want use it like this, but how i do it correctly
Код:
format(pText[playerid],sizeof(pText[playerid]),"TEST: %s(%d): %s",pName(playerid),playerid,params);
SendClientMessageToAll(COLOR_WHITE, pText[playerid]);
CORRECT:
Код:
format( pText[playerid], sizeof(pText[]), "TEST: %s(%d): %s", pName(playerid), playerid, params);



Re: 2D Array (1st playerid, 2nd string) - pen_theGun - 17.11.2009

try this:
pawn Код:
format( pText[playerid], sizeof(pText[])-1, "TEST: %s(%d): %s", pName(playerid), playerid, params);



Re: 2D Array (1st playerid, 2nd string) - TMasters - 18.11.2009

Nope. But thx for try


Re: 2D Array (1st playerid, 2nd string) - LarzI - 18.11.2009

Change
pawn Код:
sizeof(pText[playerid])
to
pawn Код:
128
And also change
pawn Код:
new pText[MAX_PLAYERS][256];
to
pawn Код:
new pText[MAX_PLAYERS][128];



Re: 2D Array (1st playerid, 2nd string) - mamorunl - 18.11.2009

I don't really remember how I did it but you could try (don't know if it works, but worth a shot right?) format(pText[playerid][0],sizeof(pText[playerid][0], "TEST: %s(%d): %s", pName(playerid), playerid, params);

larzi: will that get rid of the warnings/errors? (post had been made, so yea I figured, why not post it)


Re: 2D Array (1st playerid, 2nd string) - LarzI - 18.11.2009

It got rid of warnings when I tried atleast, so yeah...
And I also tried only sizeof(pText) but that wouldn't work out (I think).
But 128 (which is the maxsize of pText) gives no warnings/errors


Re: 2D Array (1st playerid, 2nd string) - pen_theGun - 18.11.2009

Quote:
Originally Posted by pen_†ĥęGun
pawn Код:
format( pText[playerid], sizeof(pText[])-1, "TEST: %s(%d): %s", pName(playerid), playerid, params);
Quote:

Nope. But thx for try

Are you sure?

pawn Код:
main()
{
  new pText[MAX_PLAYERS][256];
  format( pText[0], sizeof(pText[])-1, "TEST: %s(%d): %s", "Spiderman", 0, "params");
  print(pText[0]);
}
Just tested, works perfekt.


Re: 2D Array (1st playerid, 2nd string) - LarzI - 18.11.2009

please use 128 not 256 for cell size


Re: 2D Array (1st playerid, 2nd string) - pen_theGun - 18.11.2009

Quote:
Originally Posted by lrZ^ aka LarzI
please use 128 not 256 for cell size
there is no reason, not to use that (256)
i even use more then 256, if i "realy need" so much.
So you dont know, how and for what 'TMasters.tk' using it for..


Re: 2D Array (1st playerid, 2nd string) - LarzI - 18.11.2009

but strings can't be bigger than 128 cells so why bother defining the vars with more?
their inactive and useless