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.

adding bind join to script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

adding bind join to script

Post by cache »

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: Select all

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
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

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: Select all

pub_hangmanstart $nick $uhost $hand $chan "1"
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Thank you! That works :D
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Am trying tpo get the game to stay on.. after the script where it would say game over...

I added this

Code: Select all

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
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

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.
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

ok thanks :)
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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]
}
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

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: Select all

utimer 15 [list join_hangmanstart $::restarthangman(nick) $::restarthangman(uhost) $::restarthangman(hand) $::restarthangman(chan)]
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Thank you..

Just wonder if I did this right? I get error can't read restarthangman(chan) no such var...

Code: Select all

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 
}
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

cache wrote:Thank you..

Just wonder if I did this right? I get error can't read restarthangman(chan) no such var...

Code: Select all

set $::restarthangman(chan) $nick 
set $::restarthangman(nick) $uhost 
set $::restarthangman(nick) $hand 
set $::restarthangman(nick) $chan

Code: Select all

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: Select all

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: Select all

utimer 15 [list join_hangmanstart $::restarthangman(nick) $::restarthangman(uhost) $::restarthangman(hand) $::restarthangman(chan)]
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

lol sorry trying to understand what part to rename, i just crahed :(
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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: Select all

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)]
}
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

Have it way you showed me but get error when I try to start

Code: Select all

Tcl error [pub_hangmanstart]: can't read "::restarthangman(nick)": no such variable
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

cache wrote:Have it way you showed me but get error when I try to start

Code: Select all

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: Select all

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.. :P

Code: Select all

set ::restarthangman(nick) $nick
set ::restarthangman(uhost) $uhost
set ::restarthangman(hand) $hand
set ::restarthangman(chan) $chan 
c
cache
Master
Posts: 306
Joined: Tue Jan 10, 2006 4:59 am
Location: Mass

Post by cache »

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: Select all

###############################################################################
#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]
		}
	}
}
Post Reply