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.

help me combine tcl script

Old posts that have not been replied to for several years.
Locked
User avatar
hikaro
Halfop
Posts: 68
Joined: Wed Mar 10, 2004 4:29 am

help me combine tcl script

Post by hikaro »

i got 2 games running in 1 bot but the score of both game cannot be saved together. anyone please help me combine it... i want the first script modify to second script.
here the first script
proc tmcquiz_rank_save {handle idx arg} {
global rankfile userlist
global lastsolver lastsolvercount timerankreset
global qnum_thisgame
global quizconf
variable fd

## save ranks
if {[llength [array names userlist]] > 0} {
set fd [open $rankfile w]
puts $fd "# rankings from $quizconf(quizchannel) at [ctime [unixtime]]."
puts $fd "winscore: $quizconf(winscore)"
puts $fd "rankreset: $timerankreset"
puts $fd "ranksave: [unixtime]"
puts $fd "qnumber: $qnum_thisgame"
if {$lastsolver != ""} {
puts $fd "lastsolver: $lastsolver = $lastsolvercount"
}
foreach u [lsort -command mx_sortrank [array names userlist]] {
array set aa $userlist($u)
puts $fd [format "%d %d : %s at %s" $aa(started) $aa(score) $u $aa(mask)]
}
close $fd
mx_log "--- Ranks saved to \"$rankfile\"."
mxirc_dcc $idx "Ranks saved to \"$rankfile\"."
} else {
mxirc_dcc $idx "Ranks are empty, nothing saved."
}
return 1
}


and here the second one
proc write_KAOSScore {} {
global KAOSScore KAOSScoreFile
set f [open $KAOSScoreFile w]
foreach s [lsort -decreasing -command sort_KAOSScore [array names KAOSScore]] {
puts $f "$s $KAOSScore($s)"
}
close $f
}
is it possible to combine it? please help me... thank you before
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Re: help me combine tcl script

Post by arcane »

hikaro wrote:is it possible to combine it? please help me... thank you before
probably - but not with the amount of information given...
you want both saved files to be compatible? or just save the entries following the same pattern? or what?
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
User avatar
hikaro
Halfop
Posts: 68
Joined: Wed Mar 10, 2004 4:29 am

Post by hikaro »

i want both saved files to be compatible, so only need 1 score file there and 1 score (!Score command). if you can help and need tcl i can send you to ur mail the tcl because its big enough.
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

or you could use the code tags
User avatar
hikaro
Halfop
Posts: 68
Joined: Wed Mar 10, 2004 4:29 am

Post by hikaro »

hmm i think the script too long... :(
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

well, you need to change at least both load and save procs.
if you want to store your scores like in the second one, you need to convert your variables into arrays as well.
you should post the load and save procs and for easier understanding maybe some excerpts from your saved score files.
i think it's unnecessary to know the whole script.
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
User avatar
hikaro
Halfop
Posts: 68
Joined: Wed Mar 10, 2004 4:29 am

Post by hikaro »

ok i paste the load proc arcane...
here for the first one

Code: Select all

proc tmcquiz_rank_load {handle idx arg} {
    global rankfile userlist timerankreset
    global lastsolver lastsolvercount qnum_thisgame
    global quizconf
    variable timeranksaved [unixtime]
    variable fd
    variable line
    variable us 0 sc 0 mask ""

    ## clear old userlist (ranks)
    foreach u [array names userlist] {
	unset userlist($u)
    }

    ## load saved scores
    if {[file exists $rankfile] && [file readable $rankfile]} {
	set fd [open $rankfile r]
	while {![eof $fd]} {
	    set line [gets $fd]
	    if {![regexp "#.*" $line]} {
		switch -regexp $line {
		    "^winscore: .+ *$" {
			scan $line "winscore: %d" quizconf(winscore)
		    }
		    "^rankreset: +[0-9]+ *$" {
			scan $line "rankreset: %d" timerankreset
		    }
		    "^lastsolver:" {
			scan $line "lastsolver: %s = %d" lastsolver lastsolvercount
		    }
		    "^ranksave:" {
			scan $line "ranksave: %d" timeranksaved
		    }
		    "^qnumber:" {
			scan $line "qnumber: %d" qnum_thisgame
		    }
		    default {
			scan $line "%d %d : %s at %s" started sc us mask
			set alist [list "mask" $mask "score" $sc "lastspoken" 0 "started" [expr $started + [unixtime] - $timeranksaved]]
			set userlist($us) $alist
		    }
		}
	    }
	}
	close $fd
	mxirc_dcc $idx "Ranks loaded ([llength [array names userlist]]), winscore = $quizconf(winscore), saved at unixtime $timeranksaved."
	mx_log "--- Ranks loaded ([llength [array names userlist]]), winscore = $quizconf(winscore), saved at unixtime $timeranksaved."
    } else {
	mxirc_dcc $idx "Could not read \"$rankfile\"."
	mx_log "---- could not read \"$rankfile\"."
    }
    return 1
}
and this is second one

Code: Select all

proc read_KAOSScore { } {
global KAOSScore KAOSScoreFile
if [info exists KAOSScore] { unset KAOSScore }
if {[file exists $KAOSScoreFile]} {
  set f [open $KAOSScoreFile r]
  while {[gets $f s] != -1} {
    set KAOSScore([lindex $s 0]) [lindex $s 1]
  }
  close $f
} {
set f [open $KAOSScoreFile w]
puts $f "Nobody 0"
close $f
}
}

thanks for your reply

merry xmas to you all!
Locked