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.
VerificationScript:
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.