I'm working on the new major rebuild of this script and one of the functions (which I've got working perfectly apart from this exception) is that instead of having to issue the command !start for each question you can now issue !start ** (where ** represents the number of questions you want in the round) up to a max number of questions preconfigured in the script and also configurable with a public command. Its one of the most commonly requested updates people email me about constantly. Anyway I've got it working for the most part, there is now a public command that picks up the number of questions requested, checks it against the maximum number configured and then starts a counter, the questions then start and off it goes. I've got it working for two out of three scenarios so far, if you get the answer right and its your first ever win and if you get it right and you've won before (different parts of a proc for each so the code to return to the counter proc was required in both places).
The issue I'm having is that when no one gets the answer right there is a utimer that kicks in and sends it to another proc which basically was designed to tell them they didnt get it right and reset all functions, stopping the game. As nobody got it right, it didnt need to know any of the normal variables (nick uhost hand chan) so they quite rightly aren't declared at the beginning of the proc. Here's the issue, because the other procs (the counter and the main game start code require those variables, the no_answer proc isnt passing all the information back to them and the script errors out. If I add the variables to the code it simply gives the usual, null value for x error and errors out again. I cant for the life of me (and no doubt its simple) get it to return to the counter proc with the right information for the counter to carry on the round and start asking questions again.
Here's the relevant pieces of code, can someone show this silly old fool what he's doing wrong please.
This is part of the new code that checks if this is a multiple question round or not and plays the game accordingly by running "start_game".
Code: Select all
#Are we playing more than one question at a time and is it within the maximum set in the config at the top?
proc start_game_check {nick uhost handle channel args} {
global questtoask maxquesttoask
set questtoask [lindex $args 0]
if {$questtoask == ""} {
start_game $nick $uhost $handle $channel
} else {
if {$questtoask > $maxquesttoask} {
putserv "PRIVMSG $channel :Sorry\002\ $nick\002 the maximum number of questions per round is set to\002\ $maxquesttoask\002, please retry."
return 0
}
count_questions $nick $uhost $handle $channel
}
}
#Procedure to keep count of and track the number of questions asked in a round.
proc count_questions {nick uhost handle channel args} {
global questtoask questannounce
if {$questtoask == ""} {
return 0
} else {
if {$questtoask == "0"} {
putserv "PRIVMSG $channel :That is the end of the current round."
set questtoask ""
return 0
} else {
if {($questannounce == "1") && ($questtoask == "1")} {
putserv "PRIVMSG $channel :This is the last question in this round"
set questtoask [expr $questtoask-1]
} elseif {($questannounce == "1") && ($questtoask > "1")} {
putserv "PRIVMSG $channel :There are $questtoask questions left in this round"
set questtoask [expr $questtoask-1]
} else {
set questtoask ""
set gameplaying "0"
return 0
}
start_game $nick $uhost $handle $channel
}
}
}
Code: Select all
set ques_pair [lindex $quest $questionno]
set puzzle [lindex [split $ques_pair :] 1]
set answer [lindex [split $::ques_pair :] 0]
#DEBUG LINE - SHOWS ANSWER BEFORE QUESTION FOR TESTING PURPOSES ONLY
putserv "PRIVMSG $chan :DEBUG - $answer"
bind pubm -|- * answercheck
putserv "PRIVMSG $chan :Question.......\00304$puzzle"
incr questionno
utimer 25 no_answer
setuser $player XTRA wcount.$chan $questionno
Code: Select all
proc answercheck {nick uhost handle channel arg} {
global answer
if {[string equal -nocase $answer $arg]} {
winner $nick $uhost $handle $channel
}
return
}
Code: Select all
set chan $gamechan
putserv "PRIVMSG $chan :$nick this is your first ever win!!!...\00304Now try and win again!"
set score [lappend score $handle]
set score [lappend score 1]
set score [lappend score 1]
set fd [open $scores w]
foreach line $score {
puts $fd $line
}
close $fd
set gameplaying 0
set chan ""
count_questions $nick $uhost $handle $channel
Code: Select all
#If no one gets it right within the alloted time, stop game and reset.
proc no_answer {} {
global gameplaying answer chan gamechan questtoask giveanswer
set chan $gamechan
if {$giveanswer == "0"} {
putserv "PRIVMSG $chan :No body got it right!!.....\00304Try Again!!"
}
if {$giveanswer == "1"} {
putserv "PRIVMSG $chan :No body got it right!!.....The answer was \00304$answer"
}
kill_timers
unbind pubm -|- * answercheck
set gameplaying 0
set chan ""
count_questions $nick $uhost $handle $channel
return 0
}