Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 88 - 2632_CodeMind
P. 88

    FUNCTIONS

                     Functions are reusable blocks of code that perform specific tasks. They help organize your code by making
                     it more efficient and easier to understand. You can define a function once and use it multiple times, saving
                     you time and making your code easier to read. They are regularly used when writing code to increase the
                     readability of code, and to allow for reuse of common actions.

                     Benefits of Using Functions
                       Reusability: Avoid writing the same code multiple times.

                       Modularity: Break down complex programs into smaller, manageable parts.
                       Organisation: Easier to locate and modify specific code sections.

                          Steps to Create a Function
                     To create a function follow the given steps:

                     1.  Open the Functions Block:

                        o   In the MakeCode Arcade editor, look for the “Functions” block category. It usually resides at the
                          bottom of the toolbox.
                     2.  Create a New Function:

                        o  Drag and drop the “function” block onto your workspace.
                        o  Rename  the function  to  something  descriptive. For  example,  if the function  will  handle player
                          movement, you could name it “movePlayer”.

                     3.  Add Code to the Function:
                        o   Inside the function block, add the code that defines the function’s behaviour. This could involve moving
                          sprites, playing sounds, or any other actions you want to perform.

                                                                                           Advanced MakeCode Arcade    87

| 83 84 85 86 87 88 89 90 91 92 93 |