Input to 'set' executes twice ( e.g., -2); output of 'set' works as expected

When I implemented the decrement ammo functionality, I noticed that when I connect the output of the “set ammo” block to the print, it works as expected, but when I connect the input to the “set ammo” (e.g., the output of the “subtract 1” block), the first shot makes the ammo go down from 20 to 18. I suspect this may be because it is “instantly” changing the ammo from 20 to 19, and then again printing 19-1=18, so I am always seeing 1 less than the current ammo rather than the current ammo. Not sure if anyone else is seeing this. Is it better in general to use the output of ‘set’ blocks as opposed to their inputs?

1 Like

I recommend using the Decrement function instead of manually subtracting and setting; I accomplished this goal this way:


I do not know why it would be showing the wrong value, but I would assume it has to do with, like you said, how quickly it is changing the ammo. This decrement, as I understand it, automatically updates the variable.

@papajohn0120 That is correct.