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.

                when I receive [message1 v]
                set rotation style [left-rigt v]
                repeat (10)
                move (2) steps
                next costume
                if on edge, bounce
                wait (1) secs
            
                when I receive [message2 v]
                set rotation style [left-rigt v]
                repeat (5)
                move (4) steps
                next costume
                if on edge, bounce
                wait (0.5) secs
            

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.

                define walk (repetitions)(step)(pause)
                set rotation style [left-rigt v]
                repeat (repetitions)
                move (step) steps
                next costume
                if on edge, bounce
                wait (pause) secs
            

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