SA-MP Forums Archive
Assigning all items in an Enum array [using a loop] - 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: Assigning all items in an Enum array [using a loop] (/showthread.php?tid=186767)



Assigning all items in an Enum array [using a loop] - [HLF]Southclaw - 30.10.2010

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


Re: Assigning all items in an Enum array [using a loop] - legodude - 30.10.2010

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
};



Re: Assigning all items in an Enum array [using a loop] - Hiddos - 30.10.2010

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\'


Re: Assigning all items in an Enum array [using a loop] - Cameltoe - 30.10.2010

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]);



Re: Assigning all items in an Enum array [using a loop] - smeti - 30.10.2010

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]);



Re: Assigning all items in an Enum array [using a loop] - Mike_Peterson - 30.10.2010

You guys doing this on purpose?
Quote:

Wouldn\'t be wery efficient but:

Quote:

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

Vrong ledders ftw?


Re: Assigning all items in an Enum array [using a loop] - WillyP - 30.10.2010

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


ctrl + v fail?


Re: Assigning all items in an Enum array [using a loop] - Toni - 30.10.2010

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;
}



Re: Assigning all items in an Enum array [using a loop] - [HLF]Southclaw - 30.10.2010

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