Как использовать Scratch разметку

Материал из Энциклопедия вычислительного мышлении
Перейти к навигации Перейти к поиску
define insert (text) at (index) of (list) //run without screen refresh
delete (all v) of [handler v] //this is a list used for adding to the other list
set [i v] to (0)
repeat (length of (list)) //makes a copy
change [i v] by (1)
add (item (i) of (list)) to [handler v]
end
delete (all v) of (list)
set [i v] to (0)
repeat (length of [handler v])
if <(i) = (index)> then
add (text) to (list)
end
add (item (i) of [handler v]) to (list)
end

  • Recording positions of individual clones
when I start as a clone
set [id v] to (total clones)
add [] to [clonesX v]
forever
if <key [left arrow v] pressed?> then
change x by (-2.5)
end
if <key [right arrow v] pressed?> then
change x by (2.5)
end
replace item (id) of [clonesX v] with (x position)

Event Blocks[править]

Block Workaround
when green flag clicked
when I receive [Scratch-StartClicked v]
. . .

Note: Only works offline in Scratch 1.x

when [timer v] > (-1) // This is a block that can not be stopped
if <<((mouse y) = [180]) and <mouse down?>> or <(clicked) = [0]>> then
set [clicked v] to [1]
. . .
when [space v] key pressed
when [timer v] > (-1) // This is a block that can not be stopped, therefore you can make a workaround that does not require the green flag to be clicked
forever
wait until <key [space v] pressed?>
. . .
when this sprite clicked
when [timer v] > (-1) // This is a block that can not be stopped, therefore you can make a workaround that does not require the green flag to be clicked
forever
  wait until <<touching [mouse-pointer v]?> and <mouse down?>> //This is not an exact workaround because you could, first, while not touching the Sprite, hold down your mouse, then, still holding down your mouse, move it over to the sprite. This will not activate the true block but will activate this.

  . . .

or

when [timer v] > (-1) // This is a block that can not be stopped, therefore you can make a workaround that does not require the green flag to be clicked
forever
if <<mouse down> and <not<touching [mouse pointer v]>>> then
set [down? v] to [1]
wait until <not<mouse down>>
set [down? v] to [0]
end
end // This makes sure the script will not activate if you are holding down the mouse and then move it onto the sprite.

when [timer v] > (-1) // This is a block that can not be stopped, therefore you can make a workaround that does not require the green flag to be clicked
forever
if <<touching [mouse pointer v]> and <<mouse down> and <(down) = [0]>>> then
. . .
end
when [loudness v] > (10)
when gf clicked // You can not use the greater than block to work around the green flag, because the greater than block is the block you want to work around
forever
  wait until <(loudness) > (10)>
  . . .
broadcast [message v]
when gf clicked
set [broadcasted? v] to [0]
. . .
set [broadcasted? v] to [1]

when gf clicked
forever
wait until <(broadcasted?) = [1]>
. . .
set [broadcasted? v] to [0]
end

or

broadcast [broadcast v] and wait
when I receive [broadcast v]
. . . // whatever comes after the broadcast, in addition to the receive block you would have
broadcast [message v] and wait
when gf clicked
set [broadcasted? v] to [0]
set [wait v] to [0]
. . .
set [broadcasted? v] to [1]
set [wait v] to [1]
wait until <(wait) = [0]>
. . .

when gf clicked
forever
wait until <(broadcasted?) = [1]>
. . .
set [broadcasted? v] to [0]
set [wait v] to [0]
end

or

set [wait v] to [3] // however many receive blocks you have for that particular broadcast
broadcast [broadcast v]
when I receive [broadcast v]
. . .
change [wait v] by (-1) // be sure to but this right before any "stop script" blocks, too!
when backdrop switches to [background v]
when [timer v] > (-1) // This is a block that can not be stopped, therefore you can make a workaround that does not require the green flag to be clicked
if <([backdrop name v] of [Stage v]) = []> then // There goes the backdrop name
. . .
end
when Stage clicked :: events hat
when [timer v] > (-1)  // This is a block that can not be stopped, therefore you can make a workaround that does not require the green flag to be clicked
if <<(mouse x) > [-180]>and<<(mouse x) < [180]> and <<(mouse y) > [-180]> and <<(mouse y) < [180]> and <mouse down?>>>>> then
. . .
wait until <not <mouse down?>>
else
. . .
end