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 Hint

Old posts that have not been replied to for several years.
Locked
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Random Hint

Post by Sir_Fz »

Code: Select all

#shows timed hints.
proc tghint {} {
 global tgmaxhint tghintnum tgcurrentanswer tghinttimer tgchan
 global tgtimehint tghintchar tgquestionnumber tgquestionstotal
 global tgcurrentquestion tghintcharsused tgnexttimer tgtimenext tgstreak tgstreakmin
 global tgnobodygotit tgtrythenextone tgmissed tgmaxmissed tgcmdstart
 if {[catch {incr tghintnum}]!=0} {set tghintnum 0}
 if {$tghintnum >= [expr $tgmaxhint+1]} {
  incr tgmissed
  set _msg ""
  append _msg "\00310[lindex $tgnobodygotit [rand [llength $tgnobodygotit]]]"
  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 "$_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 tgnexttimer [utimer $tgtimenext tgnext]
  }
  return
 } elseif {$tghintnum == 0} {
  set i 0
  set _hint {}
  set tghintcharsused {}
  regsub -all -- "\[A-Za-z0-9\]" $tgcurrentanswer $tghintchar _hint
 } 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
  }
 }
 tggamemsg "\00304===== Question [expr $tgquestionnumber+1]/$tgquestionstotal [expr $tghintnum?"(Hint $tghintnum/$tgmaxhint)":""] ====="
 tggamemsg "\00312[strupr $tgcurrentquestion]"
 tggamemsg "\00303Hint: [strupr $_hint]"
 set tghinttimer [utimer $tgtimehint tghint]
}
this randomizes the letters in the hint (trivia)
example the answer is ANSWER it gives the hint like that: A__W_R

I want it to give the hint organized like : ANS___ what would be the right syntax ?
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

I can't be sure as there is way too much fluff in that code, but
I'd recommend try changing:

Code: Select all

    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]] 
     } 
To the following:

Code: Select all

    set _selected 0 
    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} {
      incr _selected
     } 
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

ok good :) now it shows the frist letter on each line.
for example, hint: O__ L_____ , then next hing ON_ LE____, then third hint: ONE LET___
is there a way to make some kind of percentage of showing letters from the answer ? like instead of one letter each hint, making it give according to the length of the answer ?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

    set _selected 0 
    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} { 
      incr _selected 
     }
this give a 1 letter hint on each hint, would there be a way to let it give 2 letters on each hint ?

like instead of Hint1: H___ O__ it should give Hint1: HI__ ON_ (HINT ONE is the word :P)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Ok, here's an updated version of the script:

Code: Select all

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

#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]
 }
 tggamemsg "[tgcolqhead]===== Question [expr $tgquestionnumber+1]/$tgquestionstotal [expr $tghintnum?"(Hint $tghintnum/$tgmaxhintcurrent)":""] ====="
 if {$tgalwaysshowq==1||$tghintnum==0} {
  tggamemsg "[tgcolqbody]$tgcurrentquestion"
 }
 tggamemsg "[tgcolhint]Hint: [join $_hint]"
 set tghinttimer [utimer $tgtimehint tghint]
}
it only gives 1 letter of the answer as a hint (each hint, they're three)
I want it to give atleast 2 letters on each hint, can anyone help ?
Locked