| View previous topic :: View next topic |
| Author |
Message |
keeper2 Voice
Joined: 19 Jul 2006 Posts: 12
|
Posted: Thu Aug 10, 2006 8:37 am Post subject: a list problem |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Aug 10, 2006 9:23 am Post subject: |
|
|
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 |
|
 |
keeper2 Voice
Joined: 19 Jul 2006 Posts: 12
|
Posted: Thu Aug 10, 2006 10:03 am Post subject: |
|
|
yes I worked it out was not so difficult as I think before your code help to find the way. |
|
| Back to top |
|
 |
|