TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Sorting a multicolumn list....

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
new_to_tin_tin



Joined: 05 Jan 2011
Posts: 36

PostPosted: Sun Nov 12, 2017 7:44 pm    Post subject: Sorting a multicolumn list.... Reply with quote

I have a #list that looks like this:

Code:
#VARIABLE {item_list}={
{1}{{expire}{126636}{objectid}{1884442523}}
{2}{{expire}{161427}{objectid}{1884442522}}
{3}{{expire}{178333}{objectid}{1884442524}}
{4}{{expire}{145987}{objectid}{1884442525}}
{5}{{expire}{142968}{objectid}{1884442528}}
{6}{{expire}{152922}{objectid}{1884442529}}
}


I'd like to from the lowest expire to the highest. Is there any easy way to do this using a list function?
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Tue Nov 14, 2017 8:28 am    Post subject: Reply with quote

I suppose you'll need an index list for this

Code:

#var item_sorted {};
#foreach $item_list[] cnt {#var item_sorted[$item_list[$cnt][expire]] {$cnt}}
#list item_sorted sort


Now you have a sorted list with just the expire and the index number as a reference.

Then you can use that index like this:

Code:

#foreach $item_sorted[] cnt {#show $item_list[$item_sorted[$cnt]]}

{expire}{126636}{objectid}{1884442523}
{expire}{142968}{objectid}{1884442528}
{expire}{145987}{objectid}{1884442525}
{expire}{152922}{objectid}{1884442529}
{expire}{161427}{objectid}{1884442522}
{expire}{178333}{objectid}{1884442524}


or like this to manually get single entries

Code:

#show $item_list[$item_sorted[+1]]
{expire}{126636}{objectid}{1884442523}

#show $item_list[$item_sorted[+5]]
{expire}{161427}{objectid}{1884442522}
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Wed Nov 15, 2017 9:31 pm    Post subject: Reply with quote

Could also convert it to a table.

Code:

#foreach $item_list[] cnt
{
  #var {item_table[$item_list[$cnt][expire].$item_table[$item_list[$cnt][objectid]]}
  {
    {expire} {$item_list[$cnt][expire]}
    {objectid} {$item_list[$cnt][objectid}
  }
}


Then use $item_table[+1][objectid] to access the first item.

To remove it: #unvar item_table[+1]
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group