mIRC Home    About    Download    Register    News    Help

Print Thread
#111206 13/02/05 07:47 PM
Joined: Sep 2004
Posts: 237
J
JAFO Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Sep 2004
Posts: 237
This isnt so much a scripting question as much as an understanding Tokens in scripting question.
I have been having nothing but problems with tokens and i need a push in the right direction.
So... lets say i have a line of "one two three four five" in a hash table and i want to write it to the
channel. I have no problems with that, but what i want to do is manipulate it before it writes, i want to
grab the first character from each word and color it red, then color the remaining characters in the
word blue. The help files explain it fairly well, but i just cant seem to apply it to what i want to do.
Thanks for all the help you guys give, but please dont just throw an alias or something at me that
will give me the result i am looking for .... i really need to learn this.

#111207 13/02/05 08:50 PM
D
DaveC
DaveC
D
tokens are simply a method of breaking things up.

you said ...
"one two three four five" ... i want to write it to the channel ... first character from each word and color it red, then color the remaining characters in the
word blue.

Ok so the tokenizing is really only relevent here in getting each word, so your tokens are words, now if someoen said "whats a word?" you might say "its any text seperated by a space"
So Space character is the token seperator, space characters asc value is 32, so you might see

/set %text one two three four five Bob seven
//echo -a $gettok(%text,2,32)
two
//echo -a $gettok(%text,6,32)
Bob

The 32 is the seperator of each token


You might have this
/set %text The Cat sat on the mat. The Dog went to the door. The Bird was in the cage. The Man was in bed.
//echo -a $gettok(%text,3,46)
The Bird was in the cage
//echo -a - $+ $gettok(%text,2,46) $+ -
- The Dog went to the door-
//echo -a $gettok(%text,-1,$asc(.))
The Man was in bed

The 46 is the seperator of each token, 46 is asc for . as you see from the 3rd echo you can use the actual character, and get its asc value, but why bother if u already know it.
The second echo also was designed to show you that the leading space is still in the token, just the other 2 echos destroy it when displaying there results.
You well note that the . is not part of the token , it is considered the seperator so isnt included.


So simply tokens are nothing more than a way to break up a bit of text based apon one of the characters in the text.
There are some things to watch out for

Leading and trailing seperator characters are purged (no mater how many)
/set %text .The Cat sat on the mat. The Dog went to the door. The Bird was in the cage. The Man was in bed.
//echo -a $gettok(%text,1,46)
The Cat sat on the mat
/set %text .........The Cat sat on the mat. The Dog went to the door. The Bird was in the cage. The Man was in bed..................
//echo -a $gettok(%text,1,46)
The Cat sat on the mat
//echo -a $numtok(%text,46)
4
//echo -a $gettok(%text,1-,46)
Cat sat on the mat. The Dog went to the door. The Bird was in the cage. The Man was in bed

Also seperator characters directly following one another become one seperator character.
/set %text The Cat sat on the mat............... The Dog went to the door. The Bird was in the cage. The Man was in bed.
//echo -a $gettok(%text,1-2,46)
Cat sat on the mat. The Dog went to the door

The effect of erasing or reducing seperators doesnt effect %text of course unless you load the result of the tokening back into it
/set %text The Cat sat on the mat............... The Dog went to the door. The Bird was in the cage. The Man was in bed.
//set %text $gettok(%text,1-,46)
/echo -a %text
The Cat sat on the mat. The Dog went to the door. The Bird was in the cage. The Man was in bed.


The TOKENIZE command works on the same grounds
//tokenize 46 ....The Cat sat on the mat............... The Dog went to the door. The Bird was in the cage. The Man was in bed.... | echo -a $1-
The Cat sat on the mat The Dog went to the door The Bird was in the cage The Man was in bed
//tokenize 46 ....The Cat sat on the mat............... The Dog went to the door. The Bird was in the cage. The Man was in bed.... | echo -a $2
The Dog went to the door

You well note the . is gone altogether now, since $1- well be $1<space>$2<space>$3<space>$4<space>etc etc


Back to what you wanted, heres one way

assume %text = one two three four five

Code:
var %i = $numtok(%text,32)
while (%i) {
  var %word = $gettok(%text,%i,32)
  var %word = 04 $+ $left(%word,1) $+ 12 $+ $mid(%word,2)
  var %text = $puttok(%text,%word,%i,32)
  dec %i
}


that of course can look like this, but is much harder to read.

Code:
var %i = $numtok(%text,32)
while (%i) {
  var %text = $puttok(%text,04 $+ $left($gettok(%text,%i,32),1) $+ 12 $+ $mid($gettok(%text,%i,32),2),%i,32)
  dec %i
}



Hope this helped

#111208 13/02/05 09:13 PM
Joined: Sep 2004
Posts: 237
J
JAFO Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Sep 2004
Posts: 237
That is Beautiful!
It cleared up every confusion i had.... the help files gave me the idea of how they work , just not the extent of how they work.
And one more quick question.
The asc value for  would be? Because i want to NOT adjust it if it already has an existing color code in it. And offhand the ctrl + C command and the ctrl + b command both leave that tell tale box... there has to be a difference between them for mIRC to alter the text accordingly. What is it?

#111209 14/02/05 12:18 AM
D
DaveC
DaveC
D
you can get the asc of almost all the characters by doing //echo -a $asc() replace  with the one u want

Its 3 by the way its ment to be ctrl-c but ctrl-k is used because (umm welll becuase ctrl-c is already used in mirc to break i guess)

#111210 14/02/05 12:23 AM
Joined: Sep 2004
Posts: 237
J
JAFO Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Sep 2004
Posts: 237
Thanks..... lol yeah ctrl + k .... just one of those things i do without looking at or thinking about. wink

#111211 14/02/05 12:34 AM
Joined: Nov 2003
Posts: 2,321
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,321
Just to add, you can get the ascii number of every character in a string by doing:

Code:
//bset -t &amp;Text 1 [color:red]text[/color] | echo -a $bvar(&amp;Text,1-)


Change text to whatever you want. smile

#111212 16/02/05 07:04 PM
Joined: Sep 2004
Posts: 237
J
JAFO Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Sep 2004
Posts: 237
New question on $remtok.
I have a line of "me & me1 & me2 & me3". I am setting a variable with $matchtok for the "&" tokens and then trying to remove them with $remtok in a loop .... here it is.
Code:
 on *:DIALOG:clonectrl:sclick:2:{
  set %X $did(1)
  set %T $matchtok(%X,&amp;,0,32)
  while (%T &gt; 0) { 
    $remtok(%X,&amp;,%T,32)
    dec %T
  }
}
 

When i run that i get a return of
-
me Unknown Command
-
3 times in status, once for each & in the string.
So where am i going wrong?
Note: I know i only need local variables, i just use the globals for now so i can see my progress, or lack of.
Thanks again!

#111213 16/02/05 07:09 PM
M
mIRCManiac
mIRCManiac
M
try set %X $remtok(%X,&,%T,32)

Code:
on *:DIALOG:clonectrl:sclick:2: {
  set %X $did(1)
  set %T $matchtok(%X,&amp;,0,32)
  while (%T &gt; 0) {
    [color:green]set %X $remtok(%X,&amp;,%T,32)[/color]
    dec %T
  }
}

Last edited by mIRCManiac; 16/02/05 07:10 PM.
#111214 16/02/05 07:17 PM
Joined: Sep 2004
Posts: 237
J
JAFO Offline OP
Fjord artisan
OP Offline
Fjord artisan
J
Joined: Sep 2004
Posts: 237
Oh yeah.....lol, that worked.
Thanks!

#111215 16/02/05 07:19 PM
M
mIRCManiac
mIRCManiac
M
You're welcome. smile


Link Copied to Clipboard