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.
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.
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"
}