One of the great things in computer programming
is once you've taught a computer how to do
an action, you can call that function again.
You give it a name and then you can call it.
That's really like extending the language.
In the program we built, we learned how to
draw a square by moving and turning four times.
We can take that function and give it a name,
draw a square so that any time we want to
do that, we simply say draw a square and it
will go back and invoke that function, that
code and it will get done for us. We've added
that concept to our programming language.
In this puzzle, we have already created a
draw a square function for you. You'll see
it in the toolbox as a green block. What you'll
need to do is write the same code you wrote
before to draw a square and put it in this
function. To do that, click on the edit option
in the green draw a square block. This will
open up the function editor. The function
editor has three parts. A place where you
name your function. This will appear on the
green block before that function. Then write
out a short description of what your function
is supposed to do. In this case, it's supposed
to draw a square. The white space below this
is the work space and works just like the
work space you've already been using. Drag
and drop blocks from the toolbox into this
work space. Remember to put the blocks that
create a square inside the green wrapping
block for the function. Once you're done,
click on save and exit. This will take you
back to the main puzzle work space. Now you
can use the draw the square function block
just like any other block to solve the puzzle.
Modifica di Funzioni
Una delle cose più utili della programmazione
è che una volta che hai insegnato ad un computer
come fare un'azione, puoi richiamare nuovamente
quella "funzione" (function).
Le dai un nome e dopo puoi richiamarla.
È proprio come ampliare il linguaggio.
Nel programma che hai costruito,
hai imparato come disegnare un quadrato
avanzando e poi girando per quattro volte.
Puoi prendere quella funzione e darle un nome,
ad esempio "disegna un quadrato" (draw a square),
in modo tale che ogni volta che vorrai farlo,
potrai semplicemente dire "disegna un quadrato"
e il computer richiamerà la stessa funzione,
eseguendo sempre quello stesso codice.
Hai aggiunto quel concetto al tuo
linguaggio di programmazione.
In questo esercizio, abbiamo già creato per te
la funzione "disegna un quadrato" (draw a square).
La vedi nella cassetta degli attrezzi
come un blocco verde.
Ciò che devi fare è scrivere lo stesso codice
che hai già scritto per disegnare un quadrato
e metterlo in questa funzione.
Per farlo, clicca sul pulsante blu
"modifica" (edit)
nel blocco verde
"disegna un quadrato" (draw a square).
Questo ti aprirà l'editor della funzione
che è suddiviso in tre parti.
Una parte in alto in cui puoi dare un nome
alla funzione.
Questo apparirà sul blocco verde
di questa funzione.
Poi c'è una parte centrale in cui puoi descrivere
brevemente cosa dovrebbe fare la funzione.
In questo caso, la funzione dovrebbe
disegnare un quadrato.
La parte bianca al di sotto è l'area di lavoro
e funziona esattamente come l'area di lavoro
che stai già usando.
Puoi prendere i blocchi dalla
cassetta degli attrezzi
e spostarli in quest'area di lavoro.
Ricordati di mettere i blocchi che creano
un quadrato
all'interno del blocco verde della funzione.
Quando hai finito clicca su "Chiudi" (Close).
In questo modo ritorni all'area di lavoro
dell'esercizio.
Ora, per risolvere l'esercizio, puoi usare il
blocco funzione "disegna un quadrato" (draw a square)
proprio come qualunque altro blocco.
プログラムのすばらしいことの1つは、一度どのように行えばよいか おしえれば、
それを関数として何度も使えることだ。
名前をつけて、それを呼び出す。
まるで新しいコマンドが追加されたかのようだ。
正方形をかくとき、
前に進んで曲がるを4回行う。
それを関数にして名前をつけけば、
いつでも正方形をかくことができるんだ。
「正方形をかけ」と言えいえば、
関数が呼び出されて、コードが実行される。
プログラミング言語に関数という
コンセプトが加わった。
こんどパズルには、関数「正方形をかく」が
用意されています。
ツールボックスの中にある緑のブロックが、それです。
必要なのは、関数の中に前に書いた正方形をかくコードを入れること。
緑の「正方形をかく」ブロックの[編集]をクリックしてみましょう。
ファンクション・エディターが、開きました。
3つのパートにわかれています。
一番上は名前を入れるところ。
次はこの関数が何をするのかメモするところ。
今回は、「正方形をかく」と入れます。
下はワークスペースで、いつも使っているワークスペースと同じものです。
ツールボックスから、ここに必要なブロックを ドラッグ アンド ドロップします。
正方形をかくためのブロックを 緑のブロックの中に 入れてください。
終わったら、[閉じる]をクリックします。
メインのワークスペースにもどりました。
これで他のブロックと同じように関数「正方形をかく」が
使えるようになりました。
在計算機編程中,有一個很棒的事,
就是…一旦你教會電腦如何執行一個操作,
你可以再次…呼叫 (call)…那個功能 (function)。
然後你給它一個名字然後呼叫它,
那真的就像擴展了這個程式語言。
在我們建立的程式中,我們學會了怎樣通過移動和轉彎四次來畫個正方形。
我們可以將它變成一個函式,然後將它叫做 draw a square,
這樣任何時候我們都可以用它了。
我們只要說 draw a square,然後它就會被呼叫,
就可以透過函式裡的指令幫我們畫出正方形。
這樣,我們就等於是添加了一個新的概念到這個編程語言。
在這一關中,我們已經創建了一個 draw a square(畫個正方形)的函式。
你會在工具箱裡看見它,是一個綠色模塊。
你需要做的是,將你以前寫的,能畫出正方形的程式碼寫到這個函式裡。
若要做到這一點,點擊 draw a square 上的編輯按鈕,這會打開函式編輯器。
函式編輯器有三個部分。一個是命名函式的地方,它會在顯示在綠色的函式積木上,
接著是一個簡短的描述,說明函式的用途是什麼。
在這個例子裡,它會畫出一個正方形。
底下是工作區,和你用過的工作區很類似,
你可以從工具箱裡拖曳積木到這個工作區。
記住將建立正万形的積木放置到綠色的函式積木中,
當你做完了,點擊儲存並離開,
你會回到目前關卡的工作區上,
現在你就可以使用它來解決問題,就像關卡中的其它的積木一樣。