mIRC Home    About    Download    Register    News    Help

Print Thread
$v1 and $v2 local instead of global #123358 22/06/05 01:29 PM
Joined: Nov 2003
Posts: 25
N
NeoN Offline OP
Ameglian cow
OP Offline
Ameglian cow
N
Joined: Nov 2003
Posts: 25
Consider this code:
Code:
alias v1test {
  if (1 != 2) {
    echo -ag test1a: $v1 $v2
    var %dummy = $customid
    echo -ag test1b: $v1 $v2
  }
}

alias customid {
  if (3 != 4) {
    echo -ag test2: $v1 $v2
  }
  return $true
}


/v1test results in:
Code:
test1a: 1 2
test2: 3 4
test1b: 3 4


I'd find it more useful if $v1 and $v2 behaved like local vars, ie their scope is limited to the alias or script they are executed in. In that case the example would result in:
Code:
test1a: 1 2
test2: 3 4
test1b: 1 2


That way the code for v1test is independent of whatever happens in customid.

Or does anyone use these identifiers to get info from other aliases? Maybe i'm just missing something...

Re: $v1 and $v2 local instead of global #123359 22/06/05 03:10 PM
Joined: Apr 2004
Posts: 840
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 840
I agree, that would make more sense AND remove a class of very hard-to-trace problems; e.g. just the other day I was helping someone who wondered why $ifmatch had some weird unexpected value, only to discover that he had a custom /msg alias... Nice suggestion!


Saturn, QuakeNet staff
Re: $v1 and $v2 local instead of global #123360 22/06/05 03:44 PM
Joined: Jul 2003
Posts: 77
B
bamaboy1217 Offline
Babel fish
Offline
Babel fish
B
Joined: Jul 2003
Posts: 77
i agree in full it really doesnt make sense why it would be global...


hmmm signed by me
Re: $v1 and $v2 local instead of global #123361 22/06/05 08:15 PM
Joined: May 2003
Posts: 79
A
Artwerks Offline
Babel fish
Offline
Babel fish
A
Joined: May 2003
Posts: 79
It seems like $v1/$v2 stays with their latest global value, which can be useful in some cases, but are really problematic when you're coding and you just don't know where the error is to find out it was the local/global problem. Good suggestion there.

Re: $v1 and $v2 local instead of global #123362 23/06/05 02:38 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
I'd find it more useful if $v1 and $v2 behaved like local vars, ie their scope is limited to the alias or script they are executed in.
That way the code for v1test is independent of whatever happens in customid.
Or does anyone use these identifiers to get info from other aliases? Maybe i'm just missing something...



Agreed however not using $v1 & $v2 maybe $lv1 $lv2. Since the nature of $v1 & $v2 is already known, changing it would cause (some) scripts to fail.

And yes, I have used these to return values to the calling alias,although I could have done other things this seemed easiest at the time, for what i was doing.
heres an example of one i made.
Code:
alias nicks.channels.condition.cmd.failcmd {
  var %i = 1
  while (%i <= $numtok($1,32)) {
    var %l = 1
    while (%l <= $numtok($1,32)) {
      if ( $gettok($1,%i,32) $3 $gettok($2,%l,32) ) {
        return $4
      }
      inc %l
    }
    inc %i
  }
  return $iif($5,$5,.echo -q . $(|,) ;) $iif($null = $null,)
}


could be used like this
$nicks.channels.condition.cmd.failcmd(Dave DaveC Davo,#mirc #mircnet #blah,ison,msg,halt) $v2  $v1  Found ya finally! See my PM please.
!msg $v1 I wanted to talk to you about blah blah blah

Re: $v1 and $v2 local instead of global #123363 23/06/05 05:10 PM
Joined: Jul 2003
Posts: 77
B
bamaboy1217 Offline
Babel fish
Offline
Babel fish
B
Joined: Jul 2003
Posts: 77
true wish this bug would have been discovered sooner but it should be a $lv1 cause as you said some scripts might bank on the current implementation.. so as you said maybe a $lv1 and $lv2 would be a good idea as it makes more sense and allows the use of a global id and a local id


hmmm signed by me
Re: $v1 and $v2 local instead of global #123364 23/06/05 08:55 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I dont know if i would call it a bug, since i would have to say all other $identifiers i can think of are global, so $v1 and $v2 being global would seem to be in line with this. Also $ifmatch has had the same behavour as current $v1 $v2 so it has been known just something thats not overly clear. Also the help file only says its from a IF THEN ELSE construct, it makes no mention of $IIF or WHILE results also effecting them. frown