I took the liberty of posting your "Tcl script" on a pastebin that has a static Tcl syntax checker and here you can see the result of that (the errors above the code): http://paste.tclhelp.net/?id=8p2
yea, will do. ty, was trying to get my mirc script into tcl and as i've said i've never worked with tcl scripts, so u are right. but calling it "spaghetticode" is veeeery nice of u
bind pubm o|* "!game" game
proc game {nick host hand chan text}
{
if {[string equal -nocase "#channel:!game" $text]} {random_int}
#or add set var text here and return $text or can i leave it at all??
}
proc random_int { }
{
set myrand [expr int(rand() * 7)]
return $myrand
}
{
#if {$myrand == 0} {set $myrand i+1} //<-needed??????????
if {$myrand == 1} {putserv "PRIVMSG #channel:$nick plays TXT1!"}
elseif {$myrand == 2} {putserv "PRIVMSG #channel:$nick plays TXT2!"}
elseif {$myrand == 3} {putserv "PRIVMSG #channel:$nick plays TXT3!"}
elseif {$myrand == 4} {putserv "PRIVMSG #channel:$nick plays TXT4!"}
elseif {$myrand == 5} {putserv "PRIVMSG #channel:$nick plays TXT5!"}
elseif {$myrand == 6} {putserv "PRIVMSG #channel:$nick plays TXT6!"}
elseif {$myrand == 7} {putserv "PRIVMSG #channel:$nick plays TXT7!"}
#endif ???
}
...better?
and the if one is due to the output, it has to be a txt-msg instead of the no. out of the variable
and regarding the first error, i've read:
BIND [type] [Flags] [Event] [NameofProc]
edit:
thommey wrote:I took the liberty of posting your "Tcl script" on a pastebin that has a static Tcl syntax checker and here you can see the result of that (the errors above the code): http://paste.tclhelp.net/?id=8p2
i don't get this static tcl checker -> leaving most of the braces, which i thought were needed from what i've read, removes some errors. guess i have to think over the syntax once again
if {[string equal -nocase "#channel:!game" $text]} {random_int}
can be removed. Instead of a bunch of 'if' and 'elseif' you should use switch. In order to get a random number from 1 to 7 (both included) not from 0 to 6
you need to use [expr [rand 7] +1] to have. Also, the correct definition of a proc is:
While in other coding languages it's rand() in TCL it's [rand]. Also, notice the [ and ] that translate in to calling the function of whatever you got inside.
Once the game is over, the king and the pawn go back in the same box.
just another question for you pro's, would be cool if you could help me there. is it possible to set the trigger so that it will function (in this case) to not only "!game", but also to look in whole sentences like "why dont you type !game while we're at it"
i've tried:
bind pub -|- * !game game
bind pub -|- "* !game" game
bind pub -|- *!game* game
bind pub -|- "*!game*" game
bind pubm -|- "* !game" game
bind pubm -|- "% !game" game
and so on, but nothing works...
i.e. "*!game*" will trigger on *!game* only but not on "is this a !game"
Wildcards such as * and % only works with the matching version of the binding (such as pubm for public channel chat and msgm for private messages). The proper binding would in this case be as follows:
I can't see why the binding I proposed would interfere with bender_quotes, as they don't overlap.
If you were to apply the same kind of binding to the bender_quotes script however, you would have to rewrite the pub_bender proc as "arg" would contain the whole line of text (including the !game trigger), rather than the text following the first word.
With the simple scripts proposed in this thread, that wouldn't be an issue, since they don't care of the content of "text", though.
So you were indeed applying the same kind of binding to the pub_bender proc. Thus, you'll either have to re-write pub_bender, or write a wrapper, to dig out the number from the whole line of text.
The simplest would probably be to write a wrapper, that actually don't bother with digging for the number, but use the random-line operation: