How to get the index of an array variable?

Lord Ganja

New member
Messages
161
Points
0
Age
34
Location
Ganja World
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!

 
May you elaborate what you want to do?

(I don't seem to understand your question)

 
@@Lord Ganja

The only methode i know would be:

Code:
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;	}}
 
@@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.

 
@@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:

Code:
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;
 
Thanks @Winterfox 
default_no1.gif


 
Back
Top