if stack_pos - sw_stacker > 10 then pos_error
This statement is fine as long as stack_pos is greater than sw_stacker; and the jump will be executed when stack_pos is more than 10 greater than sw_stacker. BUT if stack_pos is less than sw_stacker, then the result of the subtraction will be negative, and since the BASIC Stamp does UNSIGNED comparisons, THE JUMP PATH WILL ALWAYS BE TAKEN. It would be safer to say "
if stack_pos > sw_stacker + 10 then pos_error".
if abs(stack_pos - sw_stacker) < 10 then done_stack
To reiterate, this test will only be made when stack_pos is between sw_stacker and sw_stacker +10. And this jump will ALWAYS be taken UNLESS stack_pos EQUALS sw_stacker + 10.
Thus, the following section will only be executed when stack_pos EQUALS sw_stacker + 10:
neg_error:
error = (sw_stacker - stack_pos)
sw_stacker = 127 - (4 * error) / 10)
... and this, only when stack_pos IS GREATER THAN sw_stacker + 10:
pos_error:
error = (stack_pos - sw_stacker)
sw_stacker = 127 + (4 * error) / 10)
I don't think this is what you intended.
This should do more like what you expected:
Code:
if abs(stack_pos - sw_stacker) < 10 then done_stack
if stack_pos > sw_stacker + 10 then pos_error
neg_error:
error = (sw_stacker - stack_pos)
sw_stacker = 127 - (4 * error) / 10)
pos_error:
error = (stack_pos - sw_stacker)
sw_stacker = 127 + (4 * error) / 10)
Now, I'm not sure whether your code for neg_error and pos_error is correct, but this should get you closer, at least.