a Dr. Scratch

Duplicated Scripts

Imagine that in a project we have two programs formed by the same blocks and where only vary the parameters or values of the blocks.

whenIreceivemessage1setrotationstyleleft-rigtrepeat10move2stepsnextcostumeifonedge,bouncewait1secs
whenIreceivemessage2setrotationstyleleft-rigtrepeat5move4stepsnextcostumeifonedge,bouncewait0.5secs

What would happen if we make a small change? We would have to modify both programs, complicating the maintenance of the code. In these situations is more appropriate that the programmer make his own block that defines this behaviour and use this new block in all programs where needed.

definewalkrepetitionssteppausesetrotationstyleleft-rigtrepeatrepetitionsmovestepstepsnextcostumeifonedge,bouncewaitpausesecs

Thus, if you want a change, you just have to go to the block defined by the programmer.