mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2025
Posts: 3
V
Self-satisfied door
OP Offline
Self-satisfied door
V
Joined: Feb 2025
Posts: 3
I had an AI write this script and description of this possible issue. (I could easily just be doing something wrong.)
I am mainly posting this here for others who might encounter the issue. I appreciate any clarification as to what I may be getting incorrect here.
I'm not posting this in Bug Reports, as I don't think it's an actual bug.

; --begin script:

alias BinVarDemo.ApplyFix {
return $false
}

alias BinVarDemo {
; Reset debug window
window -c @BinVarDemo
window -n @BinVarDemo

; Simulate a POST request (first call)
BinVarDemoRequest POST http://example.com/post "data=123"

; Simulate a GET request (second call, shows overlap or fix)
BinVarDemoRequest GET http://example.com/get ""
}

alias BinVarDemoRequest {
; Two ways to fix binvar overlap:
; 1. Use named binvars (toggle BinVarDemo.ApplyFix to $true)
; 2. Add '/bunset &data' here to clear it each call
var %method = $1
var %url = $2
var %payload = $3

; Set empty header binvar (required for $urlget)
bset -t &empty 1 ""

; Use named binvar if fix is applied, otherwise shared &data
if ($BinVarDemo.ApplyFix) {
var %data.binvar = $+(&data, ., %method)
if (%method == POST && %payload) {
bset -t %data.binvar 1 %payload
}
}
else {
if (%method == POST && %payload) {
bset -t &data 1 %payload
}
}

; Log state before urlget
noop $debugOut(@BinVarDemo, $timestamp Before urlget - Method: %method)
noop $debugOut(@BinVarDemo, URL: %url)
noop $debugOut(@BinVarDemo, Payload: %payload)
if ($BinVarDemo.ApplyFix) {
; Check if binvar exists before $bvar to avoid error
noop $debugOut(@BinVarDemo, BinVar Size: $bvar(%data.binvar, 0))
noop $debugOut(@BinVarDemo, BinVar Content: $iif($bvar(%data.binvar, 0), $bvar(%data.binvar, 1, 100).text, <empty>))
}
else {
noop $debugOut(@BinVarDemo, BinVar Size: $bvar(&data, 0))
noop $debugOut(@BinVarDemo, BinVar Content: $bvar(&data, 1, 100).text)
}

; Start request with named or shared binvar based on fix
var %id = $urlget(%url, $+($lower($left(%method, 1)),b), &response, BinVarDemoCallback, &empty, $iif(%method == POST && %payload && $BinVarDemo.ApplyFix, %data.binvar, $iif(%method == POST && %payload, &data, $null)))
}

alias BinVarDemoCallback {
var %id = $1
; Log callback
noop $debugOut(@BinVarDemo, $timestamp Callback for ID %id)
}

alias debugOut {
; Log to debug window
aline -hp $1 $2-
}

;--end script


Description

Binary Variable Overlap in mIRC – Not a Bug, But a Common Pitfall

In mIRC, binary variables (e.g., &data) are powerful for handling large data with commands like $urlget, but their persistence can trip you up. Unlike local var variables that vanish when an alias ends, &binvars stick around until explicitly cleared or the script fully resolves—including any asynchronous calls like $urlget. This isn’t a bug—mIRC’s designed this way to let binvars pass data across events—but it’s an easily encountered issue when you assume they reset like var.
Take this demo: a POST request sets &data to "data=123", then a GET request reuses it. Without workarounds, the GET sends that POST data too—unexpectedly altering the request and potentially causing server-side failures (like state: fail in vUpdateChecker). Two fixes: 1) Use per-call named binvars (e.g., &data.POST, &data.GET)—ensures each request’s binvar is isolated, avoiding overlap. 2) Clear the binvar with /bunset &data before each call—wipes the slate clean, preventing carryover. It’s not a flaw in mIRC, just a nuance—knowing &binvars linger for $urlget’s callback lifespan, you can dodge the pitfall with either approach.

Verification

Script:
Comment added—shows both fixes: named binvars (toggle $true) or /bunset (add manually).
No functional change—still runs with overlap ($false) or fix ($true).

Description:
Now lists two solutions: named binvars and /bunset—matches script options.

Test It

• Overlap: Leave return $false—run /BinVarDemo, see &data persist in GET.
• Fix: Change to return $true—run again, GET uses &data.GET, no overlap.
• Manual /bunset: Add /bunset &data after bset -t &empty 1 "" with $false, rerun—overlap gone.

Joined: Jul 2006
Posts: 4,222
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,222
As you said this is not a bug, just how binvar were implemented. They get destroyed at the end of the script execution.
You can get the same behavior with regular %variable by using /set -u (same as /set -u0). /set -u %variable and binvar are called semi global for this reason, they are not fully global, but not fully local either.
mIRC does not have a way, good or bad, to pass binvar to aliases or command unless the command is explicitely made to support binvar, which is probably why they were implemented that way, so you can access them in nested aliases calls.
Quote
including any asynchronous calls like $urlget. This isn’t a bug—mIRC’s designed this way to let binvars pass data across events—
Note that this is wrong, $urlget has nothing to do with it and you cannot pass binvar across events, as events always trigger in different script execution, with the exception of on signal perhaps.
Just like /timer, $urlget always triggers after the script's execution in which it was called ends, meaning the binvar that you created prior calling $urlget are ALWAYS lost when the callback alias of $urlget triggers, you're probably confused if you use the binvar output mode of $urlget, then it is mIRC who creates the binary variable for you, prior calling your callback alias, and mIRC does that in the same script execution, obviously.


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

Link Copied to Clipboard