79079642

Date: 2024-10-11 20:31:31
Score: 0.5
Natty:
Report link

The sequential IF statements cancel each other

Here is a simplified version of your program logic. If you run this in the Scratch IDE you'll find that the output value is the same as the input value. Why doesn't the value change when it is greater than screen_x?

If you follow the comments in the figure, you'll notice that both "if" statements are executed. The first changes the value and the second changes it back. So this logic clearly won't help us reverse the trajectory of the ball. You might be able to fix this by instead using if-then-else logic, but there is a much better way.

(click image to enlarge)

Scratch programming if statements

Fortunately, Scratch can handle the ball physics for you with an If on Edge, Bounce block. See the Pong Starter by ScratchTeam for an easy example.

Scratch programming Bounce Block

Reasons:
  • RegEx Blacklisted phrase (1): help us
  • Long answer (-0.5):
  • No code block (0.5):
  • Contains question mark (0.5):
  • High reputation (-1):
Posted by: Yogi