mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Never mind again! One of these days I'll catch a real bug.

Click to reveal.. (Old post)

I think I'm not imagining it this time.

The script below should go back and forth between unset and inc, but every second time you run the script, it repeats "unset" twice. Tested it on mIRC 7.43-7.46 and even asked a friend to try it, who got the same result.

A few things I tried:
  • "var %x = 15,%o 1" OR "var %x = 15,%o = 1" "var %x = 15,%o $true" OR ""var %x = 15,%o = $true"
    Result seems to vary. Sometimes it gets stuck and gives you unset twice, and sometimes it works like it should. It seems to change the state when you switch do one or more runs with "1" or "$false".
  • "var %x = 15,%o" OR ""var %x = 15,%o 0" OR "var %x = 15,%o = 0" OR "var %x = 15,%o $false" OR "var %x = 15,%o = $false"
    Gives you unset twice in a row every other run.
  • "unset %o" at the start
    Works like it should every single time.
  • "unset %o" twice in the loop
    Works like it should every single time.
Code:
alias unsetinctest {
  var %x = 15,%o
  echo -at * $str(-,10)
  while (%x) {
    if (%o) {
      unset %o
      echo -at * unset
    }
    else {
      %o = 1
      echo -at * inc
    }
    dec %x
  }
}


Last edited by Dazuz; 04/08/16 09:21 PM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
This is not a bug, you first assign $null to %o with /var, making it a local variable, but once you /unset, the syntax "%o = 1" creates a global variable, visible in the variable tab of the script editor.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
You can do "inc %o" instead of "%c = 1" too, but I guess that counts as global, but in that case why would it also keep the earlier value set with var?

As in:
Code:
var %x = 1
while (%x <= 10) {
  inc %x
}

It keeps the value like it should.

There's a chance I'm too tired, but what's the distinction? As far as I know, you can pretty much mix global and local variables as you like, but in this case it just doesn't work.


EDIT: to rephrase that: if you can use inc, why not unset too?

Last edited by Dazuz; 04/08/16 08:41 PM.
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Unsure what you are saying, in that piece of code you declare %x as a local variable, you never unset it.
But /inc or /dec are unrelated to local/global variable state (although just like /set, they will create a global variable if the variable does not exist). You (in theory) can't have a local variable and a global variable at the same time, more importantly, if you thought /set was meant for global variable, well, that's wrong as well!

Code:
//var -s %a 1 | set -s %a 2 | echo -sg %a -- $var(%a,1).local | unset %a
Quote:
* Set %a to 1
* Set %a to 2
2 -- $true

----
Code:
//set -s %a 1 | var -s %a 2 | echo -sg %a -- $var(%a,1).local | unset %a
Quote:
* Set %a to 1
* Set %a to 2
2 -- $true
As you can see, /var defines a local variable, but after that, you can use /set to change the value of that local variable, /set really just set the variable, and only if the variable doesn't exist as a local variable, /set takes the liberty to create a global variable.
The syntax "%var = " is simple an equivalency of /set, this can be observed using the following:
Code:
//echo -sg $(%a = 1)
Note that you have an undocumented -l switch for /set, which changes the state to a local variable (or just set a local variable if the variable doesn't exist, of course):
Code:
//set -s %a 1 | set -ls %a 2 | echo -sg %a -- $var(%a,1).local
Quote:
* Set %a to 1
* Set %a to 2
2 -- $true



#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Too tired it is. Makes almost perfect sense now! Didn't take in count that the variable wouldn't count as local after the unset.

Since in theory you can't have same global and local variable at the same time, shouldn't the first var line in the script overwrite any existing global and local variable?

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
That's my bad, I meant to say that you couldn't get a global and a local variable with the same name to be set inside the same 'scope'.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2015
Posts: 148
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Well, that seals it. I should stop posting these without a good night of sleep. Maybe next time!

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Yeah it's always good to ask people on IRC about what you think is a bug before posting here, but I also do it frown


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard