Jump to content
  • 0

Print array result in order


Orce

Question


  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  5
  • Reputation:   1
  • Joined:  06/13/13
  • Last Seen:  

how to arrange the result of an array in ascending or descending form?

I have an NPC that counts the time the clan is holding the castle and I play this time in an array:

$rank(getcastledata($Castles$[.@e],1)),.@time;

now I want to organize by ex in a WoE rank, get the results by array for example: $rank(getcastledata($Castles$[.@e],1)) and organize from highest to lowest.

the variable is saved with the name of $ran the index is the cla id and the value is the time.

I can print the results but I want him to put in descending order the result of the value column.

 

thks.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  78
  • Topics Per Day:  0.03
  • Content Count:  436
  • Reputation:   167
  • Joined:  12/12/17
  • Last Seen:  

I think storing it on a separate sql table would save you the hassle...
or you can do something like this for ascending order :

 

prontera,151,174,0	script	Arrange Array	100,{
	setarray .@testarray, 1, 5, 3, 4, 9;
	.@size = getarraysize(.@testarray);
	freeloop(1);
	for ( .@i = 0; .@i < .@size; .@i++ ) {
		for ( .@j = (.@i+1); .@j < .@size; .@j++ ) {
			if ( .@testarray[.@i] > .@testarray[.@j] ) { // Reverse the calculation to descend the order
				.@temp = .@testarray[.@i];
				.@testarray[.@i] = .@testarray[.@j];
				.@testarray[.@j] = .@temp;
			}
		}
	}
	freeloop(0);
	mes "Check :";
	for ( .@i = 0; .@i < .@size; .@i++ )
		mes "Test "+ .@testarray[.@i];
	close;

}

 

Edited by pajodex
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  5
  • Reputation:   1
  • Joined:  06/13/13
  • Last Seen:  

Well, Pajodex, creating a custom table is the best solution I even did it but I wanted to avoid querying the table or updating any changes that need to be made.

This tip of yours already satisfied me. I'm going to use it and thanks a lot for the help.

Link to comment
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.   Paste as plain text instead

  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.

×
×
  • Create New...