I understand that when you try to execute two identical pieces of code, one using a regular loop and the other utilizing a function and using “pscad” but there is disparity in outputs. The difference in outputs is due to the function "mpcmove".
Kindly refer to the following thread to get a better understanding of the issue and possible workaround.
Thank you,
Shushant