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.

reverse script

Old posts that have not been replied to for several years.
Locked
T
Tzion

reverse script

Post by Tzion »

hi guys.
i'm new to eggdrop tcl. i have a script in mirc scripting that is reversing the word... like: hello-->olleh.
can you give me direction on how to build script like that in eggdrop tcl, i think it's loops, but can you give example on that?
thanks.
User avatar
CrazyCat
Revered One
Posts: 1286
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

use string functions:

Code: Select all

bind pub - "!reverse" reverse

proc reverse {nick uhost handle chan args} {
   if {[string length $args] == 0} { return 0 }
   set new ""
   for { set len 0} {$len < [string length $args]} {incr len} {
      set pos {[string length $args] - $len}
      append new [string range $pos 1]
   }
   putserv "PRIVMSG $chan :$new"
}
Not verified, but might be near of the solution
User avatar
Souperman
Halfop
Posts: 69
Joined: Sat Feb 02, 2002 8:00 pm
Location: Cape Town, South Africa
Contact:

Post by Souperman »

CrazyCat wrote:use string functions:

Code: Select all

bind pub - "!reverse" reverse

proc reverse {nick uhost handle chan args} {
   if {[string length $args] == 0} { return 0 }
   set new ""
   for { set len 0} {$len < [string length $args]} {incr len} {
      set pos {[string length $args] - $len}
      append new [string range $pos 1]
   }
   putserv "PRIVMSG $chan :$new"
}
Not verified, but might be near of the solution
Please be careful of using string and list commands. Do not use string commands on lists or vice versa. Read http://www.peterre.com/characters.html for more info on this.

In case you didn't know:
man n proc wrote: If the last formal argument has the name args, then a call to the procedure may contain more actual arguments than the procedure has formals. In this case, all of the actual arguments starting at the one that would be assigned to args are combined into a list (as if the list command had been used); this combined value is assigned to the local variable args.
So, in your example, you are using the Tcl "string" command on $args, which is actually a list. :wink:

Code: Select all

bind pub - "!reverse" reverse

proc reverse {nick uhost hand chan args} {
        if {[llength $args] == 0} { return }

        # join converts a list to a string
        set in [join $args]

        set out ""

        # loop through the given text backwards, appending each
        # character to $out.
        for {set x [expr [string length $in] - 1]} {$x >= 0} {incr x -1} {
                append out [string index $in $x]
        }

        # say the reversed string on channel
        puthelp "PRIVMSG $chan :$out"
}
8)
Quick! Somebody get me a new ink cartridge
User avatar
CrazyCat
Revered One
Posts: 1286
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

sorry :)
Tzion just want directions, so I just type a quick-comin idea :)
Locked