Array value setting
#1

PHP код:
enum RndEnum{
       
val,
       
val1
};
new 
RndArr[100][RndEnum]; 
How to set all 'val' values to -1, without looping through. for(new i; i < 100; i++)RndArr[i][val]=-1;
Reply
#2

Good question. I wanna know too.
Reply
#3

It will set all values to '0'.

Код:
static const empty_player[RndEnum];
RndArr[playerid] = empty_player;
Reply
#4

No i ONLY need to set 'val' to -1 not zero.
Reply
#5

You can't(you can but its impractical to use that method look below for example) do that without looping in pawno for multi dimensional arrays, but you can do it for single dimensional array.
Example:
PHP код:
//only works for single dimensional arrarys
new myValue[100] = {-1, ...};
//now all indexes of the above array has value '-1' 
You can do it practically for smaller multi dimensional array though, example:
PHP код:
new myValues[2][3] = {
   {
0,0,-1},
   {
0,0,-1}
}; 
So you can use this method for for larger arrays too, but you have to write 100 lines of code for a array of length 100 if you don't wanna loop then.
Reply
#6

Zeex's compiler supports nested ellipsis

So if you're willing to experiment and use it instead of standard pawn compiler, then you can use
pawn Код:
enum RndEnum{
       val,
       val1
};
new RndArr[100][RndEnum] = {
    { -1, 0 }, ...
};
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)