Am trying to add this line "bind join -|- * pub_hangmanstart" below to make the game auto start when anyone joins the room. But I get the error [07:43] Tcl error [pub_hangmanstart]: wrong # args: should be "pub_hangmanstart nick uhost hand chan rest"
The problem is the pub bind passes one too many arguments (rest) which is the rest of the input the user types. When a join occurs this argument is omitted. You can use the code below to achieve what your after
bind pub -|- [cmdchar]hangmanstart pub_hangmanstart
bind join -|- * join_hangmanstart
proc join_hangmanstart {nick uhost hand chan} {
pub_hangmanstart $nick $uhost $hand $chan "1"
}
proc pub_hangmanstart {nick uhost hand chan rest} {
global hangman
if {$hangman(trys) > 0} {putserv "NOTICE $nick :Hangman game allready in progress on $hangman(chan)."
return 0
}
if {($rest > 0) && ($rest <4)} {set hangman(level) $rest}
if {![file exists $hangman(datafile)]} {
putserv "NOTICE $nick :$hangman(datafile) not found."
return 0
}
set rest [hangman_pick]
set hangman(started) "RandomSelection"
hangman_start $chan $nick $rest
}
The join proc invokes the normal pub proc. It sets rest as "1" which will set the hangman level to 1. Since join doesn't allow the user to set this, you can modify the line below to the proper level you desire 1-4.
utimer 15 pub_hangmanstart
even tried..
utimer 15 join_hangmanstart
I was hoping that tmer would set off these binds to make game start again..
bind pub -|- [cmdchar]hangmanstart pub_hangmanstart
bind join -|- * join_hangmanstart
proc join_hangmanstart {nick uhost hand chan} {
pub_hangmanstart $nick $uhost $hand $chan "1"
}
Any idea what code I need to set off the proc pub_hangmanstart after it says game over?
That is, IF.. the 4 variable requirements are used within the section where you've added this timer. If not, you will need to somehow re-associate them so that they can be passed through the timer.
proc hangman_abort {tried here} {
global hangman tried here
if {$hangman(dtimer) != ""} {killutimer $hangman(dtimer)}
set chan $hangman(chan)
putquick "PRIVMSG $chan :The hangman game has ended. Next game in 15 seconds.."
putquick "PRIVMSG $chan :Puzzle $hangman(puzzle)"
set hangman(trys) 0
hangman_save
utimer 15 [list join_hangmanstart $nick $uhost $hand $chan]
}
proc hangman_abort {tried here} {
global hangman tried here
if {$hangman(dtimer) != ""} {killutimer $hangman(dtimer)}
set chan $hangman(chan)
putquick "PRIVMSG $chan :The hangman game has ended. Next game in 15 seconds.."
putquick "PRIVMSG $chan :Puzzle $hangman(puzzle)"
set hangman(trys) 0
hangman_save
}
See up above, how chan is set using $hangman(chan). $hangman(chan) is a global variable. The global line contains the array's prefix, hangman. So all within that array are localized as well. This is how that script is using re-association within itself. Note: notice the passed variables 'tried' and 'here' are also globalized. This is a cheap way to pass local variables into global space.
The easiest way to do this yourself is to make new globals to use to invoke at the end of your timer. So choose a new array, say restarthangman. Then to carry these across to your timer, add these to the beginning of the pub_hangmanstart proc:
set $::restarthangman(nick) $nick
set $::restarthangman(uhost) $uhost
set $::restarthangman(hand) $hand
set $::restarthangman(chan) $chan
They need to be named like this and then it will work.
Also, recheck your script. You will have an error again regarding arguments. You've somehow removed the join proc and are binding it again to the pub proc. You can't do this the arguments don't match. This is why you make a stub procedure for join, to add the extra argument rest and then invoke the normal pub procedure.
Use the code I gave above, which has the proper join bound to the join proc and pub to pub, then simply use this proc in place of the one you already have.
proc hangman_abort {tried here} {
global hangman tried here
if {$hangman(dtimer) != ""} {killutimer $hangman(dtimer)}
set chan $hangman(chan)
putquick "PRIVMSG $chan :The hangman game has ended. Next game in 15 seconds.."
putquick "PRIVMSG $chan :Puzzle $hangman(puzzle)"
set hangman(trys) 0
hangman_save
utimer 15 [list join_hangmanstart $::restarthangman(nick) $::restarthangman(uhost) $::restarthangman(hand) $::restarthangman(chan)]
}
Tcl error [pub_hangmanstart]: can't read "::restarthangman(nick)": no such variable
HAW, sorry cache.. that was me being a dumbass. Setting isn't allowed to the value, and setting to the name doesn't require the $. This was my mistake. ;/
How do I make a join bind for this one
I tried code from post #2 in this thread by speechles but I don't get what text this code below is asking for...
I also put in....
bind join - * tgstart
but it says: Tcl error [tgstart]: wrong # args: should be "tgstart nick host hand chan text"
###############################################################################
#starts the game if it isn't running.
proc tgstart {nick host hand chan text} {
global tgplaying tgstreak tgchan tgerrremindtime tgerrremindtimer tgmissed tgchoosecmd tgcheat
if {[strlwr $tgchan]==[strlwr $chan]} {
if {$tgplaying==0} {
if {$tgcheat != "ON"} {set tgcheat "OFF"}
tggamemsg "Trivia Game Started."
tgnextq
set tgplaying 1
set tgstreak 0
set tgmissed 0
set tgerrremindtimer [timer $tgerrremindtime tgerrremind]
}
}
}