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 

a list problem

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


Joined: 19 Jul 2006
Posts: 12

PostPosted: Thu Aug 10, 2006 8:37 am    Post subject: a list problem Reply with quote

Can somebody help me to do the following.

On a command lets say !add the user can add a value to a list.

Lets say the user type:
!add test
!add test2

Then the list should contains test;test2 seperated by a ;

If the user type again
!add test2
it should not be added to the list saying its already in.

If the user types
!del test

the value test should be deleted in the list.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Aug 10, 2006 9:23 am    Post subject: Reply with quote

Have a look at the list commands in tcl: list, lappend, lsearch, lreplace

Roughly tho, something like this (not complete code):
Code:

#add:
proc addlist {what} {
 global mylist
 if {[lsearch $mylist $what] == -1} {
  lappend mylist $what
 }
}

#delete:
proc dellist {what} {
 global mylist
 set i [lsearch $mylist $what]
 set mylist [lreplace $mylist $i $i]
}

#Get "proper" layout, separate with ; instead...
proc getproper {} {
 global mylist
 return [join $mylist ";"]
}


Not complete code, but should give you a decent example on how to use those commands
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
keeper2
Voice


Joined: 19 Jul 2006
Posts: 12

PostPosted: Thu Aug 10, 2006 10:03 am    Post subject: Reply with quote

yes I worked it out Smile was not so difficult as I think before your code help to find the way.
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