| View previous topic :: View next topic |
| Author |
Message |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Thu Jan 08, 2009 5:55 pm Post subject: adding bind join to script |
|
|
Hey all.
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"
| Code: |
bind pub -|- [cmdchar]hangmanstart pub_hangmanstart
bind join -|- * pub_hangmanstart
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
} |
Can anyone please show me how or point me in direction to get it to work? Thanks |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Thu Jan 08, 2009 6:53 pm Post subject: |
|
|
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
| Code: | 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. | Code: | | pub_hangmanstart $nick $uhost $hand $chan "1" |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Thu Jan 08, 2009 10:33 pm Post subject: |
|
|
Thank you! That works  |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Jan 11, 2009 5:11 pm Post subject: |
|
|
Am trying tpo get the game to stay on.. after the script where it would say game over...
I added this
| Code: | 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?
Thanks |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jan 11, 2009 5:43 pm Post subject: |
|
|
| Code: | utimer 15 [list join_hangmanstart $nick $uhost $hand $chan]
...or..
utimer 15 [list pub_hangmanstart $nick $uhost $hand $chan $rest]
|
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. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Jan 11, 2009 5:46 pm Post subject: |
|
|
ok thanks  |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Jan 11, 2009 6:11 pm Post subject: |
|
|
Where do I add the 4 varibles?
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]
} |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jan 11, 2009 6:34 pm Post subject: |
|
|
| cache wrote: | Where do I add the 4 varibles?
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: | Code: | set $::restarthangman(nick) $nick
set $::restarthangman(uhost) $uhost
set $::restarthangman(hand) $hand
set $::restarthangman(chan) $chan |
Then add this wherever your presently adding the timer: | Code: | | utimer 15 [list join_hangmanstart $::restarthangman(nick) $::restarthangman(uhost) $::restarthangman(hand) $::restarthangman(chan)] |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Jan 11, 2009 6:48 pm Post subject: |
|
|
Thank you..
Just wonder if I did this right? I get error can't read restarthangman(chan) no such var...
| Code: | bind pub -|- [cmdchar]hangmanstart pub_hangmanstart
bind join -|- * pub_hangmanstart
proc pub_hangmanstart {nick uhost hand chan rest} {
set $::restarthangman(chan) $nick
set $::restarthangman(nick) $uhost
set $::restarthangman(nick) $hand
set $::restarthangman(nick) $chan
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
} |
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jan 11, 2009 6:49 pm Post subject: |
|
|
| cache wrote: | Thank you..
Just wonder if I did this right? I get error can't read restarthangman(chan) no such var...
| Code: | set $::restarthangman(chan) $nick
set $::restarthangman(nick) $uhost
set $::restarthangman(nick) $hand
set $::restarthangman(nick) $chan |
|
| Code: | 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. | Code: | 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
set $::restarthangman(nick) $nick
set $::restarthangman(uhost) $uhost
set $::restarthangman(hand) $hand
set $::restarthangman(chan) $chan
..rest of script continues... |
Then use this timer when the game ends to restart it. | Code: | | utimer 15 [list join_hangmanstart $::restarthangman(nick) $::restarthangman(uhost) $::restarthangman(hand) $::restarthangman(chan)] |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Jan 11, 2009 6:57 pm Post subject: |
|
|
lol sorry trying to understand what part to rename, i just crahed  |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Jan 11, 2009 7:01 pm Post subject: |
|
|
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. | Code: | 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)]
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Sun Jan 11, 2009 7:15 pm Post subject: |
|
|
Have it way you showed me but get error when I try to start
| Code: | | Tcl error [pub_hangmanstart]: can't read "::restarthangman(nick)": no such variable |
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Jan 12, 2009 9:45 pm Post subject: |
|
|
| cache wrote: | Have it way you showed me but get error when I try to start
| Code: | | 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. ;/
| Code: | set $::restarthangman(nick) $nick
set $::restarthangman(uhost) $uhost
set $::restarthangman(hand) $hand
set $::restarthangman(chan) $chan |
Simply remove those $ off the ::'s and everything will work as it should have to begin with, my bad..  | Code: | set ::restarthangman(nick) $nick
set ::restarthangman(uhost) $uhost
set ::restarthangman(hand) $hand
set ::restarthangman(chan) $chan |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
cache Master
Joined: 10 Jan 2006 Posts: 306 Location: Mass
|
Posted: Thu Jan 15, 2009 2:53 am Post subject: |
|
|
Thanks,
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"
| Code: | ###############################################################################
#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]
}
}
} |
|
|
| Back to top |
|
 |
|