egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

array question

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
romain
Voice


Joined: 16 Oct 2005
Posts: 12

PostPosted: Wed Oct 19, 2005 9:20 am    Post subject: array question Reply with quote

hello,

I have this script
Code:
set ::kick(lolo) 10
set ::kick(lili) 15
set ::kick(kilo) 3
set ::kick(kili) 30

bind pub - !kick pub:test
proc pub:test {nick host hand chan arg} {
 foreach {x y} [array get ::kick] {
  putserv "privmsg $chan : $x with $y kicks"
 }
}


It works.But it's possible to write this list in order decreasing Question


Last edited by romain on Mon Oct 24, 2005 3:58 am; edited 1 time in total
Back to top
View user's profile Send private message
KrzychuG
Master


Joined: 16 Aug 2003
Posts: 306
Location: Torun, Poland

PostPosted: Wed Oct 19, 2005 2:24 pm    Post subject: Reply with quote

Replace
Code:
[array get ::score]

with
Code:
[lsort -decreasing [array get ::score]]

_________________
Que?
Back to top
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Wed Oct 19, 2005 3:54 pm    Post subject: Reply with quote

decreasing in which way? Value or element? For value (which would put the one with the most kicks to the top) you will need to add ' -integer -index 1' to the parameters of lsort.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
romain
Voice


Joined: 16 Oct 2005
Posts: 12

PostPosted: Mon Oct 24, 2005 3:57 am    Post subject: Reply with quote

Hello,

I've more difficulty to write the results like this

Quote:
1. kili with 30 kicks
2. lili with 15 kicks
3. lolo with 10 kicks
4. kilo with 3 kicks


if somebody can help me Question
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Mon Oct 24, 2005 7:08 am    Post subject: Reply with quote

try:
Code:
proc pub:test {nick host hand chan arg} {
  foreach {x y} [array get ::kick] {
    if {[string is integer -s $y]} {
      lappend score [list $x $y]
    }
  }
  set i 1
  foreach {e} [lsort -decreasing -integer -index 1 $score] {
    puthelp "PRIVMSG $chan :$i. [lindex $e 0] with [lindex $e 1] kicks"
    if {[incr i] == 10} {break}
  }
}

if you wonder why I used 2 foreach... the problem is that array get will not return a proper sublist, but just a list which uneven elements are the names and even ones are the values. So first a proper sublist must be created then we can use lsort to sort it Very Happy. Change the '== 10' thing to whatever maximum number of results you want Wink.
btw. the is integer check will prevent possible errors to occur in lsort from unproper array values. Since I dont know the script that created it, I wont trust it Very Happy.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
romain
Voice


Joined: 16 Oct 2005
Posts: 12

PostPosted: Mon Oct 24, 2005 12:13 pm    Post subject: Reply with quote

Yeah, it's ok.
Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber