Is there a way to clear the return values inside of a function so I can guarantee that the return value is what I intend? Or maybe turn off this behaviour for the function?<
I too am having this exact same frustration! I had a function where a variable is supposed to count up $++
Except. I had forgotten the "++" at the end in one iteration. Which was causing the variable's value to be sent to the output buffer. It was very aggravating and time consuming to find! MS should have provided, at minimum, an ability to flush the output buffer before the user gets to assign their desired return value. Anywhew... I believe I have a work around.
Since I assign a return value at the end of the function, my desired value will always be the last entry of the output buffer array. So I've changed the way I call my functions from:
If (FunctionName (parameters)) {}
To:
If ((FunctionName (parameters))[-1]) {}
My particular scenario bit me when I was trying to capture a function $False return. because of my typo above, my IF statement saw it as true because of the garbage in the output, even though my last function output was "Return $False". The last output assigned from the function was the $False value due to the problem resulting from the typo causing mis-calculation. So changing my Function Return Evaluation to:
If (!((FunctionName (parameters))[-1])) {#something went wrong!}
Did the trick by allowing me to evaluate only the last element of the output array. I hope this helps others.