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.

Can Someone Tell me what wrong with this script?

Old posts that have not been replied to for several years.
Locked
a
an0n

Can Someone Tell me what wrong with this script?

Post by an0n »

Can Some One tell me what, if anything is wrong with this script, or maybe there is a better way to write it?


### Bot Word Reaction ###

bind pub -|- Sony pub_xplod
bind pub -|- sony pub_xplod
bind pub -|- xplod pub_xplod
bind pub -|- Xplod pub_xplod

# random responses to the word "sony" or "xplod"
set ranxplod {
"I'd rather use Jensen"
"Oh, Not the "S" word !!!"
"Xplod, We go boom"
"Red and white, but burnt all over"
"Once you go Sony, you'll never come back"
}

# random sony proc
proc pub_xplod {nick uhost hand chan $ranxplod} {
global ranxplod
if [rand 2] {
putchan $chan "[lindex $ranxplod [rand [llength $ranxplod]]]"
}
return 1
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

The most noticible thing is

Code: Select all

proc pub_xplod {nick uhost hand chan $ranxplod} {
I know many people new to Tcl have dificulties understanding why this line is like it is, but the goal behind this 1 must be out of eyesight.

Can you tell me what this was supposed to do?

The Tcl proc command has the following format
proc <name> {[argument1] [arguemnt2] [arguementX]} {<body>}
<item> = required
[item] = optional

When writting code, you break it down into re-usable functions (in Tcl, they are called procedures), so when a often used peice of code is needed, instead of typing it all out, you simply call that needed code.

When you do this, you will often need to change some fo the items within the code. EG, when you want to remove a certain letter from a string of letters, you need to know the letter that needs removing, and the string to remove it from. There would be no point in making a re-usable function for this, if you are using the same letter and string everytime.

So, to do this, you need some way of knowing the string, and character to remove. To do this, you pass them as arguments to the procedure.

EG, I made a procedure called removeletter. so I call it as

Code: Select all

removeletter "x" i hatxe you"
When you do this, you need some way, to collect this data inside of a procedure. This is what the first line of the proc command is all about.

Thus

Code: Select all

proc testcode {nick uhost hand chan arg} {
This allows for 5 arguements to be passed to this procedure. Each one of them, getting there own name. These names, can be whatever you want, so long as you know, what type of information is being passed to the procedure.

In your example, it is done incorrectly.

Using the information I have provided, and reading a copy of tcl-commands.doc, you should be able to find out what is wrong with the above code.
a
an0n

Post by an0n »

I was just trying to make a bot react on the bound words and randomly choose one of the pre set choices, I have read the tcl-commands.txt and your post, yet the solution avoids me. Thanks for the help, just seems as thou I can't grasp whats wrong.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

In the first piece of code I posted in my reply (in turn, quoted from your script), you have not properly defined the procedure arguments.

The proper arguments are shown in tcl-commands.doc.
Locked