Assigning all items in an Enum array [using a loop]
#1

Is it possible to assign a value [in my case reset to 0] to all items in an enumerated array


For instance:

enum data

{

data1,

data2,

data3,

data4,

data5

}

new array[data];



Instead of doing this:

array[data1] = 0;

array[data2] = 0;

array[data3] = 0;

array[data4] = 0;

array[data5] = 0;




Is there any way to assign all the items using a loop

for(new i;i<5;i++)

array[i]=0;



That gives me a tag mismatch error, any way around it?



Thanks for any replies :P
Reply
#2

Quote:
Originally Posted by [HLF]Southclaw
View Post
Is it possible to assign a value [in my case reset to 0] to all items in an enumerated array


For instance:

enum data

{

data1,

data2,

data3,

data4,

data5

}

new array[data];



Instead of doing this:

array[data1] = 0;

array[data2] = 0;

array[data3] = 0;

array[data4] = 0;

array[data5] = 0;




Is there any way to assign all the items using a loop

for(new i;i<5;i++)

array[i]=0;



That gives me a tag mismatch error, any way around it?



Thanks for any replies :P
haha u made ur own [code] tags

and for the tag mismatch

u could try to do
Code:
enum bla[15]{
bla1,
bla2,
and so on
};
Reply
#3

Quote:
Originally Posted by [HLF]Southclaw
View Post

enum data

{

data1,

data2,

data3,

data4,

data5

}

new array[data];
Just a small idea, didn\'t tested it:

pawn Code:
new array[daya] = {0, ...};


Sets all variable values to \'0\'
Reply
#4

Wouldn\'t be wery efficient but:

pawn Code:
enum vTest
{
     Value1,
     Value2,
     Value3,
     Value4,
}
new Reset[1][vTest];

new string[50];
format(string, sizeof(string), "0|0|0|0");
sscanf(string, "p<|>e<iiii>", Reset[0]);
Reply
#5

Try:
pawn Code:
enum
    data
{
    data1,
    data2,
    data3,
    data4,
    data5
};

new
    array[data],
    array2[data];

    for(new i; data:i < data; i++)
    {
        array[data:i] = 0;
        array2[data:i] = 1;
    }
   
    printf("%d | %d | %d | %d | %d", array[data1], array[data2], array[data3], array[data4], array[data5]);
    printf("%d | %d | %d | %d | %d", array2[data1], array2[data2], array2[data3], array2[data4], array2[data5]);
Reply
#6

You guys doing this on purpose?
Quote:

Wouldn\'t be wery efficient but:

Quote:

new array[daya] = {0, ...};

Vrong ledders ftw?
Reply
#7

Quote:
Originally Posted by Mike_Peterson
View Post
Vrong ledders ftw?


ctrl + v fail?
Reply
#8

Try this?

pawn Code:
enum data
{
    data1,
    data2,
    data3,
    data4,
    data5
}
new array[data];

for(new i = 0; i < sizeof(array[data]); i++)
{
    array[i] = 0;
}
Reply
#9

Thanks for all the replies, the one that worked was smeti\'s, thanks

never thought of using the enum name before a colon :P

Thanks again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)