Just got a couple of things, to set a variable, you don't need an =, you can just do:
var %i 1
Instead of:
var %u = $calc(%u + 1)
Just declare %u as 0 at the start and then do:
inc %u
Otherwise the script won't necessarily return anything if none of the text is caps.