Vous êtes sur la page 1sur 227

Scratch cng c lp

trnh ko th dnh cho


hc sinh, gio vin

Bi Vit H, habuiviet@gmail.com,
Ni dung
Mn Tin hc xa v sp ti.
Gii thiu tng quan xut x v ngha ca
Scratch
Mt vi s liu v Scratch.

T duy lp trnh trong mi trng Scratch.

Gii thiu nhanh giao din, cc i tng


chnh, mi trng lp trnh Srcratch.
Ni dung chnh lp trnh Scratch.

Chia s cc d n Scratch cho cng ng.


Ccch X l s
chnh Scratch: X l xu k t

Chuyn ng Mng s

V ha Th tc

m thanh. Clone

Bin nh. Game &

Hi thoi. Application.
Scratch & CS
Cm bin
Scratch & IT
Truyn thng
Mn Tin hc: hin ti
v tng lai
Chng trnh mn Tin hc hin nay
Tiu hc THCS THPT
Cu trc my My
tnh, h My tnh,
tnh. iu hnh. h iu
Tp chut, g Mng Internet. hnh.
bn phm. Son tho. Mng my

Hc v. Bng tnh. tnh. Mng


Son tho. Trnh chiu.
Internet.
Lp trnh
LOGO Lp trnh
Phn mm
Pascal.
Pascal.
CSDL
hc tp. Phn mm hc
Access.
tp.
Mn Tin hc c
Ri rc, khng lin thng, lin mch.
Khng c s vt cht h tr ging dy.

Khng khoa hc hoc rt kh xc nh tnh khoa


hc cht ch v mch chnh ca kin thc.
GV dy khng hng th, khng c ng lc
hc thm, o su thm kin thc.
HS hc nhm chn v kin thc cng ngh b lc
hu vi thc t.
Tin hc l mn khng thi thnh 1 mn ph
trong nh trng.
Mn Tin hc mi
Cn nh gi v thit k li tng th mn Tin hc
trong nh trng.
Phn loi r rng cc module kin thc ca mn
hc ny. 3 mch ni dung chnh:
CS: Khoa hc my tnh.
IT: CNTT v ng dng.
DL: Hc vn s ha ph thng.
Trong 3 hng trn CS s l trng tm, l mch
kin thc khoa hc, logic, cht ch nht.
Tin hc s l mn hc bt buc, hc t lp 1 n
12, ngang bng vi tt c cc mn hc khc.
3 cu thnh ni dung chnh

Computer Information
Science Technoloy
Khoa hc CNTT &
my tnh ng dng

Digital literacy
Hc vn s ha
CS, IT, DL
CS: Khoa hc my tnh.
X l s, t duy gii quyt vn , thit lp chng
trnh, thut ton, t duy my tnh.
IT: CNTT v ng dng.
S dng cng ngh x l s, phn mm ng dng
v to ra cc sn phm s. V d ha, phim, nh,
ng dng trong cc cng vic i sng.
DL: Hc vn s ha ph thng.
Cc k nng c bn, ti thiu cn c trong thi i s
ha, v d: K nng s dng chut, g bn phm; Son
tho vn bn, bng tnh, trnh chiu; Khai thc Internet.
S dng th in t v mng x hi.
Cu hi: lm th no dy Khoa
hc my tnh (CS) cho HS nh tui?

Trng tm ca hng CS trong mn Tin hc l


lp trnh.
Nh vy vn ln nht ca vic i mi
chng trnh mn Tin hc l lm th no a
vic dy lp trnh xung cho cc em nh tui, v
d t cp Tiu hc?
Cu tr li: ngn ng lp trnh ko th, v d
Scratch.
Tng quan v Scratch
Scratch l g?

Scratch l 1 mi trng lp trnh ng dng


c bit, trong vic vit lnh s c
thc hin bng thao tc ko th.
u ra ca Scratch h tr cc cng ngh v
ng dng mi nht ca CNTT-ICT, do vy
cc ng dng ca Scratch rt phong ph.
Scratch c s pht trin bng n 2 nm tr
li y.
Scratch hon ton min ph v chia s rng
ri trong cng ng.
Scratch rt thch hp
cho nh trng
Scratch rt thch hp to ra cc ng dng
ha, animation, bi hc, bi ging, m phng
kin thc, trnh din, sch in t, tr chi,
rt ph hp vi nh trng, gio vin.
Scratch l mi trng tt nht dy HS lm
quen vi t duy my tnh, khoa hc my tnh
ngay t la tui tiu hc.
Hin nay Scratch c nhiu nc nh Hoa
k, Anh a vo chng trnh mn Tin hc
dy cho HS ngay t lp 1.
MC CH - MISSION
We support approaches to coding that engage
young people in thinking creatively, reasoning
systematically, and working collaboratively --
essential skills for everyone in today's society.
Chng ti h tr mt cng c lp trnh mi gip
tr suy ngh hp l hn, h thng hn, sng to
hn, lm vic nhm v rn luyn cc k nng
cn thit trong x hi hm nay.
Mt vi s liu

S lng d n Scratch c chia s l hn


20 triu v ang tng chng mt vi cp s
nhn.
S lng ngi ng k chia s trc tuyn l
hn 15 triu (cha tnh nhng ngi ang
s dng Offline v cha ng k).
Biu d n
Slng d n c chia s theo tng
thng
Biu d n
Slng d n c chia s theo tng
thng
Ai s dng nhiu nht
Ngi s dng nhiu nht l hc sinh, c
bit t 7 n 18 tui. Nhiu nht tui 12.
Nc no s dng?
Biu s lng ngi ng k s dng
theo quc gia.
S lng d n?
S m t s lng d n c chia s.
Dy t duy lp trnh
bng Scratch?
Mc ch
HS lm quen v hiu, thao tc c trn mi
trng lp trnh ko th Scratch.
Thng qua Scratch, HS bit c th no l thit
k phn mm, ng dng my tnh nhm phc v
mc ch ca con ngi.
HS bc u hiu v thc hin c cc chng
trnh n gin theo yu cu ca ngi khc.
HS bc u hiu c nhng yu t c bn nht
ca t duy my tnh, hiu v thc hin c theo
cch my tnh c th lm g gii quyt cc vn
t ra.
Yu cu nng lc & k nng
Nng lc gii quyt vn : bit cch phn tch 1 vn
v chia nh thnh cc lnh thc hin tun t.
Nng lc v thut ton: hiu v p dng c thut
ton gii quyt vn . Bit c 1 s thut ton
n gin nh duyt, tm gi tr max, min, thay i v tr
2 gi tr.
Nng lc vit chng trnh my tnh: C th vit,
kim tra, pht hin li v tin hnh sa li vi cc
chng trnh n gin. Thng tho cc lnh chn, r
nhnh, lnh lp.
- Tri nghim sng to trong 1 mi trng mi, Bit
v ch ng lm vic trao i nhm vi bn b.
T duy my tnh
Computer thinking
Li ca yu cu nng lc tin hc
i vi HS chnh l T duy my
tnh
T duy my tnh?
Hc sinh cn c trang b T duy my tnh
nng cao v hon thin nng lc Tin hc ca
mnh. Dng T duy my tnh bin cc bi
ton, vn phc tp trn thc t thnh nhng
bi ton m my tnh c th t duy hiu v gii
c.
Cc yu t ca t duy my tnh:
Suy ngh logic, thut ton, gii quyt vn bng t
duy ca my tnh.
T duy tru tng ha thng qua m hnh ha, phn r
bi ton v tng hp kt qu.
Bit cch tng qut ha vn thng qua cc mu.
Kh nng nh gi, iu chnh.
Scratch c th c hc
v dy nh th no?
Hc v dy Scratch
Scratch s c a vo chng trnh chnh
thc mn Tin hc, cho HS tiu hc v THCS, c
l t lp 3 n lp 8.
Scratch s c khuyn khch a vo cc
chng trnh dy lp trnh cho tr t lp 1.
Scratch s c a vo nhiu chng trnh Tin
hc i cng ca cc trng H, chuyn
ngnh k thut khng l CNTT.
Scratch s c a vo tt c cc trung tm
dy ngh Tin hc, bn cnh cc mi trng
khc.
Scratch dnh cho ai v lm g?
Scratch s c a vo cc chng trnh thi
tay ngh, thi hc sinh gii, thi Tin hc tr khng
chuyn v nhiu cuc thi khc.
Scratch rt thch hp:
Trang b cc kin thc c bn ca thut ton, lp
trnh, gii quyt vn , ... cho HS nh tui.
Mi trng sng to, hc thut dnh cho HS v c
GV.
Thit lp nhanh cc ng dng, tr chi, phn mm
gio dc ng dng ngay trn thc t.
Gio vin cc mn hc cng nn bit thit k
cc ng dng h tr hc tp v ging dy.
Sch:T hc lp trnh
Scratch.
408 trang, 5 chng, 25 bi
hc.
Chng 1: Lm quen vi
Scratch.
Chng 2: Bt u lp
trnh Scratch.
Chng 3: Tm hiu su
hn Scratch.
Chng 4: Scratch nng
cao.
Chng 5: Thit k tr
chi v phn mm.
Gii thiu giao din
Scratch
Cc khi nim c bn.
M t giao din mn hnh.
Nhn vt (Sprite) v Cu lnh
(Script)
Thc n v thanh h thng Nt tr gip
nhanh Nt tr gip

Sn khu chnh

Ca s lnh

Nhn vt

Khu vc to nhn
vt v hnh nn Khung
iu khin
Thc n v thanh h thng Tn ngi truy cp

Sn khu chnh

Ca s lnh

Nhn vt

Khu vc to nhn Khung


vt v hnh nn iu khin Backpack
Cc khi nim c bn

Snkhu
Nhn vt

Khung iu khin
Khung nhn vt

Ca s cu lnh

Thc n h thng
Sn khu

Nhn vt
Khung iu khin

Khung cha cc Khung nhp v


mu lnh. Cc mu Khung chnh sa chnh sa m
cu lnh ny c hnh nh nhn thanh
dng bng cch vt v nn sn
ko th vo ca s khu
lnh.
Khung cc nt lnh (Script)
Nt phn
loi cu
lnh

Cc mu
cu lnh
Phn loi cc cu lnh

Motion Event

Look Control

Sound Sensing

Pen Operator

Data More Blocks


Phn loi cc cu lnh

Chuyn ng S kin

Ngoi hnh iu khin

m thanh Cm bin

Bt v Php ton

D liu Thm khi


Khu vc lm vic vi trang phc
Khu vc lm vic vi m thanh
Khu vc lm vic nhn vt, nn
Thc n v thanh h thng Tn ngi truy cp

Sn khu chnh

Ca s lnh

Nhn vt

Khu vc to nhn Khung


vt v hnh nn iu khin Backpack
Khu vc cu lnh (Script)

Ca s cu
lnh ca nhn
vt ang chn

Mi nhn vt s c 1 ca s cu
lnh ring. Mi dy cu lnh
(Script) bao gm 1 s lnh c
sp xp theo th t.
Chng trnh Scratch
L1 t hp cc hot ng ca cc nhn vt
v sn khu thng qua ca s lnh v quan
h gia cc nhn vt.
Lnh trong Scratch

Tham s ca lnh
Nhm cc lnh, on lnh

Cc lnh ny
c kt ni
cht vi
nhau theo 1
th t xc
nh
Chng trnh hon chnh
1 on chng trnh bt
u bng lnh ny s to
thnh 1 chng trnh hon
chnh trn Scratch
Sn khu
Chng ta
c th lp
trnh
iu khin
2 loi i
tng
chnh trong
Scratch:
Nhn vt v
Sn khu.

Nhn vt
Thuc tnh nhn vt
Ta (X, Y)
Hng
Kch thc (size)
Trang phc (#, name)
Nhn vt Dung lng

Thuc tnh sn khu


Nn sn khu (#, name)
Cc v d u tin
Bi ton: thit lp 1 nhn vt l 1
bn qu bng, 1 bn nam hoc
n, v cho nhn vt ny chuyn
ng theo mun.
to 1 nhn vt mi l 1 hc sinh, cho
V d 1: hc sinh ny chuyn ng 1 vng
xung quanh sn khu
Chnthm 1 Ko th v nhp
nhn vt, a tham s cho cc
v gc tri di cu lnh sau:

Phng n 1

Phng n 2
Tt hn
iu khin con mo chy t bn cnh
V d 2: tri sang cnh phi v ngc li, mi ln
gp cnh th ku meo meo v quay
chy v pha ngc li. Lp li vi ln.
acon mo v Ko th v nhp
cnh tri tham s cho cc
cu lnh sau:
Thay i ngoi hnh,
ging ni nhn vt,
thay i sn khu
Trang phc, nn sn khu, m thanh

Mi nhn vt c th c 1 dy cc trang phc v m


thanh km theo
Sn khu cng c th c 1 dy hnh nh nn v m
thanh km theo
Cc lnh vi trang phc, nn
sn khu
Cc lnh vi m thanh
Thng tin nhn vt
1. Thuc tnh ring ca
nhn vt
2. Trang phc
3. m thanh
4. Ton b bin nh ring

5. Ca s lp trnh

C th lu
li v m
ra s dng
Ca s iu chnh ha ca
nhn vt v nn sn khu
C 2 ch iu chnh ha:
Ch ha vector
Ch ha Bitmap
Ch Vector

Ch Bitmap
Cc lnh chung

Cng
c v

Chn ch
Chn nt bitmap / vector
Chn mu v
bt v
Cng c
v cho
ch
Bitmap

Cng c
v cho
ch
Vector
To thm cc hnh nn tng ng
V d 1: vi cc phong cnh thin nhin, khi
nhy phm tng ng th hnh nh
xut hin.
Tothm 3 sn To Script
khu na: tng ng nh
sau:

Cho nhn vt
chnh n i trn
mn hnh
To thm 3 nt lnh tng ng vi 3
V d 2: hnh nn. Khi click ln nt th hnh
nh tng ng xut hin.

Tothm 3 To 3 Script tng ng


nhn vt l nt vi mi nt lnh, v d
lnh nh sau:
Cc cu trc lnh iu
khin
Chng trnh s tm dng trong <1> giy.
Nhm lnh trong khung s thc hin lp <10> ln.
Nhm lnh trong khung s thc hin lp v hn ln.
Lnh iu khin c iu kin If. Nu iu kin trong
biu thc lnh l ng th nhm lnh trong khung s
c thc hin.
Lnh iu khin r nhnh If-then-else. Nu iu kin
trong biu thc lnh l ng th nhm lnh trong
khung trn s c chy, ngc li nu iu kin trong
biu thc lnh l Sai th nhm lnh trong khung di
(else) s c chy.
Lnh "dng cho n khi". Chng trnh s tm dng
cho n khi iu kin trong biu thc c gi tr ng.

Lnh "lp cho n khi". Kim tra iu kin, nu ng


th thc hin nhm lnh, v l li.

Lnh "dng chy". Lnh ny s dng chy theo cc


kh nng la chn t bn phi. C th chn "all" -
dng tt c cc chng trnh; "this script" - ch dng
chng trnh hin ti; "other scripts in sprite" - dng
tt c cc chng trnh khc ca nhn vt hin thi.
Lnh wait ...
Lnh ny s lm cho
on chng trnh hin
thi tm dng trong 1
khong thi gian tnh
theo giy.
Ch : cc chng trnh
song song khc khng
nh hng.
Lnh lp repeat ...
Gi tr s ln
Chc nng:
cn lp

Nhm lnh lp
Lnh lp v hn

Chc nng: thc hin


lp v hn ln nhm lnh
nm trong phm vi ca
lnh ny.
Nhm lnh lp Ch : lnh ny ch dng
khi c 1 lnh gi bn
trong nhm lnh trn.
Lnh if ... then...
Biu thc
logic trong Chc nng: kim tra iu
lnh Nhm lnh kin ca lnh.
Nu ng: thc hin
nhm lnh.
Nu sai: b qua lnh
ny, thc hin lnh tip
theo (nu c).
Lnh if ... then...else
Biu thc
logic trong
lnh Nhm lnh 1
Chc nng: kim tra
iu kin ca lnh.
Nu ng: thc
hin nhm lnh 1.
Nu sai: thc hin
nhm lnh 2.
Nhm lnh 2
Lnh wait until

Chc nng: tm dng


on chng trnh hin
thi cho n khi gi tr
biu thc logic c trong
lnh c gi tr ng.
Ch : lnh ny khng
Biu thc logic
trong lnh c tc dng ln cc
chng trnh hoc on
chng trnh song song
khc.
Lnh repeat until
Lp c iu kin
Chc nng: thc
Biu thc logic
trong lnh hin lin tc, lp li
nhm lnh bn
trong vng lp cho
n khi gi tr biu
thc c gi tr ng
(th dng).
Nhm lnh s Ch : kim tra iu
c lp
kin trc, thc
hin sau.
Lnh stop
Lnh dng chng trnh,
c 3 phng n:
all: dng ton b
chng trnh Scratch.
this script: ch dng
on chng trnh cha
lnh ny.
other script in sprite:
dng tt c cc on
chng trnh khc ca
nhn vt ny / sn khu
ny.
Cc chng trnh song song
Cc ca s lnh ca nhn vt, sn khu
chy song song.
Trn 1 ca s lnh, cc nhm lnh xp nhm
sau cc lnh s kin When s chy song
song.
Cc ch chnh
Cc ch chnh ca lp trnh
Scratch.
Cc ch chnh ca Scratch
Lm quen vi sn Cm bin
khu, nhn vt. Thay X l s
i nn sn khu v X l xu
trang phc Bin nh danh sch
Chuyn ng
(List)
V ha
Th tc
m thanh
Clone
Bin nh
Thit k tr chi
Hi thoi
Hi thoi v truyn
thng
Chuyn ng
Ta , kch thc sn khu
Y
180
x: -240, y: 180 x: 240, y: 180

-240 240 X
x: 0, y: 0

x: -240, y: -180 x: 240, y: -180


-180

Kch thc sn khu: 480 x 360


Hng sn khu v nhn vt
to 1 nhn vt mi l con cnh cam,
V d 1: cho con cnh cam chuyn ng
xung quanh sn khu
Chnthm 1 Ko th v cc cu
nhn vt, a lnh sau cho nhn vt
v gc tri di ny.
to 1 nhn vt mi l 1 hc sinh, cho
V d 2: hc sinh ny chuyn ng 1 vng
xung quanh sn khu
Chnthm 1 Ko th v nhp
nhn vt, a tham s cho cc
v gc tri di cu lnh sau:

Phng n 1

Phng n 2
Tt hn
iu khin con mo chy t bn cnh
V d 3: tri sang cnh phi v ngc li, mi ln
gp cnh th ku meo meo v quay
chy v pha ngc li. Lp li vi ln.
acon mo v Ko th v nhp
cnh tri tham s cho cc
cu lnh sau:
Cc lnh lin quan n ta
X, Y
Goto XY
Glice for ... secs to XY

Goto .... (nhn vt, con tr chut)

Set X to, Set Y to

Change X by, Change Y by


x position

y position
Cc lnh lin quan n hng
nhn vt
Move ... steps
Point in direction

Point toward

Turn tri / phi 1 gc

If on edge, bounce
Set rotation ... (thit lp ch xoay).
Cc lnh chuyn ng n gin
Di chuyn bc
Nhy ti v tr x: y:

Dch chuyn trong giy


n v tr x: y:
Xoay (ngc/xui)

Thay i x

Thay i y

t x l

t y l
Cc lnh chuyn ng phc tp
Xoay v hng ()
Xoay v pha (i tng)

Nhy n (i tng)

Nu chm bin, quay li


t kiu quay cho php (4
hng / tri phi / khng
quay).
Chuyn ng c iu kin
Chuyn ng theo hiu lnh (Key pressed).
Chuyn ng v hn

Chuyn ng khi gp s kin khc


V ha
Mt s nguyn tc cho v hnh
Khi nhn vt chuyn ng, nu ch t bt l
Pen down th bt s v qu o chuyn ng ca
nhn vt trn mn hnh theo thuc tnh ca bt
(pen).
Thuc tnh ca bt bao gm:
Mu sc (Color).
Kch thc nt bt (Size).
Kiu t mu (Shape).
Lnh Stamp s v ln mn hnh 1 hnh nh nhn
vt ti v tr hin thi.
Lnh Clear s xa ton b cc nt v v Stamp trn
mn hnh.
Cc lnh lin quan n ha
H bt
Nng bt
t stamp.
Thay i mu bt theo ---

Thit lp mu bt theo ---


Thay i kiu t mu ---

Thit lp kiu t mu ---


Thay i nt bt theo ---
Thit lp nt bt theo ---
Hy tt c cc hiu ng ha
V d 1:
Cho nhn vt chuyn ng v li vt ca mnh
V hnh vung
V tam gic u
V d 2: V a gic u (tng qut)
Thit lp 1 nhn vt mi v thc hin theo s
sau:
V d 3: V vng trn
Thit lp 1 nhn vt mi v thc hin theo s
sau:
V d 4: V tri t chuyn ng
To ra 3 i tng sau:
Hi thoi
Mt s lnh hi thoi
Ni --- trong giy.
Ni ---- (khng tg)

Ngh --- trong --- giy

Ngh --- (khng tg)

Pht m thanh ---


Pht m thanh --- cho
n khi xong
V d 1: Cu lnh cho hi
V d 2: Hi thoi n gin
m thanh.
Nhc v trng
Nhp trng v lnh g trng
Nhptrng (beat) l 1 n v thi gian tnh
bng 1 nhp trng c bn. Nhp trng (beat)
ng vai tr c bn trong cc lnh lin quan
n trng v nhc.

S lng nhp trng


trong 1 giy (beat per
minute)
Lnh g trng
Lnh play drum s

Chn b g trng
ti y.

Chn nhp
trng ti y.
Cc loi trng
Chi, nh nhc
Nhp trng (beat) s dung lm c s cho nhp
/ phch ca bn nhc.
1 beat = 1 nt en
Cao nt nhc

Trng nt
nhc
Cao nt nhc
Trng nt nhc

Khong lng Trng ngh


Cc loi nhc c chi nhc
V d:
Bin nh v d liu
Bin nh
Bin nh l 1 vng trong b nh
dung lu tr d liu, h tr
qu trnh iu khin chng
trnh.
Mi bin nh c 1 tn ring.
Mt s bin nh h thng
Lnh lm vic vi bin nh
Phn loi bin nh
Bin nh c 2 loi:
bin n, bin List
(mng, danh sch).
Nhn vt c php khi Bin n (variable)
to c 2 loi bin nh.
ch c 1 gi tr.
Bin List c nhiu gi
tr: 1 dy cc gi tr.
Cn c gi l danh
sch, mng.
Sn khu c php khi
to c 2 loi bin nh.
Bin nh chung v ring (bin n)
Bin nh chung (for
all, global) c khi
to dung chung
Mi nhn vt c khi to c cho tt c nhn vt v
bin nh chung v bin nh ring.
sn khu.
Bin nh ring ch
dnh cho nhn vt.
Cc nhn vt khc
hoc sn khu s khai
Sn khu ch c khi to thc bin ring thng
bin nh chung, khng c
php to bin nh ring.
qua thuc tnh ca
nhn vt.
Khai thc bin nh chung v ring
Bin nh chung

Bin nh ring
Cc tnh cht ca bin nh
Nhn vt v sn khu u c th to c bin
nh.
Bin nh c chia lm 2 loi: bin nh chung,
tng th v bin nh ring (Global & Local)
Bin nh chung: Tt c u c quyn s dng, khai
thc, thay i, xa.
Bin nh ring (ch c nhn vt c php to bin
nh ring). Cc nhn vt khc ch c php khai
thc, khng c php thay i. Nhn vt khc s khai
thc bin nh ring thng qua hm thuc tnh ca
nhn vt.
Bin nh trong Scratch

Nhn vt
Sn khu

Bin nh Bin nh Bin nh Bin nh


chung ring chung ring
Bin nh n Bin nh List
Bin nh chung
Tt c cc bin nh chung
phi c tn khc nhau.
Nhn vt Tt c mi nhn vt, sn
khu u c th thc hin
cc thao tc sau trn bin
nh chung:
Khai thc, ly d liu.
Sn khu
Thay i, cp nht d liu.
Cho php n, hin trn sn
khu ti bt c v tr no.
Bin nh ring
Ch nhn vt mi to c
bin nh ring.
Bin nh ring ca 2 nhn

Nhn vt vt c th trng tn.


Ch ca bin nh c php
thc hin mi thao tc nh
n, hin, thay i gi tr.
Nhn vt, sn khu khng
phi l ch th ch c th khai
Sn khu
thc bin nh ring thng qua
hm thuc tnh ca nhn vt.
Mt s lnh vi bin nh
Gn 1 gi tr cho bin nh.
Thay i gi tr bin nh

Hin gi tr bin nh

n gi tr bin nh

itn bin nh.


Xa bin nh
Mt s lnh vi bin List

B sung gi tr vo danh sch


Xa 1 phn t ca DS
Chn gi tr vo 1 v tr trong
DS
Thay gi tr 1 phn t trong
DS bng gi tr khc.
Hin thng tin 1 phn t ca
DS.
Hm kim tra 1 DS c cha 1
Lnh xa bin
nh List
gi tr cho trc hay khng?
Gi tr ca bin nh
Mi bin nh c th lu tr ng thi 3
kiu d liu: s, xu v logic
S
12, 34, 1.5

Xu k t
H Ni

Logic
true / false
Khai thc, s dng bin nh
trong cc lnh

Gi tr bin nh c th
a vo bt c vng d
liu no, bao gm cc
loi khung trn, vung,
hnh trm
Cc php ton trn kiu d liu
Php ton vi d liu s
Php cng 2 s
Php tr 2 s hm ly s ngu nhin
Php nhn 2 s
Php chia 2 s,
kt qu thp cc hm s c th trong
phn Scratch

S d ca php chia
2 s nguyn
Lm trn s nguyn
gn nht.
Cc php ton trn kiu d liu
Php ton vi d liu s

Lm trn ln s nguyn gn nht.

Lm trn xung s nguyn gn


nht.
Cc php ton trn kiu d liu
Php ton vi d liu xu k t

Ni 2 xu

hm ly di xu k t

hm ly 1 k t ca xu
Cc php ton trn kiu d liu
Php ton vi d liu logic

Biu thc logic < Php ton v logic


Php ton hoc
Biu thc logic > logic
Php ton ph nh
Biu thc logic = logic
Gio vin yu cu HS nhp 2 s, sau
V d 1: tnh tng v hin trn mn hnh

To 3 bin nh To Script tng t sau:


n1, n2, gdc
Gio vin yu cu HS nhp 2 s, sau
V d 2: tnh SCLN hai s trn v hin
trn mn hnh
To 3 bin nh To Script tng t nh
n1, n2, gdc bi trc, on lnh tnh
SCLN nh sau:
Mt s thut ton c bn vi
xu v list
Ly ra 1 xu con (dy con) bt u t v tr k,
c di d, t 1 xu hoc dy cho trc.
Hon v ngu nhin 1 xu hoc 1 dy.

Sinh ngu nhin 1 xu con, dy con vi


di cho trc.
Chn 1 xu A vo 1 v tr ca xu B.

Chn 1 dy A vo 1 v tr ca dy B.

Sinh ngu nhin k phn t ly t 1 dy (list)


hoc xu cho trc.
Cm bin
Mt s lnh cm bin
tip xc vi ---?
tip xc vi mu sc --?

Mu tip xc vi --?

Hi --- v i tr li
Khong cch n ---

Phm nhn cha?

nhy chut cha?

V tr x ca chut

V tr y ca chut
Gi tr thi gian hin thi

Reset thi gian


Phn loi cm bin
Hithoi ngi my tnh
Cm bin mu sc

Cm bin va chm

Cm bin khong cch

Cm bin bn phm v chut


Cm bin thi gian

Cm bin m thanh

Cm bin nhn vt
V d 1: chuyn ng c iu
kin cm bin V trn sn khu 1
vch . Cho mo
chuyn ng v t
nhn bit dng khi
gp vch .

Lnh cm bin
mu sc
V d 2: cm bin tip xc
2 nhn vt Ch v mo chuyn
ng ngu nhin trn sn khu
nhng trnh va vo nhau. Vit 2
script ring cho ch v mo.
V d 3: cm bin bn phm
Sdng cc phm iu khin
chuyn ng ca mo v chut
Truyn thng
ngha ca truyn thng
Truyn thng l 1 trong nhng c tnh hay
nht v quan trng nht ca Scratch.
Trong Scratch cc nhn vt, sn khu u
hot ng song song. Do vy truyn thng
gia cc hot ng ca nhn vt ng vai tr
rt quan trng.
Thng qua khi nim thng ip (message),
gi v nhn thng ip s gip cc nhn vt
v sn khu trong chng trnh c th truyn
tin cho nhau tc thi, bo m tnh logic cht
ch ca cc hot ng trong chng trnh.
M hnh truyn thng
Gi thng ip Nhn thng ip, x l
Gi thng ip

Gi thng ip v
khng cn ch
phn hi.
Thng ip c
pht i tc thi
Gi thng ip v
ch thc hin

Gi thng ip v
ch cho n khi c
phn hi, tc l
cho n khi c 1
lnh

c thc hin.
Thng ip c
pht i tc thi.
So snh thng ip v s dng
bin nh chung
Thng ip Bin nh
Truyn thng tin gia cc Truyn thng tin gia cc
nhn vt v sn khu. nhn vt v sn khu.
Tc : tc thi. Tc : khng tc thi,
Thng ip khng c c th tr do vic gn gi
ngha gi tr. tr ca bin nh v lnh.
Truyn nhiu thng tin c
ch.
Mt s lnh iu khin giao tip
Thng bo -----
Thng bo ----- v i
S kin: khi ti nhn
c thng bo ----
V d 1: cho hi
To 2 nhn vt: Cat v Nam
To cc Script ring bit cho 2 nhn vt ny.
To 2 m thanh: Cho bn v Ti l Nam
ring bit cho mi nhn vt.
V d 2: cho hi
To 3 nhn vt: Lan, Bnh, Vit
To cc Script ring bit cho 3 nhn vt ny.
Lan ln lt ni chuyn ring bit vi Bnh v
Vit.
X l s
Cc php ton vi s
Php cng 2 s
Php tr 2 s
Php nhn 2 s

Php chia 2 s
Tnh s d
Lm trn s

Tnh vi hm c th
Hm ly s ngu nhin
Cc hm ton hc trn s
Php ton vi d liu s

Lm trn ln s nguyn gn nht.

Lm trn xung s nguyn gn


nht.
Cc php ton logic

Php so snh <


Php so snh =

Php so snh >

Php ton v: AND

Php ton hoc: OR


Php ph nh NOT
Gio vin yu cu HS nhp 2 s, sau
V d 1: tnh tng v hin trn mn hnh

To 3 bin nh To Script tng t sau:


n1, n2, gdc
Gio vin yu cu HS nhp 2 s, sau
V d 2: tnh SCLN hai s trn v hin
trn mn hnh
To 3 bin nh To Script tng t nh
n1, n2, gdc bi trc, on lnh tnh
SCLN nh sau:
X l k t
Cc php ton vi ch v xu

Kt ni 2 xu

Ly k t th (1) trong xu

di xu k t
Cc php ton logic ny p dng
c cho c xu k t
Php so snh <
Php so snh =

Php so snh >

Php ton v: AND

Php ton hoc: OR


Php ph nh NOT
V d 1: Thit lp 1 bi hc tm t, so snh 2
t (xu k t)
Thitlp nhn vt l GV iu
khin lp hc. Thc hin bi sau.
List: Mng, dy gi tr
Khi nim Dy (List)
Dy (mng,
list) l 1 danh
sch cc gi
tr (s hoc
ch).
Mi dy l 1
i tng
ca nhn vt.
Nhn vt,
sn khu u
c th to
List.
Nhp d liu vo bin List
Nhp trc
tip trn mn
hnh.
Nhp bng
lnh import
thng qua
tp *.txt.
Nhp bng
lnh, chng
trnh
Cc lnh vi Dy (List)
B sung gi tr vo dy
Xa 1 phn t -- ca dy
Chn 1 gi tr vo dy

Thay th 1 phn t ca
dy
Hin th dy
Khng hin th dy

Dy c cha gi tr --?
Gi tr phn t ca dy

di ca dy
Ni dung dy
Mt vi lnh c bit
Th hin d liu
danh sch.

Xa ton b 1
danh sch

Xa phn t cui
ca danh sch.
Mt s lnh vi bin List
B sung gi tr vo danh sch
Xa 1 phn t ca DS
Chn gi tr vo 1 v tr trong
DS
Thay gi tr 1 phn t trong
DS bng gi tr khc.
Hin thng tin 1 phn t ca
DS.
Hm kim tra 1 DS c cha 1
gi tr cho trc hay khng?
Lnh xa bin
nh List
V d 1:
Cho trc 1 dy s, hy vit chng trnh
hin th s Max trong cc s ca dy.
V d 2:
c t bn phm vo 1 dy 5 s, sau hin
th s Max trong cc s ca dy.
V d 3:
To1 dy s, sinh ngu nhin cc phn t,
sau hin th s Max trong cc s ca dy.
Th tc trong Scratch
Procedure
Th tc l g?
Th tc l 1 nhm cc lnh kt ni li vi
nhau to ra 1 lnh mi.
Th tc c to ring cho tng nhn vt,
sn khu v khng dung chung c.
Th tc c 2 loi: c tham s v khng c
tham s ring.
Th tc khng c tham s s to ra 1 lnh mi
khng c tham s.
Th tc c tham s s to ra cc lnh c tham s
u vo nh nhiu lnh khc trong Scratch.
Lnh khi to th tc ring

Lnh: New Block


Mi th tc l 1
nhm lnh
Cho php xc nh
nhiu tham s u
vo cho th tc. Cc
tham s ny c th
l: s, k t hoc
logic (ng/sai).
ngha ca th tc
Th tc to ra cc lnh mi, lm cho h
thng lnh ca Sratch thm phong ph.
Mt on chng trnh thay bng 1 lnh c
th dung li nhiu ln, tit kim khng gian
v cu lnh.
To ra cc mdule con, lm cho chng trnh
chnh tr nn sng sa, r rng hn.
a bi ton ln thnh cc bi ton con v
gii quyt tng phn c lp. y chnh l 1
trong nhng t duy c bn ca ngi lp
trnh.
Th tc khng tham
s
nh ngha
th tc
khng tham
s
Tn th tc xut hin
nh 1 lnh trong nhm
More Blocks
V d 1: th tc tm Max trong dy

To trc:
- Mng Day_so
- Cc bin nh:
Max, Stt
nh ngha th
tc Tm Max nh
hnh bn.
Th tc c tham s
Th tc c tham s
nh ngha th tc (c
hoc khng c tham s)

Ni dung th c
vit ngay pha di

Li gi th tc trong
Script (c tham s)
V d 2:
Th tc v 1 a gic u

Ch tham s trong
th tc c mu xanh
phn bit vi bin
nh mu nu
V d 3:
Th tc v 1 hnh trn bit tm v bn knh
Ch quan trng
Nhn vt trong Scratch c th lu li trong
cc tp dng *.sprites2, trong tp ny s lu
tr cc thng tin:
Ton b cc trang phc
Ton b cc m thanh
Ton b cc bin nh, danh sch (chung v
ring)
Ton b cc th tc.
Clone
Khi nim Clone
Mt nhn vt GC c
th t phn thn thnh
nhiu bn sao (clone)
ca chnh mnh.
Clone 2 Cc clone khi khi to
ra c iu khin
bng 1 chng trnh
ring.
Clone ch tn ti trong
Clone 1
Clone 3 thi gian chng trnh
ang chy.
Thuc tnh ca nhn vt + Clone
Clone khi khi to s
k tha tt c cc
thuc tnh ca nhn
vt gc.
Clone 2
Cc thuc tnh mc
nh:

l one1 Clone 3
C

Bin ring l thuc


tnh ca nhn vt.
y l lnh khi to 1 bn sao (Clone)
ca nhn vt. Nhn vt khc hoc sn
khu cng c th to c Clone cho
bt k nhn vt no.

y l bt u ca chng trnh iu
khin Clone khi c khi to.

Lnh xa Clone hin thi. Lnh ny nm


trong nhm lnh iu khin Clone.
Ch quan trng (1)
Ti thi im Clone c khi to, Clone
ny s k tha tt c cc thuc tnh ca nhn
vt gc.
Cc thuc tnh ca nhn vt gc bao gm

y l nhm cc
thuc tnh gc ca
nhn vt

y l nhm cc
bin nh ring
Ch quan trng (2)

Clonesau khi c khi to s chu s


iu khin ca tt c cc lnh Scratch
nh mi nhn vt khc.
V d Khi
click Space s to thm ra cc
my bay trn bu tri.
V d 2 Bn tn la tiu dit con rng

Script ca
Dragon
Script ca
Tn la
Mt s dng bi ng
dng khc
Trnh din / sch in t
Hi thoi / Talk Show
Bi ging elearning
V d: Trnh din / xem tranh
Xydng cc dy cc hnh nn l ni dung
cc bi hc chnh. Trnh din cho HS xem.
Thit k tr chi
Cc nguyn tc thit k tr chi,
phn mm
Bi tp ln:
Thit k tr chi 1 ngi
Thit k tr chi Ngi - My
Ngi thit k tr chi cn
lm g?
L 1 tc gi kch bn v o din chng
trnh theo ng ngha.
Vit kch bn theo yu cu; thit k nhn vt,
trang phc, sn khu, m thanh v chun b mi
cng vic bp nc ca o din.
Lngi thit k h thng chng trnh
phn mm.
Thit k h thng quan h, cc s kin, d liu,
thng ip, hm v bin nh h thng.
ng thi l ngi coding chi tit chng
trnh.
Cc bc thit k phn mm
Bc 1: Xc nh bi ton, mc ch, i
tng, vit kch bn chi tit.
Bc 2: Thit k h thng chung.

Bc 3: Xc nh cng c, k thut, cng


ngh s dung trong chng trnh.
Bc 4: thit k chi tit.
Phn r bi ton. V s thit k phn mm.
Tru tng ha, thit k m un, hm, th tc.
Coding chi tit.
Tng hp, debug, sa li v hon thin.
V d: phn mm t ng sinh
bi kim tra trc nghim: y
l con g?
D liu ban u
Dy cc hnh nh con vt (picture)
Dy tn cc con vt tng ng vi hnh nh
ny (text)
Dy thng tin m t ngn v cc con vt ny
(text).
Yu cu phn mm
Phn mm s t ng sinh cu hi trc
nghim dng: y l con g?
Cu hi phi c sinh mt cch ngu nhin,
c ni dung v p n, sao cho khng c 2
cu hi no trng nhau.
Ngi dung thc hin cu hi bng cch
nhy chut ln cc nt tng ng.
Cc cu hi c sinh t ng cho n khi
ngi dng nhy nt Kt thc ca Scratch.
Tng kt
Phn loi lnh trong Scratch
Chia s cng ng s dng
Scratch
Phn loi lnh trong Scratch
S kin

Lnh bnh thng

Gi tr logic (ng/sai)

Gitr s hoc ch
(khng logic).
Chia s cng ng Scratch
Trang home chnh ca Scratch:
https://scratch.mit.edu/
Cng ng Scratch
Trang wiki ca Scratch:
http://wiki.scratch.mit.edu/wiki/Scratch_Wi
ki_Home
Trn trang Scratch c th:
Thc hin lp trnh Scratch Online to ra
cc bi hc, animation theo mun. Lu tr
cc kt qu vo kho ring ca mnh trn
Scratch.
Chia s kt qu cho cng ng cng xem v
gp kin.
Xem v gp , bnh lun cc kt qu m
cng ng a ln.
Xem cc thng tin khc c lin quan.
Kt lun & kin ngh
Scratch l mi trng l tng dy cc kin
thc v t duy my tnh, thut ton v lp trnh
vo nh trng, c bit l HS cp 2, thm ch
c th a xung tiu hc.
Scratch l mi trng rt hp dn cho rn luyn
t duy logic, sng to, lm vic nhm, k nng
kin to sn phm CNTT ng dng vo thc t,
c th coi l 1 trong nhng hng pht trin
nng khiu v t cht dnh cho HS t la tui
tiu hc.
Ph lc 1: cc lnh
chnh
Thit k mt bi m phng hon
chnh.
Chia s cng ng s dng
Scratch
Motion cc lnh m t
chuyn ng
Dch chuyn nhn vt 10 bc theo hng hin
thi.

Xoay nhn vt 15 theo chiu kim ng h.

Xoay nhn vt 15 ngc chiu kim ng h.

Quay nhn vt theo hng c xc nh (trong


hnh: 90 ).

Quay nhn vt theo hng ca 1 nhn vt khc.


Chn nhn vt khc ny ti v tr c hnh tam
gic nh.
Di chuyn nhn vt n v tr c ta X, Y
tng ng. Lnh ny tng ng vi vic
thc hin ng thi 2 lnh Set X to v Set Y to.
Chuyn n v tr ca con tr chut hoc nhn vt khc
c xc nh bi chn t bng chn.
Di chuyn n v tr (X, Y) trong khong thi gian nht
nh tnh bng giy. Thi gian c th nhp l s thp
phn, v d 1.5 l 1 giy ri.
Thay i ta X ca nhn vt theo gi tr cho trong
lnh. Gi tr c th l s dng hoc s m.

Thit lp gi tr c th ta X ca nhn vt.


Thay i ta Y ca nhn vt theo gi tr cho trong
lnh. Gi tr c th l s dng hoc s m.

Thit lp gi tr c th ta Y ca nhn vt.


Nu gp cnh mn hnh, quay li.
y l lnh rt quan trng. Lnh s iu khin nhn vt
khi di chuyn gp cnh ca mn hnh th nhn vt s
"bt" tr li theo nguyn tc i xng gng.
Thit lp kiu quay ca nhn vt (v d khi gp cnh
mn hnh). C 3 kiu quay: tri - phi (right-left),
khng quay (do not rotate), quay trn (all around).
Looks cc lnh giao tip v
thay i th hin
Th hin dng ch "Hello" trong 1 khong thi gian
<2> tnh bng giy. Trong thi gian chng trnh s
tm dng.
Th hin dng ch "Hello" trong khi chng trnh vn
chy bnh thng.
Th hin dng ch suy ngh "Hmm" trong 1 khong
thi gian <2> tnh bng giy. Trong thi gian chng
trnh s tm dng.
Th hin dng ch suy ngh "Hmm" trong khi
chng trnh vn chy bnh thng.
Hin nhn vt.

n nhn vt.

Thay i kiu trang phc ca nhn vt sang dng c


hin trong danh sch bn phi.

Thay i kiu trang phc ca nhn vt dang dng tip


theo (trong danh sch).
Thay i sn khu nn sang dng <backdrop1> trong
danh sch chn bn phi.
Thay i hiu ng bn ngoi ca nhn vt theo gi tr
<25> cho trc. Cc hiu ng c chn trong danh
sch, nh color, fisheye,
Thit lp gi tr ca hiu ng bn ngoi ca nhn vt
theo gi tr cho trc. Cc hiu ng c chn trong
danh sch, nh color, fisheye,
Hy tt c hiu ng th hin ca nhn vt, quay tr v
trng thi ban u.
Thay i kch thc ca nhn vt theo gi tr <10> %
cho trc so vi kch thc hin thi. Gi tr c th l
s dng hoc m.
Thit lp kch thc ca nhn vt l <100>% so vi
kch thc gc.
Chuyn nhn vt ln lp trn cng.
Chuyn nhn vt xung <1> lp.
(hm) tr li s th t ca trang phc hin thi ca
nhn vt.
(hm) tr li tn ca nn sn khu hin thi.
(hm) tr li kch thc hin thi ca nhn vt.
Thay i sn khu nn sang dng <backdrop1> trong
danh sch chn bn phi.
Thay i sn khu nn sang dng trong danh sch chn
bn phi v ch thc hin cc lnh ca lnh iu khin
sau When backdrop swiches to.
Chuyn nn sn khu sang kiu tip theo.
Thay i hiu ng bn ngoi ca sn khu theo gi tr
<25> cho trc. Cc hiu ng c chn trong danh
sch, nh color, fisheye,
Thit lp gi tr ca hiu ng bn ngoi ca nn sn
khu theo gi tr cho trc. Cc hiu ng c chn
trong danh sch, nh color, fisheye,
Hy tt c hiu ng th hin ca sn khu, quay tr v
trng thi ban u.
(hm) tr li s th t ca nn sn khu hin thi trong
danh sch.
(hm) tr li tn ca nn sn khu hin thi.
Sound cc lnh iu khin
m thanh
Bt m thanh <meow> theo m thanh trong danh sch bn
phi v khng dng chy chng trnh.
Bt m thanh <meow> theo m thanh trong danh sch bn
phi, chng trnh dng li i kt thc m thanh.
Tt tt c m thanh.
nh trng vi tc <0.25> (1/4) ca nhp trng. La chn
kiu trng trong danh sch c nh s.
Tm ngh nh trng trong thi gian <0.25> (1/4) nhp trng.
Chi nt nhc <60> (nt C) trong danh sch trong thi gian
<0.5> nhp trng.
Chn cng c chi nhc <1> trong danh sch.
Thay i ln m thanh theo t l <-10> phn trm so vi
hin thi. Cho php nhp s dng v m.
Thit lp ln m thanh theo mc <100> phn trm ca loa
h thng (my tnh).
(hm) tr li ln m thanh hin thi ca loa h thng.
Thay i nhp trng, tng ln (hoc gim i) <20> nhp trng
trong mi pht.
Thit lp nhp trng theo <60> nhp p trong 1 pht.

(hm) tr li gi tr nhp trng hin thi l s lng nhp


trng trong 1 pht.
Pen cc lnh iu khin bt
v mu sc
Xa tt c cc hnh ha c v trc bi bt
(pen).
In (hin th) hnh nh nhn vt trn mn hnh (ch :
hnh nh ny khng nm trong sn khu).
t ch h bt bt u v theo vt chuyn ng
ca nhn vt.
t ch nhc bt khng v na.
t mu sc cho bt theo mu mu c chn bi
chut.
Thay i mu ca bt theo gi tr <10> c nhp trc
tip. Cho php gi tr m hoc dng. Gi tr mu c
thit lp theo hiu ng mu sc (color effect).
Thit lp mu cho bt theo gi tr mu.
Thay i m ca bt theo gi tr <10>. m c
o bi cc gi tr t 0 n 100.
Thit lp m ca bt theo gi tr <50>.
m c o bi cc gi tr t 0 n 100.
Thay i kch thc ca bt theo <1> pixel. Gi tr thay
i c th dng hoc m.
Thit lp kch thc bt theo gi tr <1> pixel.
Data cc lnh iu khin bin
nh, d liu
To mt bin nh mi.

(hm) tr li gi tr hin thi ca bin nh.

La chn c hin th hay khng gi tr bin nh trn


mn hnh. Th hin ca bin nh c dng sau:

Gn 1 gi tr c th cho bin nh "a". Gi tr c th l


s hoc ch.
Thay i bin nh "a" theo gi tr s (1) c nhp
trc tip ti pha phi.
Ch : gi tr bt buc phi l s, c th dng hoc
m.
Nu nhp sai th li s c thng bo bi "NaN".

Hin gi tr bin nh "a" trn mn hnh.

n khng hin gi tr bin nh "a" trn mn hnh.


To mt danh sch (mng) gi tr mi.

(hm) tr li gi tr ca bin nh "b" l mt dy s


hoc vn bn.
B sung gi tr <"thing"> vo cui ca mng "b". Gi
tr c th l s hoc ch.
Xa phn t th <1> khi mng "b".

Chn gi tr <"thing"> vo mng "b" ti v tr trc


phn t th <1>. Mng "b" s tng thm 1 phn t.
Gi tr c th l s hoc ch.
Thay th phn t th <1> ca mng "b" bng gi tr
mi <"thing">. Gi tr ny c th l s hoc ch.
(hm) tr li gi tr ca phn t th <1> ca mng "b".
(hm) tr li gi tr l s phn t hin c ca mng "b".
(hm logic) tr li gi tr ng nu mng "b" cha
phn t c gi tr <"thing">.
Th hin mng "b" trn mn hnh.

n khng hin mng "b" trn mn hnh.


Event cc lnh iu khin s
kin
y l lnh "bt u chng trnh". Chng trnh (nhm
lnh) s chy khi nhy ln l c xanh.
Lnh iu khin bn phm. Nhm lnh s chy khi phm tng
ng <Space> c bm.
Lnh iu khin chut. Nhm lnh s chy khi nhy chut ln
nhn vt.
Lnh iu khin theo sn khu. Nhm lnh s chy khi nn
sn khu thay i sang <backdrop1>.
Lnh iu khin ph thuc vo m (loudness), thi gian
(timer) v tc ca chuyn ng (video motion). Khi cc
iu kin trn tha mn th nhm lnh s chy.
Lnh iu khin thng ip. Nhm lnh s c thc hin khi
nhn vt nhn c thng ip <message1>.
Lnh gi thng ip c th <message1>. Lnh "when I receive
the message" c tc dng tr li cho thng ip ny. Cc lnh
khc vn chy bnh thng. Ch : trong lnh ny c chc
nng to 1 thng ip mi.

Lnh gi thng ip c th <message1>. Khi gi thng ip


chng trnh s tm dng v ch cho n khi tt c cc nhn
vt khc thc hin xong cc lnh khi nhn thng ip ny. Sau
chng trnh s quay li thc hin cc lnh tip theo. Ch
: trong lnh ny cng c chc nng to 1 thng ip mi.
Control cc lnh iu khin
Chng trnh s tm dng trong <1> giy.
Nhm lnh trong khung s thc hin lp <10> ln.
Nhm lnh trong khung s thc hin lp v hn ln.
Lnh iu khin c iu kin If. Nu iu kin trong
biu thc lnh l ng th nhm lnh trong khung s
c thc hin.
Lnh iu khin r nhnh If-then-else. Nu iu kin
trong biu thc lnh l ng th nhm lnh trong
khung trn s c chy, ngc li nu iu kin trong
biu thc lnh l Sai th nhm lnh trong khung di
(else) s c chy.
Lnh "dng cho n khi". Chng trnh s tm dng
cho n khi iu kin trong biu thc c gi tr ng.
Lnh "lp cho n khi". Nhm lnh trong khung s
c thc hin lp li cho n khi iu kin trong biu
thc lnh tr li gi tr ng.
Lnh "dng chy". Lnh ny s dng chy theo cc
kh nng la chn t bn phi. C th chn "all" -
dng tt c cc chng trnh; "this script" - ch dng
chng trnh hin ti; "other scripts in sprite" - dng
tt c cc chng trnh tng ng vi nhn vt hin
Lnh "khi ti bt u l mt bn sao". Cc
lnh trong khi ny s c thc hin khi
nhn vt bn sao (phn thn) c to ra.
Lnh thc hin vic to ra 1 bn sao (phn
thn) ca 1 nhn vt. Nhn vt s c to
bn sao (phn thn) c th chn t danh sch.
"itself" l to phn thn cho chnh mnh. C
th to phn thn cho nhn vt khc.
Lnh xa i 1 bn sao (phn thn) hin thi.
Sensing cc lnh cm bin
iu kin cm bin va chm. C th chn vt th va
chm t danh sch l cc nhn vt, con tr chut hay
cnh mn hnh. Nu c va chm th hm gi tr s tr
li gi tr ng.
iu kin cm bin va chm mu sc. Mu c chn
bng cch nhy chut ln v tr c mu mun chn.
Hm tr li gi tr ng khi nhn vt va chm vi mu
sc chn.
iu kin cm bin mu sc va chm mu sc. Mu sc
c th chn bng cch nhy chut ln v tr mu. Hm
s tr li gi tr ng khi 2 mu ny va chm nhau.
Hm s tr li khong cch t (tm) nhn vt hin thi
n 1 nhn vt khc, hoc n v tr con tr chut.
Lnh "hi v ch". Nhn vt s th hin cu hi
<What's your name> v ch nhp d liu t bn phm.
Gi tr c nhp t bn phm (s hoc ch) sau khi
bm Enter s c lu trong bin nh "answer".
Hnh nh th hin khi thc hin lnh ny.
Bin nh "Answer" dng lu gi tr nhp d liu t
bn phm ca lnh trn.
Cm bin bn phm. Hm ny s tr li gi tr ng
nu phm tng ng <Space> c bm.
Cm bin chut. Hm s tr li gi tr ng nu chut
c nhn (chut tri).
(hm) tr li ta X ca v tr chut hin thi.
(hm) tr li ta Y ca v tr chut hin thi.
(hm) tr li gi tr hin thi ca m thanh loa h
thng.
(hm) tr li gi tr l cc tham s lin quan n video
camera hin thi tng ng vi nhn vt hoc sn
khu.
Cc tham s c th tnh:
- motion: s lng chuyn ng.
- direction: hng chuyn ng
Lnh bt / tt camera ca my tnh.
Camera s dng iu khin hot ng v nhn vt
trn mn hnh.
Lnh thit lp trong sut ca video camera trn mn
hnh. Gi tr c th thit lp t 0% n 100%. Vy
video c trong sut = 100% s khng hin trn mn
hnh.
(hm) tr li gi tr thi gian bng giy tnh t lc
chng trnh bt u chy.
Lnh c tc dng t li tham s "timer" v 0.
(hm) tr li gi tr cc tham s ca nhn vt c chn
ti bn phi lnh.
Cc tham s c th tr li gi tr bao gm:
- x position: ta X
- y position: ta Y
- direction: hng
- costume #: s th t ca trang phc
- costume name: tn ca trang phc
- size: kch thc nhn vt
- volume: ln ca m thanh.
(hm) tr li gi tr thi gian hin thi c tnh theo
tham s chn trong ca lnh:
- year: nm (v d: 2016)
- month: thng (v d: 3, 112)
- date: ngy ca thng (v d: 20, 131)
- day of week: ngy ca tun (v d: 2, 17)
- hour: gi hin thi (v d: 14, 023)
- minute: pht hin thi (v d: 56. 059)
- second: giy hin thi (v d: 59. 059)
(hm) tr li s ngy ca th k 21, tnh t nm 2000.
(hm) tr li tn ti khon ngi dng trn trang
scratch.mit.edu.
Operators Biu thc logic &
ton hc
(hm) php cng 2 s

(hm) php tr 2 s

(hm) php nhn 2 s

(hm) php chia 2 s, kt qu thp phn.

(hm) tr li s ngu nhin gia 2 gi tr s.

Biu thc logic m t quan h gia 2 s. Biu thc tr


li gi tr ng nn s th nht < s th 2.
Biu thc logic m t quan h gia 2 s. Biu thc tr
li gi tr ng nn s th nht > s th 2.
Biu thc logic "and" (v).

Biu thc logic "or" (hoc)

Biu thc logic ph nh "not".


(hm) ton t ni 2 xu k t.

(hm) tr li k t th <1> ca xu k t
<world>

(hm) tr li di ca xu k t <world>

(hm) php ton tnh thng s ca php chia


s nguyn "mod".
(hm) php tnh lm trn s. Tr li phn
nguyn ca 1 s.

(hm) tr li gi tr l kt qu ca cc hm
ton hc ca 1 s. Hm ton hc c chn t
danh sch trn dng lnh.