mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2003
Posts: 655
Om3n Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Code:
alias dec2hex {
   tokenize 46 $$1
  scon -r var $(%a = %a,) $!base( $* ,10,16,2)
  return $replace(%a,$chr(32),.)
}


This code was posted as an alternative to my dex2dex code in a previous thread. However i dont quite understand it all.

I know that tokenize fills the $1 $2 etc with the values of the string you tokenize seperated by the specific charactor, and of corse i understand what replace, and scon -r do.

Where it becomes unfamiliar to me is why is the scon -r needed in order for the variable to be set correctly?

What exactly is $(%a = %a,) doing. At this point %a does not exist, so it really cant be evaluated into something, so would i be correct in assuming that 'var $(%a = %a,)' just returns 'var %a = %a'. The help file states only that $() is used in matchtext field of events to create a dynamic matchtext, doing a small test, leaving out the comma returns set %a instead of %a = %a. Can anybody explain $() to me a little better than the help file seems to and why the comma makes such a difference.

I see that $! refers to the last entered text, so $!base uses the information from $1- that was just tokenized, but what is the purpose of $*, does this just run the identifier for each token ($1 $2 etc)?

If that is the case why is "scon -r var $(%a = %a,) $!base( $* ,10,16,2)" needed instead of just "var %a = %a $!base( $* ,10,16,2)" ?

Thanks in advance, im sure somebody can explain this too me a little better than the help file does.


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
$() is short for $eval, just like $r() is short for $rand(). It's not documented in the mIRC help file, but there is a help file somewhere someone else made with all undocumented identifiers.
The comma in $() or $eval makes the second parameter 0 ($null actually I guess) instead of the default 1, so it doesn't parse the contents at all.

$* is a special identifier in that it doesn't just return a value, it re-executes the entire line it's in, each time replacing itself by $1 then $2 then $3 until all $n are done. Simple example:
//tokenize 32 a bc def ghij | echo -s $* $len($*)

Now to the scon part: this will evaluate the line in the given network context (unneeded here, since it uses -r) but is a vessel for the $* identifier to work ok. Also, the $! construct in $!base is a shorthand notation for $eval($base,0) that works only for identifiers. This is needed since /scon, just like /timer (and /flash too?) evaluates the line when it's set, but also when it's executed, and you want the $base to work the second time, not the first.

Simple example:
//timer 1 1 echo -s $time $!time $!!time | timers
You see that in the timer definition the first time is already filled in since it was calculated at the time it was set. The output of the timer is the second time expanded too, since it's re-evaluated when the timer triggers. The 3rd time is still $time and nor expanded, since there were 2 !'s to prevent both evaluations. Each evaluation removes a !.

Suppose you do this:
//echo -s $dec2hex(1.5.10.15)

Then what's executed is:

tokenize 46 $$1
var %a = %a $base( $1 ,10,16,2)
var %a = %a $base( $2 ,10,16,2)
var %a = %a $base( $3 ,10,16,2)
var %a = %a $base( $4 ,10,16,2)
return $replace(%a,$chr(32),.)


So %a is now 01.05.0A.0F and that's echoed to the status window.

The problem with this script is if you want the . to mean decimal point: $dec2hex(10.5) and $dec2hex(10.0000000005) both return 0A.05

Anyway, welcome to the wonderful world of undocumented mIRC features wink

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The key point here and the reason for going through the trouble of using /scon (and because of that, stuff that prevent evaluation, like ! and $eval(...,0)) is that $* cannot be passed to identifiers (well it can, but it doesn't work correctly). So what's happening here is actually the evaluation of $* inside the script, so that "inside" /scon's environment there will be no $*, but the value(s) of it. Those values will be input to $base().


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
A version of the mIRC help file, that contains some items that are not documented in the official help file can be found here

Joined: Jul 2003
Posts: 655
Om3n Offline OP
Fjord artisan
OP Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
Thank you for the detailed explanations, glad to see i wasn't too far off with my initial thoughts. It is a shame things like $* are not documented as i can see how this could be very useful in other situations.

Last edited by Om3n; 25/09/05 06:17 PM.

"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
alias dec2hex {
tokenize 46 $$1
scon -r var $(%a = %a,) $!base( $* ,10,16,2)
return $replace(%a,$chr(32),.)
}


There is actually a bug in the original code, the %a is not predefinde as $null before its accessed so any global %a well be pulled in

/set %a blah blah
//echo -a $dec2hex(01.45.1.255)
Blah.Blah.65.2D.01.FF

this would fix it.
Code:
alias dec2hex {
  tokenize 46 $$1
  var %a
  scon -r var $(%a = %a,) $!base( $* ,10,16,2)
  return $replace(%a,$chr(32),.)
}


My real %a value was of all things 34.FF so i was getting 34.FF.65.2D.01.FF which of course made it appear like a hexed set of values.
I mentioned this more becuase looking at the code you might well think, Damn were is this extra leading info coming from, var %a wont have anything in it etc etc

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Yep, using global %vars with less than 5 characters should be forbidden smile


Link Copied to Clipboard