<< Chapter < Page Chapter >> Page >

Passing parameters

This process of providing information to a function when you call it is commonly referred to as passing parameters to the function. For the square-root function, you need to pass a parameter whose value is the value ofthe number for which you need the square root.

You call the built-in square root function in Scratch 2.0 by dragging the bottom block shown in Image B into the programming panel and selecting sqrt in the pull down list. You pass the parameter by entering a literal value or dragging a variable block into the white areathat contains the 9 character in Image B .

Returning values

A function or method will usually

  • Perform an action,
  • Send back an answer
  • Some combination of the two

Performing an action

You might think of performing an action as something like causing a Scratch sprite to move to the right and change color.

None of the Scratch 2.0 mathematical functions shown in Image C perform an action. One of the purposes of this module is to teach you how to create customblocks that do perform an action.

Sending back an answer

On the other hand, a function that is designed to calculate the square root of a number needs to be able to send the square-root value back to the programthat called the function. After all, it wouldn't be very useful if the function calculated the square root and then kept it a secret. The process of sendingback an answer is commonly referred to as returning a value .

All of the Scratch mathematical functions shown in Image C return a value.

It appears that there is no straightforward way for you to cause a custom block that you design to return a value. However, I will show you a workaroundfor that situation later.

Creating your own custom blocks

The best explanation that I have found for the mechanics of creating a custom block is contained in the document titled How Do I Use the New Blocks? on the MIT website. Go to that webpage and scroll down to the section titled Make Your Own Blocks . Follow the instructions that you find there to create your own custom blocks.

Sample programs

With that as an introduction, this section will present and explain two Scratch 2.0 programs built around custom blocks.


This is the simplest custom block that I could come up with that:

  • Receives an incoming parameter
  • Uses the value of that parameter to compute and return a value

This program contains the two scripts and a variable shown in Image D . These scripts are tied to the cat sprite.

Image d. program code for customblocktest01.

Missing image.
Image D. Program code for CustomBlockTest01.

A global variable

The variable named var shown on the left in Image D is a global variable. That means that it is accessible by any code in the program.

The custom block

The custom block named test is shown in the bottom script in Image D . When called, this block receives an incoming numeric parameter known locally as number1 . The code in the block multiplies that value by a factor of 2 and stores the resulting product in the variable named var , making it available to the code that called the custom block.

Questions & Answers

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Teaching beginners to code. OpenStax CNX. May 27, 2013 Download for free at http://cnx.org/content/col11498/1.20
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?