Lord Ganja 5 Posted October 1, 2015 How do I extract the index of an array variable? e.g @mob_id[index] <--- How do I extract the index from @mob_id variable? Thanks in advance! Quote Share this post Link to post Share on other sites
0 Winterfox 83 Posted October 1, 2015 @@Lord Ganja Depends on what you want to do. If you wan't to use the index to check for a specific value you could do it like this: setarray .@mob_ids, 1002, 1003, 1004, 1005;.@mob_id = 1004;for(.@i=0; .@i < getarraysize(.@mobIds); .@i++) { .@blacklist[.@mobIds[.@i]] = 1;}if(!.@blacklist[.@mob_id]) { // Do something} But thats only worth if you want to have some kind of black/white list. Since if you iterate trough it depending on what you store you will get a pretty high index and will have to iterate over tons of empty values.You also could do something like this: setarray .@mob_ids$, 1002, 1003, 1004, 1005;.@mob_id$ = 1004;if(strcmp(":" + .@mob_id$ + ":", implode(.@mob_ids$, ":"))) { // Do something.} If you really want a way to easily get the index to a value you would need to do it like that i guess: setarray .@mob_ids, 1002, 1003, 1004, 1005;.@mob_id = 1005;for(.@i=0; .@i < getarraysize(.@mob_ids); .@i++) { .@mob_ids_lookup[.@mob_ids[.@i]] = .@i;}mes getmonsterinfo(.@mob_ids[.@mob_ids_lookup[.@mob_id]], 0);close; 1 Lord Ganja reacted to this Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted October 1, 2015 May you elaborate what you want to do? (I don't seem to understand your question) Quote Share this post Link to post Share on other sites
0 Winterfox 83 Posted October 1, 2015 @@Lord Ganja The only methode i know would be: setarray .@mob_ids, 1002, 1003, 1004, 1005;.@mob_id = 1004;for( .@i = 0; .@i < getarraysize(.@mob_ids); .@i++ ) { if(.@mob_ids[.@i] == .@mob_id) { .@index = .@i; break; }} Quote Share this post Link to post Share on other sites
0 Lord Ganja 5 Posted October 1, 2015 @@Dastgir, Exactly what Winterfox posted. But I was looking for something like script command, if it even exists. e.g setarray .@mob_ids, 1002, 1003, 1004, 1005; .@mob_ids[3]; <-- The index here is 3 getvarindex(.@mob_ids); <-- getvarindex is just an example, which returns the index of the attached variable -> so 'getvarindex' will return '1005' @@Winterfox Is there any alternative? Or is it the only way? Thanks btw. Quote Share this post Link to post Share on other sites
0 Lord Ganja 5 Posted October 2, 2015 Thanks @Winterfox Quote Share this post Link to post Share on other sites
How do I extract the index of an array variable?
e.g
@mob_id[index] <--- How do I extract the index from @mob_id variable?
Thanks in advance!
Share this post
Link to post
Share on other sites