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.

problem with list / mysql

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dragoneye
Voice
Posts: 9
Joined: Tue Apr 19, 2005 4:21 pm

problem with list / mysql

Post by dragoneye »

i want to put colors to my scores like if 1-0 then green if 0-1 red and 1-1 blue

Code: Select all

proc cws {nick uhost hand chan arg} {
if { [isop $nick $chan] } {
global dbhost dbuser dbpass dbname mycpage matchtab mytag pchan
 if {$arg == ""} { putnotc $nick "\[\2cw's\2\] syntax: !cws clantag";return 1 }
 set mysql(conn) [mysqlconnect -host $dbhost -user $dbuser -password $dbpass -db $dbname]
 set arg [string map {' ''} $arg]
 set rows [mysqlsel $mysql(conn) "select count(*) FROM `matches` WHERE `opponent` = '$arg' " -list ]
 set vs [mysqlsel $mysql(conn) "SELECT `score` FROM `matches` WHERE `opponent` = '$arg' " -flatlist ]
 set clname [mysqlsel $mysql(conn) "SELECT `cname` FROM `tagit` WHERE `tagi` = '$arg' " -flatlist ]
 set irc [mysqlsel $mysql(conn) "SELECT `ircchan` FROM `tagit` WHERE `tagi` = '$arg' " -list ]
 set hp [mysqlsel $mysql(conn) "SELECT `http` FROM `tagit` WHERE `tagi` = '$arg' " -list ]
 set cname [lindex $clname 0]
 if { $rows == 0 } {putmsg $chan "\[\2cw's\2\] no cw's played against \2$arg\2.";return 0}
 putmsg $chan "\[\2$arg \2•\2 $cname \2•\2 $irc \2\]"
 putmsg $chan "\[\2Homepage:\2 $hp \]"
 putmsg $chan "\[\2cw's\2\] $vs. Total $rows cw's against \2$arg"
 } else {
    puthelp "NOTICE $nick : You need to be OP to use this command"
  }
}

current output is like this, but how can i add those colors :L and maybe
put something like wins: x loses: x draws: x

[w/ • whatever • #clan.w ]
[Homepage: http://hangar.0wns.org/whatever/ ]
[cw's] 25-19 32-23 24-21 28-19 29-21 36-10 25-23 31-16 25-22 24-21 21-28 21-23 38-22 31-16 24-21 30-19 27-32 28-22 23-31 21-31 21-24 20-27 21-36 22-27 30-12 26-32 28-27 23-35 28-29 28-32 26-24 27-27 19-39. Total 33 cw's against w/
Last edited by dragoneye on Fri Feb 09, 2007 12:50 pm, edited 2 times in total.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Please don't edit your post and change all of it (my original answer here stopped making sense because I didn't quote you)

Here is the answer to your edited question:

Code: Select all

foreach {a b} [split [set vs][set vs ""] "- "] {
	lappend vs [expr {$a>$b?"\00303":($a==$b?"\00312":"\00304")}]$a-$b
}
set vs [join $vs]
EDIT: moved the \003 to prevent expr messing up the return values
Last edited by user on Fri Feb 09, 2007 2:31 pm, edited 1 time in total.
Have you ever read "The Manual"?
d
dragoneye
Voice
Posts: 9
Joined: Tue Apr 19, 2005 4:21 pm

Post by dragoneye »

user wrote:

Code: Select all

foreach {a b} [split [set vs][set vs ""] "- "] {
	lappend vs [expr {$a>$b?"\00303":($a==$b?"\00312":"\00304")}]$a-$b
}
set vs [join $vs]
EDIT: moved the \003 to prevent expr messing up the return values
again man you rock :) thx
d
dragoneye
Voice
Posts: 9
Joined: Tue Apr 19, 2005 4:21 pm

Post by dragoneye »

well how can i make the script add wins losses and draws ?
i tried this but didnt get it to work :(

Code: Select all

set win "0"
set draw "0"
set lose "0"

foreach {a b} [split [set vs][set vs ""] "- "] {
   lappend vs [expr {$a>$b?"[incr lose 1]":($a==$b?"[incr lose 1]":"[incr lose 1]")}]$a-$b
 }
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

dragoneye wrote:

Code: Select all

set win "0"
set draw "0"
set lose "0"

foreach {a b} [split [set vs][set vs ""] "- "] {
   lappend vs [expr {$a>$b?"[incr lose 1]":($a==$b?"[incr lose 1]":"[incr lose 1]")}]$a-$b
 }
you 'incr lose' no matter what...and destroy the value of vs in the process... try to think :P
Have you ever read "The Manual"?
d
dragoneye
Voice
Posts: 9
Joined: Tue Apr 19, 2005 4:21 pm

Post by dragoneye »

well im trying :) but not good with this kinda thingie :(

Code: Select all

 foreach {a b} [split [set vs][set vs ""] "- "] {
   lappend vs [expr {$a>$b?"\00303":($a==$b?"\00312":"\00304")}]$a-$b
	if { $a>$b } { [incr win 1] }
	if { $a==$b } { [incr draw 1] }
	if { $a<$b } { [incr lose 1] }
 }
why dosent that work :L
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

dragoneye wrote:why dosent that work :L
because you do alot of weird stuff that doesn't make sense (like adding random brackets) :P Here's some weird stuff that works:

Code: Select all

set win [set draw [set lose 0]]
foreach {a b} [split [set vs][set vs {}] "- "] {
	lappend vs [if {$a>$b} {
		incr win
		list \00303
	} elseif {$a==$b} {
		incr draw
		list \00312
	} else {
		incr lose
		list \00304
	}]$a-$b
}
set vs [join $vs]
You should read and understand this page http://tcl.tk/man/tcl8.4/TclCmd/Tcl.htm before trying to code any more. It will save you alot of trouble to know the syntax.
Have you ever read "The Manual"?
d
dragoneye
Voice
Posts: 9
Joined: Tue Apr 19, 2005 4:21 pm

Post by dragoneye »

thx again...well im learning more about tcl all the time :) but sometimes i need little help :L
Post Reply