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.

$arg is not being returned?

Help for those learning Tcl or writing their own scripts.
Post Reply
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

$arg is not being returned?

Post by daigo »

Here is my script:

Code: Select all

bind pubm - !give give

set givechan "#daigo"

proc give {nick host hand chan arg} {
  global givechan

  if {$chan eq $::givechan} {
  puthelp "PRIVMSG $givechan :Here is $arg for you"
  }

  return 0
}
But when I do something like: !give milk and cookies
In the channel, but the bot doesn't return anything, not even an error. But if I make the bind pubm as * (bind pubm - * give) then it does work. How come?
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

you need bind pub instead of pubm there...
and you already have "global" line for "givechan" in give proc..
you have to choose one of :

global givechan
.. $givechan

or remove "global" line and just use :

.. $::givechan

Code: Select all

 set givechan "#daigo" 

bind pub - !give pub_give

 proc pub_give {nick host hand chan arg} { 
    # this one is "case sensitive"
     if {$chan eq $::givechan} { 
    
   # you can use string match -nocase or string equal -nocase
   # if {[string match -nocase $::givechan $chan]} {  
   # if {[string equal -nocase $::givechan $chan]} {

   # or add a line outside of the proc , an user defined channel flag  
   # setudef flag something 
   # and add a line just under the proc line to check this channel flag 
   #  activated or not 
   # if {[channel get $chan something]} {
   # and no need to set givechan "..." 
   # do : .chanset #your-channel +something 
   # voilà  if you would go this way ,don't forget to replace all 
   # $::givechan vars to $chan in proc too...

     # !cmd first Word to last Word. it takes whole line.
       set given [join [lrange [split $arg] 0 end]] 

      # if you want to post !cmd first-word :
      # set given [lindex [split $arg] 0]

      #  or if you want to post !cmd three-words :
      # set given [join [lrange [split $arg] 0 2]]

       puthelp "PRIVMSG $::givechan :Here is $given for you"
       return 0
      }  
 } 
 

Life iS Just a dReaM oN tHE wAy to DeaTh
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

Post by daigo »

For the last 3 lines, what is the difference between:

Code: Select all

       return 0
      } 
 } 
and

Code: Select all

      }
  return 0 
 } 
User avatar
CrazyCat
Revered One
Posts: 1334
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

There's no difference in the placement of the return with this "simple" procedure, but there is a condition in it. So it's better to have the return exactly when needed.

And I agree with the inline comment from heartbroken : use a nocase comparison for channel name, because if you do:

Code: Select all

# In party-line
.+chan #DaIgO

# In tcl
set givechan "#daigo"
The eggdrop will see that the channel is #DaIgO, doesn't equal #daigo.
Post Reply