Context is reset to default when input is 0

because of this line

context.dim = context.dim || 100.0;

When you set context.dim to 0, the next time it runs, it gets the 100.0

THE REASON IS... 0 == false

Do this instead...

if(context.dim == "undefined"){
  context.dim = 100.0 //init value ONLY if its undefined
}

NOTE: accessing context in this manner is depreciated (see the node red documentation on context.get, context.set)