Diagnostics
T436
loop or handler variable cannot be reassigned
T436
The key and member names of a family loop or family handler are fixed for each member and cannot be assigned. Copy the value into a let local and assign that instead.
Failing example
script "conf"
data chart = subscribe(data.ohlcv)
plot out = plot.line(title: "out")
setup fam = for key in ["a", "b"] { key == "a" ? 1.0 : 2.0 }
on chart.update {
let acc = 0.0
for k, v in fam {
k = "zz"
acc += v
}
out.plot(acc)
}Corrected example
script "fixed"
data chart = subscribe(data.ohlcv)
plot out = plot.line(title: "out")
setup fam = for key in ["a", "b"] { key == "a" ? 1.0 : 2.0 }
on chart.update {
let acc = 0.0
for k, v in fam {
let label = k
acc += label == "a" ? v : 2.0 * v
}
out.plot(acc)
}