Jump to content
  • 0

Print array result in order


Question

Posted

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.

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

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
  • 0
Posted

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.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...