how to set a default array value to a var with 2 agruments? (when creating it globally)
#1

pawn Code:
new Text:PlayerFadeText[MAX_PLAYERS][MAX_FADES] = {INVALID_TEXT_DRAW,...};
it gives, invalid expression
Reply
#2

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;
    }
Reply
#3

thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)