Trivia : les indices continuent après réponse
#1
Bonsoir,

J'ai résolu pas mal de problèmes avec mon Trivia qui datais d'une époque fiouuuuuuu mais après m'avoir connecté sur le réseau IRC ou il tourne j'ai eu quelques réclamations sur un Bug énoncé dans le titre du sujet " Après réponse les indices continuent " ce qui est plutôt casse bonbons :p

Voilà un petit screen de l'histoire des indices :

[Image: http://imagesup.org/images11/1351535791-...12-10-.png]

Voici la proc de la mise en place des indices :

tcl
#Mise en place des indices.
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} {}
	if {![info exists tghintnum]} {
        set tghintnum 0
        regsub -all -- "\[^A-Za-z0-9\]" [no_accent $tgcurrentanswer] "" _hintchars
        set tgmaxhintcurrent [expr [strlen $_hintchars]<=$tgmaxhint?[expr [strlen $_hintchars]-1]:$tgmaxhint]
        catch {tgunbindhintcmd}
        if {$tgmaxhintcurrent>0} {
            set tgrebindhinttimer [utimer $tgtempnohint tgbindhintcmd]
        }
    } else { incr tghintnum }
    if {$tghintnum >= [expr $tgmaxhintcurrent+1]} {
        incr tgmissed
        set _msg ""
        append _msg " [tgcolmiss][lindex $tgnobodygotit [rand [llength $tgnobodygotit]]]"
        if {$tgshowanswer==1} {
            append _msg "09,01La réponse était [tgcolmisc2]13,01$tgcurrentanswer[tgcolmiss]."
        }
        if {$tgmaxmissed>0&&$tgmissed>=$tgmaxmissed} {
            append _msg " Cela fait $tgmissed questions sans réponse ! Le  quizz a ete automatiquement arreté. pour le relancer, tapez 04$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\]" [no_accent $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\]" [no_accent $_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]
    }
    if {$tgalwaysshowq==1||$tghintnum==0} {
        tggamemsg "04,01 -07,01\[\Question n°[expr $tgquestionnumber+1]\]\04,01-[tgcolqbody] $tgcurrentquestion ? "
    }
    tggamemsg "04,01 € 07,01Indice : 08,01[join $_hint] "
    set tghinttimer [utimer $tgtimehint tghint]
}



Puis la vérification lorsque une réponse est donné :

tcl
#vérifie si n'importe qui a indiqué la réponse correcte sur le canal.
proc tgcheckanswer {nick host hand chan text} {
    global tgcurrentanswer
    putlog [tgstripcodes $text]
    if {[strlwr [no_accent $tgcurrentanswer]] == [tgstripcodes [strlwr [string trim [no_accent $text]]]]} {
        tgcorrectanswer $nick
    }
}

#déclenché quand quelqu'un dit la réponse correcte.
proc tgcorrectanswer {nick} {
    global tgcurrentanswer tghinttimer tgtimenext tgchan tgnextqtimer tgstreak tgstreakmin
    global tgscoresbyname tgranksbyname tgranksbynum tgcongrats tgscorestotal tgmissed
    global tgtimestart tgshowallscores tgrealnames tgscoresbyrank tgtimeanswer tgmulti
    tggetscores
    if {![info exists tgranksbyname([strlwr $nick])]} {
        set _oldrank 0
    } else {
        set _oldrank $tgranksbyname([strlwr $nick])
    }
    tgincrscore $nick
    tggetscores
    set _newrank $tgranksbyname([strlwr $nick])
    set _timetoanswer ""
    if {$tgtimeanswer==1} {
        set _timetoanswer [expr [expr [clock clicks -milliseconds]-$tgtimestart]/1000.00]
    }
	if !([isvoice $nick $tgchan]||[isop $nick $tgchan]) {
			putserv "MODE $tgchan +v $nick"
	}
    set _msg "[tgcolmisc1] [lindex $tgcongrats [rand [llength $tgcongrats]]] [tgcolmisc2]13,01$nick[tgcolmisc1] ! La réponse était [tgcolmisc2]13,01$tgcurrentanswer[tgcolmisc1].[expr $tgtimeanswer==1?" Tu l'as trouvée en [tgcolmisc2]13,01$_timetoanswer[tgcolmisc1] secondes. ":""]"
    if {$_newrank<$_oldrank} {
        if {$_newrank==1} {
            append _msg " Tu es maintenant en 1er position!"
        } else {
            if {$tgshowallscores==0} {
                append _msg " Tu as changé de place!"
            } else {
                append _msg " Tu es maintenant classé [tgcolmisc2][ordnumber $tgranksbyname([strlwr $nick])][tgcolmisc1]e sur [tgcolmisc2]$tgscorestotal[tgcolmisc1], derrière [tgcolmisc2]$tgrealnames($tgranksbynum([expr $_newrank-1]))[tgcolmisc1] avec [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]13,01 $nick[tgcolstrk]09,01 [lindex $tgmulti [rand [llength $tgmulti]]] [tgcolmisc2]13,01[lindex [split $tgstreak ,] 1] [tgcolstrk]09,01réponses consécutives ! "
            }
        } 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]
}



Une petite idée ?
Répondre Avertir


Messages dans ce sujet
Trivia : les indices continuent après réponse - par kipof - 29/10/2012, 20:43

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
Tchat 100% gratuit -Discutez en toute liberté