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 

random limit must be greater than zero

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Gbot
Voice


Joined: 13 May 2012
Posts: 1
Location: PK

PostPosted: Sun May 13, 2012 6:41 am    Post subject: random limit must be greater than zero Reply with quote

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:
Quote:

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:

#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]
 }
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Jun 22, 2012 12:00 pm    Post subject: Trivia with no Errors:) Reply with quote

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
.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
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