This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

How to delete a value in a variable?

Old posts that have not been replied to for several years.
Locked
R
Real
Voice
Posts: 24
Joined: Mon Mar 08, 2004 11:27 am

How to delete a value in a variable?

Post by Real »

Hello

I made a proc which lets people put themselves in the topic, whether or not they are available for a clanwar.

In short this is:

Code: Select all

proc pub_waravail {nick host hand chan text} { 
  global avail
  set myname "[lindex $text 0]" 
  if {($myname != "")} { 
    if {$avail == ""} { 
      set avail "$myname" 
      } else { 
      append avail " $myname" 
    }
    putserv "TOPIC $chan :Available: $avail"
  } 
}
However, there should also be a !remove command. So if e.g. $avail = playerA playerB playerC, and somebody says !remove playerB, only playerA and playerC remain

Is this possible?
I've already made this with different variables, but it's a LOT of code, and there are a lot of spaces in the topic :(
It looks like this:

Code: Select all

if {$avail1 == ""} { 
      set avail1 $myname
	putserv "TOPIC $chan :Available: $avail1 $avail2 $avail3 $avail4 $avail5 $avail6 $avail7 $avail8 $avail9 $avail10"
	return      
	} 

if {$avail2 == ""}  {
      set avail2 $myname
	putserv "TOPIC $chan :Available: $avail1 $avail2 $avail3 $avail4 $avail5 $avail6 $avail7 $avail8 $avail9 $avail10"
	return	
	}
So can this be done with just one vars? Thank you :)
d
dollar
Op
Posts: 178
Joined: Tue Oct 28, 2003 3:47 pm
Location: Netherlands

Post by dollar »

Split the string and remove the element with lreplace (http://www.tcl.tk/man/tcl8.4/TclCmd/lreplace.htm)
dollar (or something similar) at:
#eggdrop / #tcl - undernet
#egghelp / #tcl / #eggtcl - efnet
#eggdrop.support / #tcl - quakenet
#eggdrop - ircnet
R
Real
Voice
Posts: 24
Joined: Mon Mar 08, 2004 11:27 am

Post by Real »

dollar wrote:Split the string and remove the element with lreplace (http://www.tcl.tk/man/tcl8.4/TclCmd/lreplace.htm)
Sorry but I have no idea how to do that :)
Could you give me an example or anything?

Thanks
s
spyda
Halfop
Posts: 64
Joined: Mon Aug 12, 2002 2:22 am
Location: Australia

this might help :)

Post by spyda »

You can use a few types of code.

Code: Select all

bind PUB - !remove remove:name

proc remove:name {nick uhost hand chan text} {
   global avail
   #### Any check you need in here ####
   set who [lindex [split $text] 0]
   set newavail ""
   foreach takeout [split $avail] {
      if {[string match $takeout $who]} {
         set removed $takeout
      } else {
         append newavail "$takeout "
      }
   }
   putquick "NOTICE $nick :Removed $removed - Left $newavail"
}
This will work with /msg $botnick !remove <nick>
And also is untested.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

An basic search and remove:

Code: Select all

set place [lsearch $variable "your thing"]
set result [lreplace $result $place $place]
Once the game is over, the king and the pawn go back in the same box.
R
Real
Voice
Posts: 24
Joined: Mon Mar 08, 2004 11:27 am

Post by Real »

thanks caesar, it works perfectly :)
Locked