how to set a default array value to a var with 2 agruments? (when creating it globally) - 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 set a default array value to a var with 2 agruments? (when creating it globally) (
/showthread.php?tid=259413)
how to set a default array value to a var with 2 agruments? (when creating it globally) -
Donya - 04.06.2011
pawn Code:
new Text:PlayerFadeText[MAX_PLAYERS][MAX_FADES] = {INVALID_TEXT_DRAW,...};
it gives, invalid expression
AW: how to set a default array value to a var with 2 agruments? (when creating it globally) -
Nero_3D - 04.06.2011
You cant in pawn, you could use a 1d array with a little trick
pawn Code:
new Text: PlayerFadeText[MAX_PLAYERS * MAX_FADES] = {INVALID_TEXT_DRAW, ...};
#define PlayerFadeText[%0][%1] PlayerFadeText[(%0) + (MAX_PLAYERS * (%1))]
//could be [(MAX_FADES * (%0)) + (%1)] but %0 wont be an constant => no preprocess
This can be used like every 2d array, it is some nanoseconds slower through the calculation (also not worth to mention)
Or you set them in OnGameModeInit to their default value
pawn Code:
//OnGameModeInit
for(new i, j; i != sizeof PlayerFadeText; ++i) {
for(j = 0; j != sizeof PlayerFadeText[]; ++j) {
PlayerFadeText[i][j] = INVALID_TEXT_DRAW;
}
}
Or in your example with a player based array in OnPlayerConnect
pawn Code:
//OnPlayerConnect
for(new i; i != sizeof PlayerFadeText[]; ++i) {
PlayerFadeText[playerid][i] = INVALID_TEXT_DRAW;
}
Re: how to set a default array value to a var with 2 agruments? (when creating it globally) -
Donya - 04.06.2011
thanks.