You seem to have way too many variables. A much easier version is this:
Alias fac {
var %i = $$1
var %j = 1
While %i > 1 { %j = $calc(%j * %i) | dec %i }
return %j
}
It doesn't have error checking, but it works as expected when given proper input. Note that this version only will do anything useful if used as an identifier.
A slightly better version which checks if it was called as an identifier or not.
Alias fac {
var %i = $$1
var %j = 1
While %i > 1 { %j = $calc(%j * %i) | dec %i }
if ($isid) { return %j }
else echo -a %j
}
And finally with a bit of error checking:
Alias fac {
var %i = $$1
if !$regex($$1,/^\d+$/) { echo -a Error: $$1 is not a number | halt }
var %j = 1
While %i > 1 { %j = $calc(%j * %i) | dec %i }
if ($isid) { return %j }
else echo -a %j
}