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.

Procedure in a procedure?

Old posts that have not been replied to for several years.
Locked
o
otterboyy

Post by otterboyy »

After several months delay, I find myself up against a wall and having to learn IRCD's, Eggbot in general and TCL so I can have custom actions done for a company I work for.

With all that, I have gotten to the point of writing my first TCL for Egg and it works well. Now I want to add on to the tcl I have now.
It consists of one bind (!URG) and a procedure to process that bind and do something with the text (send PRVMSG to all in channel). Simple, yet effective for what I need. Now what I want to do is to take the text of that message and write it out to a file, formated in HTML.
I feel I can do that, but in the interests of being modular, I would like to write it in another tcl file or procedure and call it from the urgmsg proc I created.
So to sum it up. When the urgmsg proc is fired by the bind !URG, I want to take the text that follows !URG and write it to a file in HTML format.
So can I create this 2nd proc and call it from with in the first?

Thanks in advance!

Otterboyy
Z
Zygomaticum

Post by Zygomaticum »

yes u can :smile:

greejtz, Zygo.
o
otterboyy

Post by otterboyy »

So I can do something like

Proc name {args} {
if {condition} {
do this
} else {
do this
call proc {args}
}
}

The "call proc {args}" was made up by me. Not sure if thats the format or not.
Could you, or someone provide a sample?
To be clear, I would like to pass the argument $args to the second proc for processing further.

Thanks again!

Otterboy
Z
Zygomaticum

Post by Zygomaticum »

nop

use something like this:

proc proc1 { arg } {
set var [proc2]
}

proc proc2 { arg } {
return 1
}

$var in proc1 will get the value 1, proc2 returns 1 to $var
or just type this in a proc:
proc2

and proc2 will be runned
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Calling your own procedure is exactly like calling any of tcl's builtin ones (puts, open, close, etc). Check out http://dev.scriptics.com for detailed help with tcl syntax.

Code: Select all

proc firstproc {text} {
  if {[string match $text "*sheep*"] == 1} {
    secondproc "Sheep" $text
  } elseif {[string match $text "*goat*"] == 1} {
    secondproc "Goats" $text
  } else {
    putlog "off-topic discussion detected!"
  }
}

proc secondproc {title line} {
  # open file for appending
  set fp [open /home/apache/www/animals.html a+]
  puts $fp "<b>$title</b>: $line<br>"
  close $fp
}
o
otterboyy

Post by otterboyy »

Thank you very much! this is exactly what I am looking for.
Now after 2 server crashes in 12 hours, perhaps I can get back to the script.

Again. Thank you!!!

Otterboyy
Locked