This guide will help you understand the syntax of actions, how they work and how they can be used.

First of all, we need to ask ourselves "What is a function?"

A function is a collection of statements that together perform a task. Every program has at least one function – the function called "function main".

Therefore, you can divide your code into separate functions, such that each has one specific task. How you divide the tasks is entirely up to you.

All the additional functions are written outside the main function (in separate actions), and afterwards called in the main function.


Basic Syntax

action name then

| action body

end action


Tutorial

To further understand how an actions work, try running the following tutorials:

  • Tutorial - "Draw a Mickey Mouse face"

    Description:As you will see this script has a main function called "function main()" that calls 4 other different functions: set background, draw 1st ear, draw head, draw 2nd ear. These functions are declared separately and each performs a different task as you can see from their name declaration.


    Touch Develop Commands

    The tutorials use a set of basic commands you might not have seen before.

    wall -> set background(picture -> Picture) - sets the background of the wall to a chosen picture.



    Exercises

    Now try it yourself.

    1. Try to draw a house using a square and a triangle. Construct a different action for each shape then call them in the main function.


    Don't stop here! Experiment with the commands you have learned and create scripts of your own.



    PREVIOUS LESSON

    NEXT LESSON

    BACK TO INDEX