Jump to content
  • 0
Lord Ganja

How to get the index of an array variable?

Question

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

5 answers to this question

Recommended Posts

  • 0

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

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.