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 

problem with list / mysql

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


Joined: 19 Apr 2005
Posts: 9

PostPosted: Fri Feb 09, 2007 12:06 pm    Post subject: problem with list / mysql Reply with quote

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

Code:

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
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Fri Feb 09, 2007 2:21 pm    Post subject: Reply with quote

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:
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
_________________
Have you ever read "The Manual"?


Last edited by user on Fri Feb 09, 2007 2:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
dragoneye
Voice


Joined: 19 Apr 2005
Posts: 9

PostPosted: Fri Feb 09, 2007 2:30 pm    Post subject: Reply with quote

user wrote:
Code:
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 Smile thx
Back to top
View user's profile Send private message
dragoneye
Voice


Joined: 19 Apr 2005
Posts: 9

PostPosted: Fri Feb 09, 2007 3:14 pm    Post subject: Reply with quote

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


Code:

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


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Fri Feb 09, 2007 3:29 pm    Post subject: Reply with quote

dragoneye wrote:
Code:

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 Razz
_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
dragoneye
Voice


Joined: 19 Apr 2005
Posts: 9

PostPosted: Fri Feb 09, 2007 3:43 pm    Post subject: Reply with quote

well im trying Smile but not good with this kinda thingie Sad
Code:
 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
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Fri Feb 09, 2007 5:16 pm    Post subject: Reply with quote

dragoneye wrote:
why dosent that work :L

because you do alot of weird stuff that doesn't make sense (like adding random brackets) Razz Here's some weird stuff that works:
Code:
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"?
Back to top
View user's profile Send private message
dragoneye
Voice


Joined: 19 Apr 2005
Posts: 9

PostPosted: Sat Feb 10, 2007 7:41 am    Post subject: Reply with quote

thx again...well im learning more about tcl all the time Smile but sometimes i need little help :L
Back to top
View user's profile Send private message
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