Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
DustyShouri
Novice


Joined: 29 Oct 2004
Posts: 34

PostPosted: Thu Aug 11, 2005 11:12 pm   

Arrays and their indexs
 
I was wondering if there was a way to grab the index with the highest value in an array? I don't mean the value of the highest index, just the highest index?

#VAR test %array{0,1,0,5,0}

Is there anyway I could get it to return 4?
Reply with quote
Carabas
GURU


Joined: 28 Sep 2000
Posts: 434
Location: USA

PostPosted: Fri Aug 12, 2005 11:31 am   
 
#HELP %arrhigh
_________________
Carabas
Reply with quote
DustyShouri
Novice


Joined: 29 Oct 2004
Posts: 34

PostPosted: Fri Aug 12, 2005 6:30 pm   
 
That only grabs the length of the array.
Reply with quote
Carabas
GURU


Joined: 28 Sep 2000
Posts: 434
Location: USA

PostPosted: Fri Aug 12, 2005 6:39 pm   
 
If I understand your original question, this is the function you are looking for.

Quote:
Syntax: %arrhigh(arrayname)

return the index value of the last element in the array


#VAR test %array(0,1,0,5,0)
#SH %arrhigh(test)

Output: 4
_________________
Carabas
Reply with quote
DustyShouri
Novice


Joined: 29 Oct 2004
Posts: 34

PostPosted: Fri Aug 12, 2005 9:40 pm   
 
Nope, that gives the number of indexes in the array. I was looking to somehow find the index with the largest value in the array.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Fri Aug 12, 2005 10:40 pm   
 
You'll have to build your own on that one. It's basically a modified sort function, so it shouldn't be that hard to hammer out.
_________________
EDIT: I didn't like my old signature
Reply with quote
Carabas
GURU


Joined: 28 Sep 2000
Posts: 434
Location: USA

PostPosted: Sat Aug 13, 2005 12:33 am   
 
DustyShouri wrote:
Nope, that gives the number of indexes in the array.


Perhaps I am completely misunderstanding your question, but I thought you wanted the number of elements.

DustyShouri wrote:
#VAR test %array{0,1,0,5,0}

Is there anyway I could get it to return 4?


Then I suppose instead of returning 4, you'd want it to really return the index of 3 with the value of 5?

Ah, you know what. We have misunderstood each other. The first element of an array is at 0 (zero), not 1.

Now I understand your question Razz Unfortunately, there is no "built-in" way of doing this.
_________________
Carabas
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Sun Aug 14, 2005 3:20 am   
 
If you can use lists instead of arrays you can use the %max function.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net