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 wih colour

Help for those learning Tcl or writing their own scripts.
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

help wih colour

Post by Reynaldo »

Code: Select all

PRIVMSG $chan :\(4\002Hi..\002\)
how to set with random color? from 1-15 colour
Please help. :oops:
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

[rand 15] returns a random number between 0 and 14

Code: Select all


  set colour [expr [rand 15] + 1]
  PRIVMSG $chan :\(\003$colour \002Hi..\002\003\)

i hope this helps
I once was an intelligent young man, now i am old and i can not remember who i was.
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

[rand 16]
returns a number in this range [0,15].
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

0 being nothing is probably why he adds 1 :)
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Actually 0 is for white, so I thought he might wanna use it.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

MeTroiD wrote:0 being nothing is probably why he adds 1 :)
There are actually 16 colours, not 15!
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

it's working now..
thank you guys
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

How to made each character from words be different the colour? :roll:
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Reynaldo wrote:How to made each character from words be different the colour? :roll:
All is revealed in Colour and formatting codes.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

i mean, each caracter will be automatically random the color.
says "botnick" , character "b" "o" "t" "n" "i" "c" & "k". will be random eachother & never same color. :roll:
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

proc randomcolors str {
 set str2 ""
 for {set i 0} {$i<[llength [split $str ""]]} {incr i} {
  set rdm [expr {[rand 15]+1}]
  if {[set token [string index $str $i]] != " "} {
   append str2 \003${rdm}$token\003
  } {
   append str2 $token
  }
 }
 set str2
}
Usage:
set string [randomcolors $string]
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

i cant used it on "numbering" ?? :oops:
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

proc randomcolors str {
 set str2 ""
 for {set i 0} {$i<[llength [split $str ""]]} {incr i} {
  set rdm [expr {[rand 15]+1}]
  if {$rdm < 10} { set rdm 0$rdm }
  if {[set token [string index $str $i]] != " "} {
   append str2 \003${rdm}$token\003
  } {
   append str2 $token
  }
 }
 set str2
}
R
Reynaldo
Halfop
Posts: 54
Joined: Wed May 11, 2005 2:51 am

Post by Reynaldo »

Thank you verymuch bro Sir_fz
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You can use this proc, which is much faster:

Code: Select all

proc randomcolors str {
 set str2 ""
 foreach token [split $str ""] {
  set rdm [expr {[rand 15]+1}]
  if {$rdm < 10} { set rdm 0$rdm }
  if {$token != " "} {
   append str2 \003${rdm}$token\003
  } {
   append str2 $token
  }
 }
 set str2
}
Post Reply