My Blocks#

Introduction#

My Blocks is the equivalent to functions in Python. My Blocks group code into reusable, efficient sections of code designed to perform a specific task. My Blocks can be called multiple times within a program, making code organization easier, and helping to avoid repeated code.

    define myBlock

    myBlock

Parameters

Description

block name

A name you give to your My Block.

parameters

Optional. Variables that accept input values when the function is called, allowing data to be passed into the function. It can be text, a number, or a Boolean.

Defining and Calling My Blocks#

My Blocks#

If a My Block does not require input, you can define it without parameters.

When started, calls a custom block named ‘greeting’ to print ‘Hello!’ on the screen.#
    define greeting
        [Define a My Block to display a message]
        print [Hello!] on screen ▶

    when started :: hat events
        [Call a My Block to display the message]
        greeting

My Blocks with Parameters#

You can also add parameters to My Block, which let you pass in information the My Block needs to work. Possible parameters are:

  • inputs — numbers or text

  • Booleans

    define Divide by 3 (number) :: custom
        [Display the quotient with two decimals.]
        set print precision to [0.01 v] on console
        print ((number) [/ v] (3)) on console ◀ and set cursor to next row

    when started :: hat events
        [Set the equation's dividend.]
        Divide by 3 [4]
        Divide by 3 [12]