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.

random limit must be greater than zero

Help for those learning Tcl or writing their own scripts.
Post Reply
G
Gbot
Voice
Posts: 1
Joined: Sun May 13, 2012 6:30 am
Location: PK

random limit must be greater than zero

Post by Gbot »

Hi Guys,

In my trivia bot, I am receiving this error which makes trivia bot to go quiet in between questions. This happens intermittently. Below is the detail on the error I have found while doing set errorinfo

Thanks in advance,
gBot

Details:
random limit must be greater than zero
Currently: while executing
Currently: "rand [strlen $_word]"
Currently: (procedure "tghint" line 79)
Currently: invoked from within
Currently: "tghint"
Method:

Code: Select all

#shows timed hints.
proc tghint {} {
 global tgmaxhint tghintnum tgcurrentanswer tghinttimer tgchan
 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
 if {[catch {incr tghintnum}]!=0} {
  set tghintnum 0
  regsub -all -- "\[^A-Za-z0-9\]" [string trim $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 $tgcurrentanswer" tgcorrectanswer}
  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]
 }
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Trivia with no Errors:)

Post by SpiKe^^ »

Try BogusTrivia for a trivia game with no errors.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply