egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

trivia tcl by Harry Scarry - script has error
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Sun Apr 13, 2008 5:49 pm    Post subject: trivia tcl by Harry Scarry - script has error Reply with quote

I need help fixing this error, can anyone please show me what to change?

Error I get is when im turning the game on using !start

Tcl error [tgstart]: can't read "tgmaxhintcurrent": no such variable


Code:
######################################################################
#PLEASE customise the settings before rehashing your bot!            #
######################################################################
#This is the enhanced version of original version Trivia.tcl made by Souperman.
#Enhanced with a !choose option for multiple question files.
#Reason for the adjustment was purely to have an *Nerd* version with all
#kinds of exams like MCSE MCSA CCISP or whatever those whizzkids want.
#
#
#
#      
#
#Enhancements:
#The questionfiles can handle tabs for better editting and manipulation
#eg with a spreadsheet using tabs as a seperator.
#When the next question is selected, all tabs will be removed.
#
#The questionfiles can be setup to use multiplechoice questions.
#The script will determine if a question is a multiplechoice or not.
#If not, it will sendout the question on one line.
#If it is, it will sendout the question and choices on different lines.
#
#This is the layout for them:
#Answer|Question   $A:choice   $B:choice   $C:choice $D:choice   $E:choice
#It doenst matter how many choices there are, the script will figure it out.
#lowercase uppercase... it doesnt matter.

#Cheat protection for blocking people from just trying and guessing.
#This is especially handy with multiplechoice question with one answer.
#They have to wait for the next hint or answer.
#
#   Greetings Hairy_Scary@hotmail.com 21-06-2004
###########################################################################

#  The full path to the file containing the questions and answers.
#  The account the bot runs on must have read access to this file.
#  This is the default question file used at startup
set tgqdb "scripts/demoquestions.txt"

#Set your questions data files here
#If u dont use one of them
#use <return> as seperator or put everything on one line with a space!! eg: set questionfiles"file&desc file&desc file&desc"   
#The first line contains the default database set above
set questionfiles "$tgqdb&default
scripts/demoquestions.txt&demo
scripts/ccnaquestions.txt&CCNA"

#   What trigger should be used for changing the category?
set tgchoosecmd "!choose"

set tgcommandlist $tgchoosecmd$
#  Flags required to be able to use the reset command.
set tgflagschoose "-|-"

#  The character that seperates the question and the answer in the
#  question/answer file.
set tgqdbsep "|"
#  The character that seperates the multiplechoices in the
# question/answer file.
set tgmultiplesep "$"
# The factor u want the hints delayd by multiplechoice questions
# This is not used by setting the next question
# 2 is a fairly good one.
set tgmultifact 2

#Do you allow cheaters in ur channel? eg. people just typing in all the possible answers?
#This is especially useful for preventing cheating on multiplechoice questions.
#The user is put on a list and has to wait until the next hint or new question.
#Set this to ON or OFF.
set tgcheat "ON"

#  What you set here defines how the bot expects the question/answer
#  pairs to be arranged.
#  If set to 1, bot expects lines in the format:
#    question<seperator>answer
#  If set to 0, bot expects lines in the format:
#    answer<seperator>question
set tgqdbquestionfirst 0

#  The full path to the file which tracks the scores. The account
#  the bot runs on must have read & write access to this file. If
#  the file does not exist, it will be created when needed.
set tgscf "scripts/trivia.scores"

#  How to send error reports. Set to 1 to send error report to an
#  e-mail address of your choice, or 0 to record errors in a file.
#  Sending via e-mail requires that the bot have access to the "mail"
#  program. If the bot doesn't have access to this program (e.g. if
#  you're running the bot on the Windows platform), then set this to
#  0 to have errors recorded in a file.
set tgerrmethod 1

#  The full path to the file which records error reports. The
#  account the bot runs on must have read & write access to this
#  file. If the file does not exist, it will be created when needed.
set tgerrfil "scripts/trivia.errors"

#  The e-mail address to send error reports to.
set tgerremail "hairy_scary@hotmail.com"

#  If error reports are sent via e-mail, where will the bot create
#  a temp file? /tmp is usually a good idea.
set tgerrmailtmp "/tmp"

#  The full path to the file which the bot will use to generate
#  an HTML info page. The account the bot runs on must have read
#  & write access to this file. If the file does not exist, it will
#  be created when needed.
set tghtmlfile "public_html/mychan.html"

#  How often (in seconds) does the html file get updated. Set to 0
#  to disable HTML page.
set tghtmlrefresh 0

#  The font to use on the html page.
set tghtmlfont "verdana,helvetica,arial"

#  The name of the channel where the game will be played. The game
#  can only be played on one channel.
set tgchan "#bots"

#  How many points to give a person for a correctly answered
#  question.
set tgpointsperanswer 1

#  The maximum number of hints to give before the question 'expires'
#  and the bot goes on to another one. This EXCLUDES the first hint
#  given as the question is asked (i.e. the hint which shows no letters,
#  only placeholders).
set tgmaxhint 3

#  Should the bot show the question on each hint (1) or only on the first (0)?
set tgalwaysshowq 1

#  Show questions in all CAPS (1) or not (0)?
set tgcapsquestion 0

#  Show answers in all CAPS (1) or not (0)?
set tgcapsanswer 0

#  Show hints in all CAPS (1) or not (0)?
set tgcapshint 0

#  The minimum number of correct answers in a row by one person which
#  puts them on a winning streak. Setting this to 0 will disable the
#  winning streak feature.
set tgstreakmin 3

#  The number of missed (i.e. unanswered, not skipped) questions to allow
#  before automatically stopping the game. Setting this to 0 will cause the
#  game to run until somebody uses the stop command, or the bot dies, gets
#  killed, pings out, or whatever.
set tgmaxmissed 3

#  The character to use as a placeholder in hints.
set tghintchar "."

#  The time in seconds between hints.
set tgtimehint 20

#  The time in seconds between a correct answer, 'expired' or skipped question
#  and the next question being asked.
set tgtimenext 10

#  Phrases to use at random when someone answers a question correctly. This must
#  be a TCL list. If you don't know what that means, stick to the defaults.
set tgcongrats [list "Congratulations" "Well done" "Nice going" "Way to go" "You got it" "That's the way" "Show 'em how it's done" "Check out the big brain on"]

#  Phrases to use when the question has 'expired'. Must also be a TCL list.
set tgnobodygotit [list "Nobody got it right." "Hello? Anybody home?" "You're going to have to try harder!" "Are these too tough for you?" "Am I alone here or what?" "You're not going to score any points this way!"]

#  Phrases to use when the question expired and there's another one coming up.
#  Yep, you guessed it... another TCL list.
set tgtrythenextone [list "Let's see if you can get the next one..." "Get ready for the next one..." "Maybe you'll get the next one..." "Try and get the next one..." "Here comes the next one..."]

#  Will the bot calculate the time it took to get the correct
#  answer (1) or not (0)? (requires TCL 8.3 or higher).
#  With a lot of multiple choice questions the timer gets out of sync.
set tgtimeanswer 0

#  Will the bot show the correct answer if nobody gets it (1) or not (0)?
set tgshowanswer 1

#  When someone answers a question, will the bot show just that person's score (0)
#  or will it show all players' scores (1) (default). This is useful in channels with
#  a large number (>20) players.
set tgshowallscores 1

#  Use bold codes in messages (1) or not (0)?
set tgusebold 0

#  Send private messages using /msg (1) or not (0)?
#  If set to 0, private messages will be sent using /notice
set tgpriv2msg 0

#  Word to use as /msg command to give help.
#  e.g. set tgcmdhelp "helpme" will make the bot give help when someone
#  does "/msg <botnick> helpme"
set tgcmdhelp "?"

#  Channel command used to start the game.
set tgcmdstart "!start"

#  Flags required to be able to use the start command.
set tgflagsstart "-|-"

#  Channel command used to stop the game.
set tgcmdstop "!stop"

#  Flags required to be able to use the stop command.
set tgflagsstop "-|-"

#  Channel command used to give a hint.
set tgcmdhint "!hint"

#  Flags required to be able to use the hint command.
set tgflagshint "-|-"

#  Disable the !hint command x seconds after someone uses it. This
#  prevents accidental double hints if two people use the command in
#  quick succession.
set tgtempnohint 10

#  Channel command used to skip the question.
set tgcmdskip "!skip"

#  Flags required to be able to use the skip command.
set tgflagsskip "-|-"

#  Channel command for showing the top 10 scores.
set tgcmdtop10 "!top10"

#  Flags required to use the top 10 command.
set tgflagstop10 "-|-"

#  /msg command used to reset scores.
set tgcmdreset "reset"

#  Flags required to be able to use the reset command.
set tgflagsreset "m|m"

#  Require password for resetting scores?
#  If enabled, you must use /msg bot reset <password> to reset scores.
#  The password is the one set by a user using '/msg bot pass'.
set tgresetreqpw 1

#  /msg command for looking up somebody's score.
set tgcmdlookup "score"

#  /msg command for looking up your target.
#  (i.e. the person ranked one higher than you).
set tgcmdtarget "target"

#  /msg command for reporting errors in questions and/or answers.
set tgcmderror "error"

#  /msg command to show channel's rules.
set tgcmdrules "rules"

#  Channel's rules.
set tgrules "No advertising, no profanity, no harassing of users, no active scripts and no flooding. Break the rules and expect to be banned. Have fun. :-)"

#  Number of minutes between reminders of how to report errors.
set tgerrremindtime 15

#  COLOURS
#  The colour codes used are the same as those used by mIRC:
#  00:white        01:black        02:dark blue    03:dark green
#  04:red          05:brown        06:purple       07:orange
#  08:yellow       09:light green  10:turquoise    11:cyan
#  12:light blue   13:magenta      14:dark grey    15:light grey
#
#  Always specify colour codes as two digits, i.e. use "01" for
#  black, not "1".
#  You can specify a background colour using "00,04" (white text
#  on red background).
#  To disable a colour, use "".
#  Note that disabling some colours but not others may yield
#  unexpected results.

set tgcolourstart "03"      ;#Game has started.
set tgcolourstop "04"      ;#Game has stopped.
set tgcolourskip "10"      ;#Question has been skipped.
set tgcolourerr "04"      ;#How to report errors.
set tgcolourmiss "10"      ;#Nobody answered the question.
set tgcolourqhead "04"      ;#Question heading.
set tgcolourqbody "12"      ;#Question text
set tgcolourhint "03"      ;#Hint.
set tgcolourstrk "12"      ;#Person is on a winning streak.
set tgcolourscr1 "04"      ;#Score of person in first place.
set tgcolourscr2 "12"      ;#Score of person in second place.
set tgcolourscr3 "03"      ;#Score of person in third place.
set tgcolourrset "04"      ;#Scores have been reset.
set tgcolourstend "12"      ;#Winning streak ended.
set tgcolourmisc1 "06"      ;#Miscellaneous colour #1.
set tgcolourmisc2 "04"      ;#Miscellaneous colour #2.
set tgcolourmpca "00,04"   ;#Color of multiplechoice answer code

set tgwrngansw " "


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#                                                                   #
#    Any editing done beyond this point is done at your own risk!   #
#                                                                   #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#Misc checks & var initialisations
set tgver "1.3.4"
set tgrel "release"
if {[info tclversion]<8.2} {
   putlog "\002[file tail [info script]]\002 failed to load: in order to use this script, eggdrop needs to be compiled to use tcl 8.2 or higher (recommended: latest stable version)."
   return
}
if {$tgtimeanswer==1&&[info tclversion]<8.3} {
   putlog "\002[file tail [info script]]\002 warning: timing of answers has been automatically disabled. this feature requires tcl 8.3 or higher."
   set tgtimeanswer 0
}
if {![info exists alltools_loaded]||$allt_version<205} {
   putlog "\002[file tail [info script]]\002 failed to load: please load alltools.tcl v1.14 or higher (available with eggdrop 1.6.13 or higher) before attempting to load this script."
   return
}
if {[utimerexists tghtml]!=""} {killutimer $tghtmlrefreshtimer}
if {$tghtmlrefresh>0} {
   set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}
if {![file exists $tgqdb]} {
   putlog "\002[file tail [info script]]\002 failed to load: $tgqdb does not exist."
   return
}
if {[llength [split $tgchan]]!=1} {
   putlog "\002[file tail [info script]]\002 failed to load: too many channels specified."
   return
}
if {![info exists tgplaying]} {
   set ctcp-version "${ctcp-version} Triviaplus.tcl M.C.-questions and categories. Based upon $tgver ($tgrel) from www.eggdrop.za.net)"
   set tgplaying 0
}
if {![info exists tghintnum]} {set tghintnum 0}
if {![info exists tgmissed]} {set tgmissed 0}

#Binds
bind pubm $tgflagsstart "$tgchan %$tgcmdstart" tgstart
bind pubm $tgflagsstop "$tgchan %$tgcmdstop" tgstop
proc tgbindhintcmd {} {
   global tgflagshint tgcmdhint
   bind pubm $tgflagshint "$::tgchan %$tgcmdhint" tgforcehint
}
proc tgunbindhintcmd {} {
   global tgflagshint tgcmdhint
   unbind pubm $tgflagshint "$::tgchan %$tgcmdhint" tgforcehint
}
tgbindhintcmd
bind pubm $tgflagsskip "$tgchan %$tgcmdskip" tgskip
bind pubm $tgflagstop10 "$tgchan %$tgcmdtop10" tgshowtop10
bind join -|- "$tgchan *" tgjoinmsg
bind msg - $tgcmdhelp tggivehelp
bind msg - $tgcmdlookup tgscorelookup
bind msg - $tgcmdtarget tgtargetlookup
bind msg - $tgcmderror tgerror
bind msg - $tgcmdrules tgrulesmsg
bind msg $tgflagsreset "$tgcmdreset" tgresetscores
bind kick - "$tgchan $botnick" tgbotgotkicked
bind evnt - disconnect-server tgbotgotdisconnected


#this is the new choose command
bind pubm $tgflagschoose "$tgchan %$tgchoosecmd" give_choicenew
proc give_choicenew {nick uhost handle channel args} {
 global questions tgplaying tgqdb quest usedq questionno questionfiles gameplaying gameonoff chan tgquestionstotal tgtotalquestfiles tgquestionfiles tgset_catgentrig tgchoosecmd
  if {$tgplaying != 0} {
  putserv "PRIVMSG $channel :Game is already running, please either wait for it to finish or enter !stop (if ur autorized) then $tgchoosecmd again to set category"
   return
}
   set questionno 0
   set quest ""
   set usedq ""
   set tgset_catgentrig ""
set tgquestionfiles [split $questionfiles]
set tgtotalquestfiles [llength $questionfiles]
       set i 0
         while {$i<$tgtotalquestfiles} {
         set tgfilename [lindex [split [lindex $tgquestionfiles $i] &] 0]
         set tgdesc [lindex [split [lindex $tgquestionfiles $i] &] 1]
         if {$tgqdb ==$tgfilename} {tggamemsg "[tgcolqbody] Current category:\00304$tgdesc[tgcolqbody] with \00304$tgquestionstotal [tgcolqbody]questions"}
         incr i
         }
         tggamemsg "[tgcolqbody] Current \00304$tgtotalquestfiles\003 [tgcolqbody]categories available."
          set i 0
         set qfile ""
         while {$i<$tgtotalquestfiles} {
         set tgfilename [lindex [split [lindex $tgquestionfiles $i] &] 0]
         set tgdesc [lindex [split [lindex $tgquestionfiles $i] &] 1]
         set qfile [open $tgfilename r]
         set tglist [split [read -nonewline $qfile] "\n"]
         set tgquestioncount [llength $tglist]
         close $qfile
         incr i
         tggamemsg "\00304$tgdesc[tgcolqbody] with \00304$tgquestioncount\003 [tgcolqbody]questions."
            bind pub -|- $tgdesc set_catgen
            lappend tgset_catgentrig $tgdesc
         }
         tggamemsg "[tgcolqbody] Which category u want to use?"
}

#set category
proc set_catgen {nick uhost handle channel text} {
 global tgqdb tgtotalquestfiles tgquestionfiles tgdesc lastbind tgset_catgentrig tgcmdstart
          set i 0
          while {$i<$tgtotalquestfiles} {
         set tgfilename [lindex [split [lindex $tgquestionfiles $i] &] 0]
         set tgdesc [lindex [split [lindex $tgquestionfiles $i] &] 1]
         if {[strlwr $tgdesc] != [tgstripcodes [strlwr [string trim $lastbind]]]} {
         incr i
         }
         if {[strlwr $tgdesc] == [tgstripcodes [strlwr [string trim $lastbind]]]} {
         tggamemsg "[tgcolqbody] Current category set to: \00304$lastbind"
         tggamemsg "[tgcolqbody] Use \00304$tgcmdstart[tgcolqbody] to start the game!"
         set tgqdb $tgfilename
                  set i 0
                   while {$i<$tgtotalquestfiles} {
                   unbind pub -|- [lindex $tgset_catgentrig $i] set_catgen      
                   incr i
                   }
         return
         }   
   }
}
###############################################################################
#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 "[tgcolstart]Trivia game started by $nick! For an other category use: $tgchoosecmd [tgcolstart]The cheat protection is \00304$tgcheat"
         tgnextq
         set tgplaying 1
         set tgstreak 0
         set tgmissed 0
         set tgerrremindtimer [timer $tgerrremindtime tgerrremind]
      }
   }
}


#stops the game if it's running.
proc tgstop {nick host hand chan text} {
   global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak tgstreakmin
   global tgerrremindtimer tgrebindhinttimer
   if {[strlwr $tgchan]==[strlwr $chan]} {
      if {$tgplaying==1} {
         tggamemsg "[tgcolstop]Trivia game stopped by $nick!"
         if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
         set tgstreak 0
         set tgplaying 0
         catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
         if {[utimerexists tghint]!=""} {killutimer $tghinttimer}
         if {[utimerexists tgnextq]!=""} {killutimer $tgnextqtimer}
         if {[timerexists tgerrremind]!=""} {killtimer $tgerrremindtimer}
         if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
      }
   }
}

#gives a hint if there is currently a question to answer.
proc tgforcehint {nick host hand chan text} {
   global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak tgstreakmin
   global tgtempnohint tgmaxhintcurrent tghintnum tgrebindhinttimer tgtempnohint
   if {[strlwr $tgchan]==[strlwr $chan]} {
      if {$tgplaying==1&&[utimerexists tghint]!=""} {
         killutimer $tghinttimer
         tghint
         tgunbindhintcmd
         if {$tghintnum<$tgmaxhintcurrent} {
            set tgrebindhinttimer [utimer $tgtempnohint tgbindhintcmd]
         }
      }
   }
}

#skips the current question if one has been asked.
proc tgskip {nick host hand chan text} {
   global tghinttimer tgnextqtimer tgplaying tgchan tgcurrentanswer tgstreak
   global tgstreakmin tgtimenext tgrebindhinttimer
   if {[strlwr $tgchan]==[strlwr $chan]} {
      if {$tgplaying==1&&[utimerexists tghint]!=""} {
         tggamemsg "[tgcolskip]Skipping to next question by [tgcolmisc2]$nick's[tgcolskip] request..."
         if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin&&[strlwr [lindex [split $tgstreak ,] 0]]==[strlwr $nick]} {
            tgstreakend
            set tgstreak 0
         }
         catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
         killutimer $tghinttimer
         if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
         set tgnextqtimer [utimer $tgtimenext tgnextq]
      }
   }
}

#reminds channel how to report errors in questions/answers
proc tgerrremind {} {
   global tgerrremindtimer tgerrremindtime botnick tgcmderror
   tggamemsg "[tgcolerr]Remember: to report errors in questions/answers, type /msg $botnick $tgcmderror <number> \[description\]"
   set tgerrremindtimer [timer $tgerrremindtime tgerrremind]
}

#bot got kicked. stop the game.
proc tgbotgotkicked {nick host hand chan targ text} {
   tgquietstop
}

#bot got disconnected. stop the game.
proc tgbotgotdisconnected {disconnect-server} {
   tgquietstop
}

#stops the game without telling the channel.
proc tgquietstop {} {
   global tgplaying tgstreak tgchan tgcurrentanswer tghinttimer tgnextqtimer tgerrremindtimer
   global tgrebindhinttimer
   if {$tgplaying==1} {
      set tgstreak 0
      set tgplaying 0
      catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
      if {[utimerexists tghint]!=""} {killutimer $tghinttimer}
      if {[utimerexists tgnextq]!=""} {killutimer $tgnextqtimer}
      if {[timerexists tgerrremind]!=""} {killtimer $tgerrremindtimer}
      if {[utimerexists tgrebindhinttimer]!=""} {killtimer $tgrebindhinttimer}
   }
}

#reads the question database.
proc tgreadqdb {} {
   global tgqdb tgquestionstotal tgquestionslist
   set tgquestionstotal 0
   set tgquestionslist ""
   set qfile [open $tgqdb r]
   set tgquestionslist [split [read -nonewline $qfile] "\n"]
   set tgquestionstotal [llength $tgquestionslist]
   close $qfile
}

#selects the next question.
proc tgnextq {} {
   global tgqdb tgcurrentquestion tgcurrentanswer tgquestionnumber
   global tgquestionstotal tghintnum tgchan tgquestionslist tgqdbsep tgqdbquestionfirst
   global tgcapsquestion tgcapsanswer
   tgreadqdb
   set tgcurrentquestion ""
   set tgcurrentanswer ""
   while {$tgcurrentquestion == ""} {
      set tgquestionnumber [rand [llength $tgquestionslist]]         
      set tgquestionselected [lindex $tgquestionslist $tgquestionnumber]
#Striping all the *mess* leaving alphanumeric.
      set tgquestionselected [tgstripcodes $tgquestionselected]

      set tgcurrentquestion [lindex [split $tgquestionselected $tgqdbsep] [expr $tgqdbquestionfirst^1]]
      if {$tgcapsquestion==1} {
         set tgcurrentquestion [strupr $tgcurrentquestion]
      }
      set tgcurrentanswer [string trim [lindex [split $tgquestionselected $tgqdbsep] $tgqdbquestionfirst]]
      if {$tgcapsanswer==1} {
         set tgcurrentanswer [strupr $tgcurrentanswer]
      }
   }
   unset tghintnum
   tghint
   bind pubm -|- "$tgchan *" tgcheckanswer
   return
}

#shows timed hints.
proc tghint {} {
   global tgmaxhint tghintnum tgcurrentanswer tghinttimer tgchan tgmultiplesep tgmultifact
   global tgtimehint tghintchar tgquestionnumber tgquestionstotal
   global tgcurrentquestion tghintcharsused tgnextqtimer tgtimenext tgstreak tgstreakmin
   global tgnobodygotit tgtrythenextone tgmissed tgmaxmissed tgcmdstart tgshowanswer
   global tgtimestart tgtimeanswer tgalwaysshowq tgmaxhintcurrent tgtempnohint tgcapshint tgwrngansw
   if {[catch {incr tghintnum}]!=0} {
      set tghintnum 0
      regsub -all -- "\[^A-Za-z0-9\]" $tgcurrentanswer "" _hintchars
      set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]
      catch {tgunbindhintcmd}
      if {$tgmaxhintcurrent>0} {
         set tgrebindhinttimer [utimer $tgtempnohint tgbindhintcmd]
      }
   }
   if {$tghintnum >= [expr $tgmaxhintcurrent+1]} {
      incr tgmissed
      set _msg ""
      append _msg "[tgcolmiss][lindex $tgnobodygotit [rand [llength $tgnobodygotit]]]"
      if {$tgshowanswer==1} {
         append _msg " The answer was [tgcolmisc2]$tgcurrentanswer[tgcolmiss]."
      }
      if {$tgmaxmissed>0&&$tgmissed>=$tgmaxmissed} {
         append _msg " That's $tgmissed questions gone by unanswered! The game is now automatically disabled. To start the game again, type $tgcmdstart"
         tgquietstop
      } else {
         append _msg " [lindex $tgtrythenextone [rand [llength $tgtrythenextone]]]"
      }
      tggamemsg "[tgcolmiss]$_msg"
      if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
      set tgstreak 0
      catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
      if {$tgmaxmissed==0||$tgmissed<$tgmaxmissed} {
         set tgnextqtimer [utimer $tgtimenext tgnextq]
      }
      return
   } elseif {$tghintnum == 0} {
      set i 0
      set _hint {}
      set tghintcharsused {}
      foreach word [split $tgcurrentanswer] {
         regsub -all -- "\[A-Za-z0-9\]" $word $tghintchar _current
         lappend _hint $_current
      }
      if {$tgtimeanswer==1} {
         set tgtimestart [clock clicks -milliseconds]
      }
   } elseif {$tghintnum == 1} {
      set i 0
      set _hint {}
      while {$i<[llength [split $tgcurrentanswer]]} {
         set _word [lindex [split $tgcurrentanswer] $i]
         set j 0
         set _newword {}
         while {$j<[strlen $_word]} {
            if {$j==0} {
               append _newword [stridx $_word $j]
               lappend tghintcharsused $i,$j
            } else {
               if {[string is alnum [stridx $_word $j]]} {
                  append _newword $tghintchar
               } else {
                  append _newword [stridx $_word $j]
                  lappend tghintcharsused $i,$j
               }
            }
            incr j
         }
         lappend _hint $_newword
         incr i
      }
      } else {
         set i 0
         set _hint {}
         while {$i<[llength [split $tgcurrentanswer]]} {
            set _word [lindex [split $tgcurrentanswer] $i]
            set j 0
            set _newword {}
            set _selected [rand [strlen $_word]]
            regsub -all -- "\[^A-Za-z0-9\]" $_word "" _wordalnum
            if {[strlen $_wordalnum]>=$tghintnum} {
               while {[lsearch $tghintcharsused $i,$_selected]!=-1||[string is alnum [stridx $_word $_selected]]==0} {
                set _selected [rand [strlen $_word]]
               }
            }
            lappend tghintcharsused $i,$_selected
            while {$j<[strlen $_word]} {
               if {[lsearch $tghintcharsused $i,$j]!=-1||[string is alnum [stridx $_word $j]]==0} {
                  append _newword [stridx $_word $j]
               } else {
                  if {[string is alnum [stridx $_word $j]]} {
                     append _newword $tghintchar
                  }
            }
            incr j
         }
         lappend _hint $_newword
         incr i
      }
   }
   if {$tgcapshint==1} {
      set _hint [strupr $_hint]
   }
   tggamemsg "[tgcolqhead]===== Question [expr $tgquestionnumber+1]/$tgquestionstotal [expr $tghintnum?"(Hint $tghintnum/$tgmaxhintcurrent)":""] ====="
# reseting wronganswer counter
# tggamemsg "resetting wrong answer counter for the hint"
   set tgwrngansw ""
#Detection of a multiplechoice question
set tgmultiple 0   
set tgmultiquestion [split $tgcurrentquestion $tgmultiplesep]
set tgmultiple [llength $tgmultiquestion]
#Normal question
if {$tgmultiple==0} {
if {$tgalwaysshowq==1||$tghintnum==0} {
 
      tggamemsg "[tgcolqbody]$tgcurrentquestion geen multiple"
   }
}
#Detected an multiplechoice
if {$tgmultiple!=0} {
if {$tgalwaysshowq==1||$tghintnum==0} {
      set i 0
         while {$i<$tgmultiple} {
         if {$i==0} {
         tggamemsg "[tgcolqbody][lindex $tgmultiquestion $i]"
         }
         if {$i!=0} {
         set tganswername [strupr [string range [lindex $tgmultiquestion $i] 0 0]]
         set tganswertxt [string range [lindex $tgmultiquestion $i] 2 end]
         tggamemsg "[tgcolmpca]$tganswername\003:[tgcolqbody]$tganswertxt"
         }
         incr i
         }
   }
}
   tggamemsg "[tgcolhint]Hint: [join $_hint]"
   if {$tgmultiple ==0 } {   set tghinttimer [utimer $tgtimehint tghint]}
   if {$tgmultiple !=0 } {   set tghinttimer [utimer [expr $tgtimehint+$i] tghint]}
}

#triggered when someone uses !top10 command
proc tgshowtop10 {nick host hand chan text} {
   global tgscores tgchan tgscorestotal
   if {[strlwr $chan]==[strlwr $tgchan]} {
      tggetscores
      if {$tgscorestotal>0} {
         if {$tgscorestotal>9} {
            set _max 9
         } else {
            set _max [expr $tgscorestotal-1]
         }
         set i 0
         while {$i<=$_max} {
            set _item [lindex $tgscores $i]
            set _nick [join [lindex [split $_item ,] 2]]
            set _score [join [lindex [split $_item ,] 0]]
            if {$i==0} {
               append _scores "[tgcolscr1]$_nick $_score"
            } elseif {$i==1} {
               append _scores ", [tgcolscr2]$_nick $_score"
            } elseif {$i==2} {
               append _scores ", [tgcolscr3]$_nick $_score"
            } else {
               append _scores ", [tgcolmisc1]$_nick $_score"
            }
            incr i
         }
         tggamemsg "[tgcolmisc1]Top 10: $_scores"
      } else {
         tggamemsg "[tgcolmisc1]Score table is empty."
      }
   }
}

#checks if anyone has said the correct answer on channel.
proc tgcheckanswer {nick host hand chan text} {
   global tgcurrentanswer tgwrngansw tgcommandlist tgcheat
#cheat protection on
      if {$tgcheat == "ON"} {
      if {[strlwr $tgcurrentanswer] != [tgstripcodes [strlwr [string trim $text]]]} {
      
      if { ([string length $text] == [string length $tgcurrentanswer]) || [string first $text $tgcommandlist] != -1} {
      set firstone [lsearch $tgwrngansw $nick]
      if {$firstone ==-1} {lappend tgwrngansw $nick}
      if {$firstone !=-1} {tggamemsg "[tgcolstart] You already gave an wrong answer $nick. Wait for the hint or next question"}      
      }
   }
   
    if {[strlwr $tgcurrentanswer] == [tgstripcodes [strlwr [string trim $text]]]} {
          set firstone [lsearch $tgwrngansw $nick]
      if {$firstone ==-1} {
      tgcorrectanswer $nick
         }
      if {$firstone !=-1} {tggamemsg "[tgcolstart] Duh!! You really want me to ignore yah $nick?"}
      }
      return
   }
   
#cheatprotection is not ON
      if {[strlwr $tgcurrentanswer] == [tgstripcodes [strlwr [string trim $text]]]} {
      tgcorrectanswer $nick
      }
}

#triggered when someone says the correct answer.
proc tgcorrectanswer {nick} {
   global tgcurrentanswer tghinttimer tgtimenext tgchan tgnextqtimer tgstreak tgstreakmin
   global tgscoresbyname tgranksbyname tgranksbynum tgcongrats tgscorestotal tgmissed
   global tgtimestart tgshowallscores tgrealnames tgscoresbyrank tgtimeanswer tgwrngansw
   tggetscores
   if {![info exists tgranksbyname([strlwr $nick])]} {
      set _oldrank 0
   } else {
      set _oldrank $tgranksbyname([strlwr $nick])
   }
   tgincrscore $nick
#resetting wrongansw list
   set tgwrngansw ""
   tggetscores
   set _newrank $tgranksbyname([strlwr $nick])
   set _timetoanswer ""
   if {$tgtimeanswer==1} {
      set _timetoanswer [expr [expr [clock clicks -milliseconds]-$tgtimestart]/1000.00]
   }
   set _msg "[tgcolmisc1][lindex $tgcongrats [rand [llength $tgcongrats]]] [tgcolmisc2]$nick[tgcolmisc1]! The answer was [tgcolmisc2]$tgcurrentanswer[tgcolmisc1].[expr $tgtimeanswer==1?" You got it in [tgcolmisc2]$_timetoanswer[tgcolmisc1] seconds.":""]"
   if {$_newrank<$_oldrank} {
      if {$_newrank==1} {
         append _msg " You are now in first place!"
      } else {
         if {$tgshowallscores==0} {
            append _msg " You've moved up in rank!"
         } else {
            append _msg " You are now ranked [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])][tgcolmisc1] of [tgcolmisc2]$tgscorestotal[tgcolmisc1], behind [tgcolmisc2]$tgrealnames($tgranksbynum([expr $_newrank-1]))[tgcolmisc1] with [tgcolmisc2]$tgscoresbyrank([expr $_newrank-1])[tgcolmisc1]."
         }
      }
   }
   tggamemsg "$_msg"
   if {$tgstreak!=0} {
      if {[lindex [split $tgstreak ,] 0]==[strlwr $nick]} {
         set tgstreak [strlwr $nick],[expr [lindex [split $tgstreak ,] 1]+1]
         if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} {
            tggamemsg "[tgcolstrk][tgcolmisc2]$nick[tgcolstrk] is on a winning streak! [tgcolmisc2][lindex [split $tgstreak ,] 1] [tgcolstrk]in a row so far!"
         }
      } else {
         if {$tgstreakmin>0&&[lindex [split $tgstreak ,] 1]>=$tgstreakmin} { tgstreakend }
         set tgstreak [strlwr $nick],1
      }
   } else {
      set tgstreak [strlwr $nick],1
   }
   set tgmissed 0
   tgshowscores $nick
   catch {unbind pubm -|- "$tgchan *" tgcheckanswer}
   killutimer $tghinttimer
   set tgnextqtimer [utimer $tgtimenext tgnextq]
}

#read current scores from file, sort and store in variable.
proc tggetscores {} {
   global tgscf tgscorestotal tgscores tgscoresbyname tgranksbyname tgranksbynum
   global tgrealnames tgscoresbyrank
   if {[file exists $tgscf]&&[file size $tgscf]>2} {
      set _sfile [open $tgscf r]
      set tgscores [lsort -dict -decreasing [split [gets $_sfile]]]
      close $_sfile
      set tgscorestotal [llength $tgscores]
   } else {
      set tgscores ""
      set tgscorestotal 0
   }
   if {[info exists tgscoresbyname]} {unset tgscoresbyname}
   if {[info exists tgranksbyname]} {unset tgranksbyname}
   if {[info exists tgrealnames]} {unset tgrealnames}
   if {[info exists tgranksbynum]} {unset tgranksbynum}
   set i 0
   while {$i<[llength $tgscores]} {
      set _item [lindex $tgscores $i]
      set _nick [lindex [split $_item ,] 2]
      set _lwrnick [lindex [split $_item ,] 3]
      set _score [lindex [split $_item ,] 0]
      set tgscoresbyname($_lwrnick) $_score
      set tgrealnames($_lwrnick) $_nick
      set tgranksbyname($_lwrnick) [expr $i+1]
      set tgranksbynum([expr $i+1]) $_lwrnick
      set tgscoresbyrank([expr $i+1]) $_score
      incr i
   }
   return
}

#increment someone's score.
proc tgincrscore {who} {
   global tgscores tgscf tgpointsperanswer tgscorestotal tgscoresbyname
   tggetscores
   if {$tgscorestotal>0} {
      set i 0
      if {![info exists tgscoresbyname([strlwr $who])]} {
         append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who] "
      }
      while {$i<[llength $tgscores]} {
         set _item [lindex $tgscores $i]
         set _nick [lindex [split $_item ,] 2]
         set _time [lindex [split $_item ,] 1]
         set _score [lindex [split $_item ,] 0]
         if {[strlwr $who]==[strlwr $_nick]} {
            append _newscores "[expr $_score+$tgpointsperanswer],[expr 1000000000000.0/[unixtime]],$who,[strlwr $who][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
         } else {
            append _newscores "$_score,$_time,$_nick,[strlwr $_nick][expr [expr [llength $tgscores]-$i]==1?"":"\ "]"
         }
         incr i
      }
   } else {
      append _newscores "1,[expr 1000000000000.0/[unixtime]],$who,[strlwr $who]"
   }
   set _sfile [open $tgscf w]
   puts $_sfile "$_newscores"
   close $_sfile
   return
}

#shows the current scores on channel.
proc tgshowscores {nick} {
   global tgscores tgchan tgscorestotal tgshowallscores tgranksbyname tgranksbynum
   global tgscoresbyname tgrealnames tgscoresbyrank
   tggetscores
   set i 0
   if {$tgshowallscores} {
      while {$i<[llength $tgscores]} {
         set _item [lindex $tgscores $i]
         set _nick [lindex [split $_item ,] 2]
         set _score [lindex [split $_item ,] 0]
         if {$i==0} {
            append _scores "[tgcolscr1]$_nick $_score"
         } elseif {$i==1} {
            append _scores ", [tgcolscr2]$_nick $_score"
         } elseif {$i==2} {
            append _scores ", [tgcolscr3]$_nick $_score"
         } elseif {[onchan $_nick $tgchan]} {
            append _scores ", [tgcolmisc1]$_nick $_score"
         }
         incr i
      }
      tggamemsg "[tgcolmisc1]The scores: $_scores"
   } else {
      if {$tgranksbyname([strlwr $nick])==1} {
         set _tgt "."
      } else {
         set _tgt ", behind [tgcolmisc2]$tgrealnames($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1]))[tgcolmisc1] with [tgcolmisc2]$tgscoresbyrank([expr $tgranksbyname([strlwr $nick])-1])[tgcolmisc1]."
      }
      tggamemsg "[tgcolmisc2]$nick [tgcolmisc1]now has [tgcolmisc2]$tgscoresbyname([strlwr $nick]) [tgcolmisc1][expr $tgscoresbyname([strlwr $nick])==1?"point":"points"] and is ranked [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])] [tgcolmisc1]of [tgcolmisc2]$tgscorestotal[tgcolmisc1]$_tgt"
   }
}

#reset current scores.
proc tgresetscores {nick host hand text} {
   global tgscf tgscorestotal tgscores tgplaying tgresetreqpw
   if {($tgresetreqpw==1 && [passwdok $hand $text]) || $tgresetreqpw==0} {
      if {[file exists $tgscf]&&[file size $tgscf]>2} {
         set _sfile [open $tgscf w]
         puts $_sfile ""
         close $_sfile
         set tgscores ""
         set tgscorestotal 0
      }
      tggamemsg "[tgcolrset]===== Score table reset by $nick! ====="
   }
}

#triggered when a winning streak ends.
proc tgstreakend {} {
      global tgstreak tgrealnames
      tggamemsg "[tgcolstend]So much for [tgcolmisc2]$tgrealnames([lindex [split $tgstreak ,] 0])'s[tgcolstend] winning streak."
      return
}

#triggered when someone joins trivia chan.
proc tgjoinmsg {nick host hand chan} {
   global botnick tgplaying tgcmdhelp tgcmdstart tgflagsstart tgcmdstop tgflagsstop tgchan
   if {$nick != $botnick} {
      set _msg ""
      append _msg "Welcome to $botnick's trivia channel for nerds. Trivia game is currently"
      if {$tgplaying==1} {
         append _msg " \002on\002."
      } else {
         append _msg " \002off\002."
      }
      if {[matchattr $hand $tgflagsstart $tgchan]&&$tgplaying==0} {
         append _msg " To start the game, type \002$tgcmdstart\002 on $tgchan."
      }
      append _msg " Please type \002/MSG $botnick [strupr $tgcmdhelp]\002 if you need help. Enjoy your stay! :-)"
      [tgpriv] $nick "$_msg"
   }
}

#triggered when someone /msgs the bot with the score lookup command.
proc tgscorelookup {nick host hand text} {
   global tgscoresbyname tgranksbyname tgscorestotal tgrealnames
   if {$text==""} { set text $nick } else { set text [lindex [split $text] 0] }
   tggetscores
   if {![info exists tgscoresbyname([strlwr $text])]} {
      if {[strlwr $text]==[strlwr $nick]} {
         set _who "[tgcolmisc1]You are"
      } else {
         set _who "[tgcolmisc2]$text [tgcolmisc1]is"
      }
      [tgpriv] $nick "[tgbold]$_who [tgcolmisc1]not on the score list."
   } else {
      if {[strlwr $text]==[strlwr $nick]} {
         set _who "[tgcolmisc1]You have"
      } else {
         set _who "[tgcolmisc2]$tgrealnames([strlwr $text]) [tgcolmisc1]has"
      }
      [tgpriv] $nick "[tgbold]$_who [tgcolmisc2]$tgscoresbyname([strlwr $text])[tgcolmisc1] points, ranked [tgcolmisc2][ordnumber $tgranksbyname([strlwr $text])] [tgcolmisc1]of [tgcolmisc2]$tgscorestotal[tgcolmisc1]."
   }
}

#triggered when someone /msgs the bot with the target lookup command.
proc tgtargetlookup {nick host hand text} {
   global tgscoresbyname tgranksbyname tgscorestotal tgranksbynum tgrealnames
   tggetscores
   if {![info exists tgscoresbyname([strlwr $nick])]} {
      [tgpriv] $nick "[tgbold][tgcolmisc1]You are not on the score list yet."
   } elseif {$tgranksbyname([strlwr $nick])==1} {
      [tgpriv] $nick "[tgbold][tgcolmisc1]You are in first place!"
   } else {
      [tgpriv] $nick "[tgbold][tgcolmisc1]You are on [tgcolmisc2]$tgscoresbyname([strlwr $nick])[tgcolmisc1]. Your next target is [tgcolmisc2]$tgrealnames($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1])) [tgcolmisc1]with [tgcolmisc2]$tgscoresbyname($tgranksbynum([expr $tgranksbyname([strlwr $nick])-1]))[tgcolmisc1], ranked [tgcolmisc2][ordnumber [expr $tgranksbyname([strlwr $nick])-1]] [tgcolmisc1]of [tgcolmisc2]$tgscorestotal[tgcolmisc1]."
   }
}

#triggered when someone /msgs the bot with the error reporting command.
proc tgerror {nick host hand text} {
   global tgquestionstotal tgquestionslist tgerrmethod tgerrfil tgerremail tgerrmailtmp
   if {$text==""||![string is int [lindex [split $text] 0]]} {
      [tgpriv] $nick "[tgbold][tgcolmisc1]You need to specify the number of the question."
      return
   }
   tgreadqdb
   set _qnum [lindex [split $text] 0]
   if {$_qnum>$tgquestionstotal} {
      [tgpriv] $nick "[tgbold][tgcolmisc1]No such question."
      return
   }
   set _qques [lindex [split [lindex $tgquestionslist [expr $_qnum-1]] |] 1]
   set _qans [lindex [split [lindex $tgquestionslist [expr $_qnum-1]] |] 0]
   set _desc [join [lrange [split $text] 1 end]]
   if {$_desc==""} { set _desc "No further info given for this error." }
   if {$tgerrmethod==1} {
      set _fname $tgerrmailtmp\trivia[rand 100000].tmp
      set _file [open $_fname w]
   } else {
      set _file [open $tgerrfil a]
   }
   puts $_file ""
   puts $_file "Error report generated [strftime %A,\ %d\ %B\ %Y\ @\ %H:%M:%S]"
   puts $_file "Reported by:\t$nick!$host"
   puts $_file "Question #:\t$_qnum"
   puts $_file "Question:\t$_qques"
   puts $_file "Answer:\t\t$_qans"
   puts $_file "Comments:\t$_desc"
   puts $_file "------------------------------"
   close $_file
   if {$tgerrmethod==1} {
      exec mail -s "trivia.tcl error report from $nick" $tgerremail < $_fname
      file delete $_fname
      [tgpriv] $nick "[tgbold][tgcolmisc1]Thanks! Your error report has been e-mailed to my owner."
   } else {
      [tgpriv] $nick "[tgbold][tgcolmisc1]Thanks! Your error report has been logged and will be looked at as soon as possible."
   }
}

#triggered when someone /msgs the bot with the rules command.
proc tgrulesmsg {nick host hand text} {
   global tgrules
   [tgpriv] $nick "The channel's rules are as follows: $tgrules"
}

#triggered when someone /msgs the bot with the help command.
proc tggivehelp {nick host hand {text ""}} {
   global botnick tgcmdlookup tgcmdhelp tgcmdstart tgcmdstop tgchan tgflagsstop
   global tgcmdstop tgflagshint tgcmdhint tgflagsskip tgcmdskip tgflagsreset tgcmdreset
   global tgcmdtarget tgcmderror tgcmdrules tgflagsstart
   if {$text==""} {
      [tgpriv] $nick "You have access to the following /MSG commands:"
      [tgpriv] $nick "To use, /MSG $botnick <command>"
      [tgpriv] $nick "  \002[strupr $tgcmdrules]\002"
      [tgpriv] $nick "   -- Lists the channel rules."
      [tgpriv] $nick "  \002[strupr $tgcmdlookup]\002 \[nick\]"
      [tgpriv] $nick "   -- Shows you the rank & score of \[nick\], if specified,"
      [tgpriv] $nick "    otherwise, shows you your own rank & score."
      [tgpriv] $nick "  \002[strupr $tgcmdtarget]\002"
      [tgpriv] $nick "   -- Shows you the rank & score of the person ranked"
      [tgpriv] $nick "    one above you."
      [tgpriv] $nick "  \002[strupr $tgcmderror]\002 <number> \[description\]"
      [tgpriv] $nick "   -- Reports an error in question <number>"
      [tgpriv] $nick "    The description is optional, but helpful."
      if {[matchattr $hand $tgflagsreset $tgchan]} {
         [tgpriv] $nick "  \002[strupr $tgcmdreset]\002"
         [tgpriv] $nick "   -- Resets the score table."
      }
      [tgpriv] $nick "For a list of channel commands, /MSG $botnick [strupr $tgcmdhelp] PUBCMDS"
   }
   if {[strlwr $text]=="pubcmds"} {
      [tgpriv] $nick "You have access to the following channel commands:"
      if {[matchattr $hand $tgflagsstart $tgchan]} {
         [tgpriv] $nick "  \002$tgcmdstart\002 -- starts the trivia game."
      }
      if {[matchattr $hand $tgflagsstop $tgchan]} {
         [tgpriv] $nick "  \002$tgcmdstop\002 -- stops the trivia game."
      }
      if {[matchattr $hand $tgflagshint $tgchan]} {
         [tgpriv] $nick "  \002$tgcmdhint\002 -- shows a hint."
      }
      if {[matchattr $hand $tgflagsskip $tgchan]} {
         [tgpriv] $nick "  \002$tgcmdskip\002 -- skips current question."
      }
      [tgpriv] $nick "For a list of /MSG commands, /MSG $botnick [strupr $tgcmdhelp]"
   }
}

# Returns text without colour, bold, etc. control codes.
# This is a stripped down version of the proc in MC_8's mc.moretools.tcl.
proc tgstripcodes {text} {
   regsub -all -- "\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?" $text "" text
#stripping tabs as well
   regsub -all -- "\t" $text " " text
   set text "[string map -nocase [list \002 "" \017 "" \026 "" \037 ""] $text]"
   return $text
}

proc tggamemsg {what} {
   global tgchan

   putquick "PRIVMSG $tgchan :[tgbold]$what"
}

proc tgbold {} {
   global tgusebold
   if {$tgusebold==1} { return "\002" }
}
proc tgcolstart {} {
   global tgcolourstart
   if {$tgcolourstart!=""} { return "\003$tgcolourstart" }
}
proc tgcolstop {} {
   global tgcolourstop
   if {$tgcolourstop!=""} { return "\003$tgcolourstop" }
}
proc tgcolskip {} {
   global tgcolourskip
   if {$tgcolourskip!=""} { return "\003$tgcolourskip" }
}
proc tgcolerr {} {
   global tgcolourerr
   if {$tgcolourerr!=""} { return "\003$tgcolourerr" }
}
proc tgcolmiss {} {
   global tgcolourmiss
   if {$tgcolourmiss!=""} { return "\003$tgcolourmiss" }
}
proc tgcolqhead {} {
   global tgcolourqhead
   if {$tgcolourqhead!=""} { return "\003$tgcolourqhead" }
}
proc tgcolqbody {} {
   global tgcolourqbody
   if {$tgcolourqbody!=""} { return "\003$tgcolourqbody" }
}
proc tgcolhint {} {
   global tgcolourhint
   if {$tgcolourhint!=""} { return "\003$tgcolourhint" }
}
proc tgcolstrk {} {
   global tgcolourstrk
   if {$tgcolourstrk!=""} { return "\003$tgcolourstrk" }
}
proc tgcolscr1 {} {
   global tgcolourscr1
   if {$tgcolourscr1!=""} { return "\003$tgcolourscr1" }
}
proc tgcolscr2 {} {
   global tgcolourscr2
   if {$tgcolourscr2!=""} { return "\003$tgcolourscr2" }
}
proc tgcolscr3 {} {
   global tgcolourscr3
   if {$tgcolourscr3!=""} { return "\003$tgcolourscr3" }
}
proc tgcolrset {} {
   global tgcolourrset
   if {$tgcolourrset!=""} { return "\003$tgcolourrset" }
}
proc tgcolstend {} {
   global tgcolourstend
   if {$tgcolourstend!=""} { return "\003$tgcolourstend" }
}
proc tgcolmisc1 {} {
   global tgcolourmisc1
   if {$tgcolourmisc1!=""} { return "\003$tgcolourmisc1" }
}
proc tgcolmisc2 {} {
   global tgcolourmisc2
   if {$tgcolourmisc2!=""} { return "\003$tgcolourmisc2" }
}
proc tgpriv {} {
   global tgpriv2msg
   if {$tgpriv2msg==1} { return "putmsg" } else { return "putnotc" }
}
proc tgcolmpca {} {
   global tgcolourmpca
   if {$tgcolourmpca!=""} {return "\003$tgcolourmpca" }
}

#this generates an html file with all the people on the chan with
#their score, as well as a list of all scores, sorted by rank
proc tghtml {} {
   global tgchan botnick tghtmlfile tghtmlrefresh server tgscoresbyname tgranksbyname
   global tgscorestotal tgranksbyname tgrealnames tgscoresbyrank tgranksbynum tgplaying
   global tgquestionstotal tghtmlrefreshtimer tghtmlfont
   tggetscores
   tgreadqdb
   set _file [open $tghtmlfile~new w]
   puts $_file "<!DOCTYPE HTML PUBLIC \"-/W3C/DTD HTML 4.01 Transitional/EN\">"
   puts $_file "<html>"
   puts $_file " <head>"
   puts $_file "  <title>$botnick's trivia channel: $tgchan on [lindex [split $server :] 0]</title>"
   puts $_file "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
   puts $_file "  <meta http-equiv=\"refresh\" content=\"$tghtmlrefresh\">"
   puts $_file "  <meta name=\"generator\" content=\"trivia.tcl script for eggdrop. http://www.eggdrop.za.net/\">"
   puts $_file "  <style type=\"text/css\">"
   puts $_file "  <!--"
   puts $_file "  body,td{font-family:$tghtmlfont;font-size:13px;}"
   puts $_file "  a{text-decoration:none;color:#09f;}"
   puts $_file "  -->"
   puts $_file "  </style>"
   puts $_file " </head>"
   puts $_file " <body>"
   puts $_file "  <h1>$tgchan on [lindex [split $server :] 0]</h1>"
   puts $_file "  <hr size=\"1\" noshade>"
   if {![onchan $botnick $tgchan]} {
      puts $_file "  <p>Hmmm... for some reason I'm not on $tgchan at the moment. Please try again later.</p>"
   } else {
      puts $_file "  <p>Trivia game is currently <b>[expr $tgplaying==1?"on":"off"]</b>. There are <b>$tgquestionstotal</b> questions in the database."
      puts $_file "  <p>People on $tgchan right now:<br>"
      puts $_file "  <table width=\"50%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><table width=\"100%\" cellspacing=\"3\" border=\"0\">"
      puts $_file "   <tr>"
      puts $_file "    <td><b>Nick</b></td>"
      puts $_file "    <td><b>Score</b></td>"
      puts $_file "    <td><b>Rank</b></td>"
      puts $_file "    <td><b>Idle</b></td>"
      puts $_file "   </tr>"
      foreach nick [lsort [chanlist $tgchan]] {
         puts $_file "   <tr>"
         puts $_file "    <td>[expr [isop $nick $tgchan]?"@":""][expr [isvoice $nick $tgchan]?"+":""]$nick[expr [string match $nick $botnick]?" (that's me!)":""]</td>"
         if {[info exists tgscoresbyname([strlwr $nick])]} {
            puts $_file "    <td>$tgscoresbyname([strlwr $nick])</td>"
         } else {
            puts $_file "    <td>-</td>"
         }
         if {[info exists tgranksbyname([strlwr $nick])]} {
            puts $_file "    <td>$tgranksbyname([strlwr $nick])</td>"
         } else {
            puts $_file "    <td>-</td>"
         }
         puts $_file "   <td>[expr [getchanidle $nick $tgchan]>10?"[getchanidle $nick $tgchan]m":"-"]</td>"
         puts $_file "   </tr>"
      }
      puts $_file "  </table></td></tr></table>"
   }
   if {$tgscorestotal>0} {
      puts $_file "  <p><small>There [expr $tgscorestotal==1?"is":"are"] currently <b>$tgscorestotal</b> [expr $tgscorestotal==1?"nick":"nicks"] in the score table:<br>"
      set _rank 1
      while {$_rank<=$tgscorestotal} {
         puts $_file "  <b>$_rank</b>. $tgrealnames($tgranksbynum($_rank)) $tgscoresbyrank($_rank)<br>"
         incr _rank
      }
   } else {
      puts $_file "  <p><small>There are currently no nicks in the score table.<br>"
   }
   puts $_file "  </small></p>"
   puts $_file "  <hr size=\"1\" noshade>"
   puts $_file "  <small>Generated on [strftime %A,\ %d\ %B\ %Y\ @\ %H:%M:%S] by <a href=\"http://www.eggdrop.za.net/\">trivia.tcl</a> for <a href=\"http://www.eggheads.org\">eggdrop</a>.<br>"
   puts $_file "  This page is automatically updated (and refreshed if supported by your browser) every [expr $tghtmlrefresh==1?"second":"$tghtmlrefresh seconds"].</small>"
   puts $_file " </body>"
   puts $_file "</html>"
   close $_file
   file rename -force $tghtmlfile~new $tghtmlfile
   set tghtmlrefreshtimer [utimer $tghtmlrefresh tghtml]
}

putlog "======================================================="
putlog "* triviaplus.tcl The Enhanced Version by Hairy Scary loaded."
putlog "* based upon:"
putlog "* trivia.tcl 1.3.4 release by Souperman"
putlog "* Enhanced with:    "
putlog "*   - Multiplechoice questions"
putlog "*    - A $tgchoosecmd for multiple categories or questionfiles"
putlog "*   - A cheat protection for stopping guessing and trying "
putlog "* Visit http://www.eggdrop.za.net/ for updates for trivia.tcl"
tgreadqdb
putlog "* $tgquestionstotal questions in $tgqdb ([file size $tgqdb] bytes)"
putlog "======================================================="
Back to top
View user's profile Send private message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Mon Apr 14, 2008 10:59 pm    Post subject: Reply with quote

If it helps any, the above script works on my windrop, and my freeBSD linux just not my OpenSUSE linux I use... so I guess problem is my OS?
Back to top
View user's profile Send private message
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Sun Apr 27, 2008 8:45 pm    Post subject: Reply with quote

for what it's worth... that variable tgmaxhintcurrent is never set in the script that you posted... So perhaps when you copied over the script to the new installation, you editted and removed that setting by mistake.
Back to top
View user's profile Send private message Visit poster's website
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Apr 27, 2008 11:28 pm    Post subject: Reply with quote

Code:
   if {[catch {incr tghintnum}]!=0} {
      set tghintnum 0
      regsub -all -- "\[^A-Za-z0-9\]" $tgcurrentanswer "" _hintchars
      set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]

It's setting it, but perhaps the code used to set the variable behaves differently depending on OS? Otherwise it's likely the problem is with tghintnum and the IF statement isn't behaving correctly and setting tgmaxhintcurrent.
Code:
   if {[catch {incr tghintnum}]} {
      set tghintnum 0
      regsub -all -- "\[^A-Za-z0-9\]" $tgcurrentanswer "" _hintchars
      set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]

That may fix it. The !=0 isn't neccessary.
Back to top
View user's profile Send private message
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Mon Apr 28, 2008 12:36 am    Post subject: Reply with quote

Odd, I used the search feature several times for that variable and it only came across it being referenced twice in the original post, originally.

Information also of value would be what version of Tcl is the bot compiled/being compiled against when it works and when it doesn't work.
Back to top
View user's profile Send private message Visit poster's website
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Mon Apr 28, 2008 1:56 am    Post subject: Reply with quote

speechles wrote:
Code:
   if {[catch {incr tghintnum}]!=0} {
      set tghintnum 0
      regsub -all -- "\[^A-Za-z0-9\]" $tgcurrentanswer "" _hintchars
      set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]

It's setting it, but perhaps the code used to set the variable behaves differently depending on OS? Otherwise it's likely the problem is with tghintnum and the IF statement isn't behaving correctly and setting tgmaxhintcurrent.
Code:
   if {[catch {incr tghintnum}]} {
      set tghintnum 0
      regsub -all -- "\[^A-Za-z0-9\]" $tgcurrentanswer "" _hintchars
      set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]

That may fix it. The !=0 isn't neccessary.


Thanks, I tried this on version 1.19 and got this error:
Tcl error [tgstart]: can't read "tgmaxhintcurrent": no such variable

and tried change on 1.18 and works fine... no clue why this script will only work on freeBSD/ 1.18
Back to top
View user's profile Send private message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Mon Apr 28, 2008 2:05 am    Post subject: Reply with quote

strikelight wrote:
Odd, I used the search feature several times for that variable and it only came across it being referenced twice in the original post, originally.

Information also of value would be what version of Tcl is the bot compiled/being compiled against when it works and when it doesn't work.


Code:

openSUSE (eggdrop 1.18 and 1.19) Don't work
freeBSD (eggdrop 1.19) Don't work
windrop (eggdrop 1.19) Don't work
===============================
freeBSD (eggdrop 1.18) Works
windrop (eggdrop 1.18) Works

both freebsd and opensuse are latest versions I downloaded from the site.


Last edited by cache on Mon Apr 28, 2008 2:07 am; edited 1 time in total
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Mon Apr 28, 2008 2:05 am    Post subject: Reply with quote

Here is a quick fix hopefully, since tgmaxhintcurrent is a global variable, add at the very top of the script this code below.
Code:
set tgmaxhintcurrent 0

This should let the script at least initially start running as it will then have the variable in memory before it gets to the point your having problems with at the moment.

*** note: it's more than likely that complex equation used to set the contents of tgmaxhintcurrent that is causing an error, which in turn keeps it from being properly set. The interpreter afterwards moves down into code below expecting that variable to be set. When it isn't it generates the error your presently seeing, basically masking the real error behind it (that overly complex variable setting).
Code:
if {catch {set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]}} {
  putlog "yes indeed, the titanic has sunk :\("
}

This can deduce if indeed the problem lies with that pesky complex variable setting, hope you understand.. Wink
Back to top
View user's profile Send private message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Mon Apr 28, 2008 2:24 am    Post subject: Reply with quote

Code:
if {catch {set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]}} {
  putlog "yes indeed, the titanic has sunk :\("
}


Sorry do I add this or replace it with something? I crashed added lol
Back to top
View user's profile Send private message
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Mon Apr 28, 2008 2:36 am    Post subject: Reply with quote

Got this error:
Tcl error [tgstart]: can't read "tgstreak": no such variable

When I added: set tgmaxhintcurrent 0
Back to top
View user's profile Send private message
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Mon Apr 28, 2008 6:46 pm    Post subject: Reply with quote

cache wrote:
strikelight wrote:
Odd, I used the search feature several times for that variable and it only came across it being referenced twice in the original post, originally.

Information also of value would be what version of Tcl is the bot compiled/being compiled against when it works and when it doesn't work.


Code:

openSUSE (eggdrop 1.18 and 1.19) Don't work
freeBSD (eggdrop 1.19) Don't work
windrop (eggdrop 1.19) Don't work
===============================
freeBSD (eggdrop 1.18) Works
windrop (eggdrop 1.18) Works

both freebsd and opensuse are latest versions I downloaded from the site.


Not the eggdrop versions (and they would be 1.6.18, 1.6.19, etc)...
When you compile eggdrop, it requires Tcl to be installed... I'm asking what version Tcl (Tool Command Language) is installed and being compiled against with your bots.
Back to top
View user's profile Send private message Visit poster's website
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Tue Apr 29, 2008 6:40 am    Post subject: Reply with quote

strikelight wrote:
cache wrote:
strikelight wrote:
Odd, I used the search feature several times for that variable and it only came across it being referenced twice in the original post, originally.

Information also of value would be what version of Tcl is the bot compiled/being compiled against when it works and when it doesn't work.


Code:

openSUSE (eggdrop 1.18 and 1.19) Don't work
freeBSD (eggdrop 1.19) Don't work
windrop (eggdrop 1.19) Don't work
===============================
freeBSD (eggdrop 1.18) Works
windrop (eggdrop 1.18) Works

both freebsd and opensuse are latest versions I downloaded from the site.


Not the eggdrop versions (and they would be 1.6.18, 1.6.19, etc)...
When you compile eggdrop, it requires Tcl to be installed... I'm asking what version Tcl (Tool Command Language) is installed and being compiled against with your bots.


Oh sorry, I haven't paid attention to that... what version TCL is best? I see 8.5 out... when I installed BSD and SUSE they downloaded software in packages and maybe both took a different version.
Back to top
View user's profile Send private message
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Tue Apr 29, 2008 12:05 pm    Post subject: Reply with quote

There are some minor unrelated issues with Tcl8.5 and eggdrop at the moment, which I hear will be resolved in the next eggdrop version. So your best bet is Tcl8.4.19. You will need to recompile your eggdrop after installing the new Tcl package you install.
Back to top
View user's profile Send private message Visit poster's website
cache
Master


Joined: 10 Jan 2006
Posts: 306
Location: Mass

PostPosted: Wed Apr 30, 2008 1:41 am    Post subject: Reply with quote

strikelight wrote:
There are some minor unrelated issues with Tcl8.5 and eggdrop at the moment, which I hear will be resolved in the next eggdrop version. So your best bet is Tcl8.4.19. You will need to recompile your eggdrop after installing the new Tcl package you install.

Thanks Very Happy
Back to top
View user's profile Send private message
Amr
Halfop


Joined: 14 Sep 2007
Posts: 94
Location: Egypt

PostPosted: Fri Aug 29, 2008 6:04 am    Post subject: Reply with quote

I got the same error , I got Tcl8.4.19 installed and am using FreeBSD.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber