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 array by numeric value

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
perlsaiyan



Joined: 21 Sep 2014
Posts: 21

PostPosted: Sun Aug 30, 2015 11:24 am    Post subject: Sorting array by numeric value Reply with quote

I have an array, with spells and values. I'd like to return a sorted list, such that the elements are in descending order by their value in the original array.


Code:

#var skillList[missile] 1;
#var skillList[flame] 2;
#var skillList[sleep] 3;


Can I generate a list from that, where the elements in order are sleep, flame, missile?
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Mon Aug 31, 2015 4:08 am    Post subject: Reply with quote

This can be a solution if you invert content/index of your array... why are you using it inverted ?

Code:

#list skl create missile flame sleep
#list skl size skl_size
#var
############################ VARIABLES ############################
#VARIABLE {skl}={{1}{missile}{2}{flame}{3}{sleep}}
#VARIABLE {skl_size}={3}

#loop $skl_size 1 cnt {#echo {$skl[$cnt]}}
sleep
flame
missile

#loop $skl_size 1 cnt {#list skl2 add {$skl[$cnt]}}
#var
############################ VARIABLES ############################
#VARIABLE {skl}={{1}{missile}{2}{flame}{3}{sleep}}
#VARIABLE {skl2}={{1}{sleep}{2}{flame}{3}{missile}}
#VARIABLE {skl_size}={3}


If you want to maintain the original value of the spell you should change a bit the format of the content, leaving alone the array index:

Code:

#list skl create [1][missile] [2][flame] [3][sleep]
#var
############################ VARIABLES ############################
#VARIABLE {skl}={{1}{[1][missile]}{2}{[2][flame]}{3}{[3][sleep]}}


so the result of the previous script will become:
Code:
#VARIABLE {skl2}={{1}{[3][sleep]}{2}{[2][flame]}{3}{[1][missile]}}
Back to top
View user's profile Send private message
perlsaiyan



Joined: 21 Sep 2014
Posts: 21

PostPosted: Sun Oct 04, 2015 11:45 am    Post subject: Reply with quote

I have a spell list, I want to assign a weight, so that my "practice all spells" alias will do them in a biased order. That way if I have limited practice sessions, it will choose the most important spells first. I think I'll just create a list in order, and then look it up. I was overthinking it I guess.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Sun Oct 04, 2015 12:39 pm    Post subject: Reply with quote

Then #list is for you.

You can also use the #list INS command to add a spell at some particular position.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion 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