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 number or 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.

When started, calls a custom block ‘named_greeting’ with a parameter. It prints ‘Hello, ’ followed by the given name on the screen.#
    define named_greeting (name) :: custom
        [Define a My Block with a parameter]
        print [Hello, ] on screen ▶
        print (name) on screen ▶

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