mIRC Home    About    Download    Register    News    Help

Print Thread
[7.46] Weird variable/logica... (Never mind again) #258626 04/08/16 08:26 PM
Joined: Dec 2015
Posts: 116
D
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Dec 2015
Posts: 116
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.
Re: [7.46] Weird variable/logical bug [Re: Dazuz] #258627 04/08/16 08:31 PM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
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.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: [7.46] Weird variable/logical bug [Re: Wims] #258628 04/08/16 08:38 PM
Joined: Dec 2015
Posts: 116
D
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Dec 2015
Posts: 116
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.
Re: [7.46] Weird variable/logical bug [Re: Dazuz] #258629 04/08/16 08:59 PM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
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



Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: [7.46] Weird variable/logical bug [Re: Wims] #258630 04/08/16 09:12 PM
Joined: Dec 2015
Posts: 116
D
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Dec 2015
Posts: 116
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?

Re: [7.46] Weird variable/logical bug [Re: Dazuz] #258631 04/08/16 09:17 PM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
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'.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: [7.46] Weird variable/logical bug [Re: Wims] #258632 04/08/16 09:20 PM
Joined: Dec 2015
Posts: 116
D
Dazuz Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Dec 2015
Posts: 116
Well, that seals it. I should stop posting these without a good night of sleep. Maybe next time!

Re: [7.46] Weird variable/logical bug [Re: Dazuz] #258633 04/08/16 09:22 PM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
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


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net