mIRC Homepage

/tokenize and $null

Posted By: NaquadaServ

/tokenize and $null - 17/10/05 09:53 AM

This really should be called a bug, but I think some may disagree that's it's a bug. It certainly sucks to work-around.

//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 3 -

Do I really need to explain why it isn't good that /tokenize act this way? If I write a script that expects $3 to be "3", it's now $null. The reason /tokenize does this is probably linked with X>1 spaces is always one space (why do that?!?!?!).

Also but related, token handling identifers (such as $gettok), should support $null tokens for the same reason.

Naquada
Posted By: ClickHeRe

Re: /tokenize and $null - 17/10/05 10:55 AM

I think the spaces you meant are not there, you should enclose your example into code tags to preserve the space aspect of it.

And mIRC has always done this before in removing spaces and I don't think it will change in the futur. Same thing with null tokens in the $*tok idents.
Posted By: NaquadaServ

Re: /tokenize and $null - 17/10/05 03:40 PM

Not talking about spaces (well not specifically), I'm only talking about $null tokens.

Yeah always done it, but that's not to say it's wise to keep it.
Posted By: mIRCManiac

Re: /tokenize and $null - 17/10/05 03:42 PM

I think he means your two examples above are
identical except for the missing 2 and shifted 3.

Yours
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 3 -

Did you mean it to be?..
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3
//tokenize 44 1,,3 | echo -a $1 - $2 - $3 == 1 - 3 -
1 - 3 - == 1 - 3 -

or?..
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3
//tokenize 44 1, ,3 | echo -a $1 - $2 - $3 == 1 - 3 -
1 - - 3 == 1 - 3 -
Posted By: DaveC

Re: /tokenize and $null - 17/10/05 09:49 PM

Quote:
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 3 -


What are you on about?????? The results of above are....

1 - 2 - 3 == 1 - 2 - 3
1 - 2 - 3 == 1 - 3 -
Posted By: starbucks_mafia

Re: /tokenize and $null - 17/10/05 10:29 PM

Quote:
The reason /tokenize does this is probably linked with X>1 spaces is always one space (why do that?!?!?!).

- Because when someone types something into the command-line like:
Code:
/msg   someguy hi there!

the're about a one in a billion chance that they meant to try and send a message to someone with no nick. The same goes for pretty much every other IRC command. Remember that that's what mIRC scripting really was made for - to allow people to simplify/automate certain tasks within IRC, and so the 'language' is designed to aid people to that end. It was never originally intended to be someone's programming language of choice for any and every task, so why would things like null tokens have been supported? Changing the default behaviour now would be incredibly stupid.
Posted By: mIRCManiac

Re: /tokenize and $null - 17/10/05 10:41 PM

[Rudeness removed by author], but the two tokenize
commands in his examples are identical. I (and obviously
ClickHeRe) think he intended for a couple of spaces, or a
null token
to be in his examples that are not. All he did
was remove the 2 and shift the 3 in the expected result
of his second example.

Quote:

//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3 <-- 1
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 3 - <-- 2


1 - 2 - 3 == 1 - 2 - 3 <-- 1
1 - 2 - 3 == 1 - 3 - <-- 2

Actual results
Expected results
Posted By: DaveC

Re: /tokenize and $null - 17/10/05 11:21 PM

I dont think so, he mentiones not talking about spaces, looking at it again i now think he screwed up the example, i think he ment to use this
//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3
//tokenize 44 1,,3 | echo -a $1 - $2 - $3 == 1 - 3 -

I think hes saying the $null field between the 2 ,, should be seen as $2, and i can see where hes coming from with that (not that i aggree).
I used 46 over 44 becuase there easier to insert into a $+()
Code:
//var %a = 1, %b = 1, %c = 3 |  tokenize 46 $+(%a,.,%b,.,%c) | echo $!1= $1     $!2= $2     $!3= $3
$1= 1     $2= 2     $3= 3
.
//var %a = 1, %b = $null, %c = 3 |  tokenize 46 $+(%a,.,%b,.,%c) | echo $!1= $1     $!2= $2     $!3= $3
$1= 1     $2= 3     $3=


He wants to maintain the location of his values but insert them into $N values, with the posablility that any $N value maybe a $null string.

As im sure you know you can call an alias as an identifier and manage the effect of creating $null $N values.
Code:
alias example ( echo $!1= $1     $!2= $2     $!3= $3 )
//var %a = 1, %b = $null, %c = 3 | .echo -q $example(%a,%b,%c)
$1= 1     $2=     $3= 3


I personally wouldnt like it, i have depended on the exact opersite effect , tokenize 32 %a %b %c, to get $1=1 and $2=3
Posted By: NaquadaServ

Re: /tokenize and $null - 19/10/05 05:34 PM

oops thanks...

I did mean...

//tokenize 44 1,2,3 | echo -a $1 - $2 - $3 == 1 - 2 - 3
//tokenize 44 1,,3 | echo -a $1 - $2 - $3 == 1 - 3 -
Posted By: NaquadaServ

Re: /tokenize and $null - 19/10/05 05:50 PM

Quote:
I personally wouldnt like it, i have depended on the exact opersite effect , tokenize 32 %a %b %c, to get $1=1 and $2=3


Are you serious? I would love to see an example of where this might be useful...

Here is my logic and reason... There is no easy way to pass null parameters to a signal... In effect this is what I'm trying to do.

Code:
alias usetest { echo -a $test(1, $null, 3) }
alias test { signal Blah $1 $2 $3 }
on *:signal:Blah:{
  var %A $1 | var %B $2 | var %C $3
  if (%B != $null) { return } ; Oops if $2 in 'test' was null, %B==3
  ; if $1 || $2 || $3 could == $null, How can I know which was $null
  ; since their location is meaningless
}
Posted By: Riamus2

Re: /tokenize and $null - 19/10/05 06:53 PM

It may be a workaround, but you can always pass a special character for $null (this if for if you aren't using an alias, though it could be set up for use with the alias as well)...

Pick a character (such as ~):
if (%A == $null) var %A = ~

Or, use the word NULL:
if (%A == $null) var %A = NULL

Then, you can just ignore that character (or word) when looking at the data... it's basically just a spacer.

Another option would be to put leading and/or trailing characters on all variables (this is for either with or without the alias)...

var %A = .1.

Then, when you get a $null, you have .. with nothing else (easy to notice). And the leading/trailing .'s are easy to remove when getting the data. You could, of course, choose another character instead of .'s. It was just an example. smile

I think that changing $null would be very difficult as I believe all commands will ignore $null as if it's not there. To change it for this would mean it would need to be changed everywhere.
Posted By: DaveC

Re: /tokenize and $null - 19/10/05 07:52 PM

Quote:
Are you serious? I would love to see an example of where this might be useful...

Code:
alias committurn {
  var %players = $gamevalue($1,$2,$3,&lt;,players), %text = $gettok(player1action player2action player3action player4action player5action player6action player7action player8action,$+(1-,%players),32),  %order . . . . . . . .
  while (%players) {
    var %r = $r(1,%players), %order = $puttok(%order,$gettok(%text,%r,32),%players,32), %text = $deltok(%text,%r,32)
    dec %players
  }
  tokenize 32 $1 $2 $3 $gamevalue($1,$2,$3,&lt;,$gettok(%order,1,32)) $gamevalue($1,$2,$3,&lt;,$gettok(%order,2,32))  $gamevalue($1,$2,$3,&lt;,$gettok(%order,3,32))  $gamevalue($1,$2,$3,&lt;,$gettok(%order,4,32))  $gamevalue($1,$2,$3,&lt;,$gettok(%order,5,32))  $gamevalue($1,$2,$3,&lt;,$gettok(%order,6,32))  $gamevalue($1,$2,$3,&lt;,$gettok(%order,7,32))  $gamevalue($1,$2,$3,&lt;,$gettok(%order,8,32))
  commitactions $1-
}



Quote:
Here is my logic and reason... There is no easy way to pass null parameters to a signal...

alias usetest { echo -a $test(1, $!null, 3) }
or
alias test { signal Blah $iif($1 == $null,$!null,$1) $iif($2 == $null,$!null,$2) $iif($3 == $null,$!null,$3) }

Essentially what Ramius said, use a symbolic place holder, since "$null" is not quite but damn close to $null, functions the same when compared at least.
© 2020 mIRC Discussion Forums