say
Say something in a speech bubble and the console.
say "Hello!"THE SPARKY LANGUAGE
The same reference you see when you hover over code in Sparky. Search a command, find an example, and try it in the app.
130 entries
Say something in a speech bubble and the console.
say "Hello!"Show a thought bubble.
think "Hmm..."Say it out loud with the computer's voice.
speak "Hello"Ask a question and keep the answer in a variable.
ask "Your name?" into nameWrite text on the stage where the sprite is.
write "Score: {score}" size 24 boldMake a variable, or change what it holds.
set score to 0Add to a variable (use a minus number to take away).
change score by 1Put something at the end of a list (or add to a number).
add "fish" to petsTake something out of a list.
remove "cat" from petsPut something into a list at a spot.
insert "fish" at 1 in petsKeep a value for next time, even after Sparky closes.
save score as "best"Get a saved value back (0 if nothing was saved).
load "best" into bestStart the timer from 0 again.
reset timerDo the lines inside again and again.
repeat 4 times
move 50
turn 90
endKeep going until you press Stop.
forever
turn 5
endOnly do it when something is true.
if score > 5 then
say "Wow!"
endWhat to do when the if wasn't true.
if x > 0 then
say "yes"
else
say "no"
endCount, or go through every item of a list.
for i from 1 to 10
say i
endPause for some seconds, or until something is true.
wait 0.5Jump out of a loop, or end the program.
stop loopCatch a problem without stopping the program.
try
say 1 / 0
oops
say problem
endWhat to do when the try had a problem. `problem` says what it was.
oops
say problemUse the commands taught in another file.
use "shapes.spark"Closes a repeat, forever, if, for, try, when, tell or teach.
endTeach Sparky a new command.
teach square side
repeat 4 times
move side
turn 90
end
endUse a command you taught.
do square 50Give back an answer from a command you taught.
give back n * 2Same as give back.
return n * 2Run some lines when something happens.
when key "space" pressed
say "jump!"
endSend a message to every `when message` block.
broadcast "go"Wait for the next frame (60 a second), or switch costume.
next frameMake a new sprite.
make sprite rocket with costume "rocket"Give commands to one sprite.
tell rocket
move 50
endChange how a sprite looks: a name like cat or rocket, or any emoji.
costume "cat"See-through: 0 is solid, 100 is invisible.
ghost 50Bring a sprite to the front (or the back).
layer frontTurn around at the edge of the stage.
bounce if on edgeSlide smoothly to a spot.
glide to 100 50 in 2 secondsWalk forward (a minus number walks backward).
move 100Walk backward.
back 50Turn right (or left) by degrees.
turn left 90Face a direction: 0 up, 90 right, 180 down, 270 left.
point 90Jump to a spot. 0 0 is the middle.
goto 100 -50Back to the middle, facing up.
homeMake the sprite invisible.
hideMake the sprite visible again.
showMake the sprite bigger or smaller (100 is normal).
size 150Leave a copy of the sprite on the stage.
stampHow fast: 1 slow, 10 instant.
speed 8Draw while moving: pen down, pen up, pen color, pen size, pen style, pen opacity.
pen color "orange"Erase every drawing.
clearPaint the whole stage one color.
background "ink"A picture behind everything: space, ocean, grass, sunset, night, grid.
backdrop "space"A circle around the sprite.
circle 50A rectangle around the sprite.
rectangle 80 by 40A shape with that many sides.
polygon 6 sides 40A star with that many points.
star 5 points 40A filled dot.
dot 10Part of a circle.
arc 90 radius 50Fill the shapes that come next.
fill color "yellow"Stop filling shapes.
no fillPlay a sound, a note 1–14, a song of note names, or a chord. C is middle C; R is a rest.
play note 4 for 0.5Beats per minute, from 20 to 300. Songs use one beat per note unless you give seconds with for.
tempo 120Pick piano, xylophone, guitar, organ or flute.
instrument "guitar"Wait silently for this many beats at your tempo.
rest 1A little beep.
beepSparky for Arduino: turn a pin on or off, or set its power 0–255.
pin 13 onSparky for Arduino: turn a servo motor to an angle.
servo 9 to 90Sparky for Arduino: where the buzzer is plugged in.
buzzer 8How many items (or letters).
length(pets)TEXT IN CAPITALS.
upper("hi")text in small letters.
lower("HI")Text without spaces at the ends.
trim(" hi ")Text with a capital first letter.
capital("sparky")Turn anything into text.
text(42)Turn text into a number.
number("42")Square root.
sqrt(16)A number times itself, again and again.
power(2, 10)Round to a whole number, or to some decimal places.
round(3.14159, 2)Without the minus sign.
abs(-5)Round down.
floor(3.7)Round up.
ceil(3.2)How many 10s multiply to make it.
log(1000)The natural logarithm.
ln(10)Keep a number between two others.
clamp(x, 0, 100)Sine (degrees).
sin(30)Cosine (degrees).
cos(60)Tangent (degrees).
tan(45)The smallest.
min(3, 7, 1)The biggest.
max(scores)All the numbers in a list added up.
sum([1, 2, 3])How far the sprite is from a spot.
distance(0, 0)Which way to point to face a spot.
angle(100, 50)A color from red, green and blue (0–255 each).
rgb(255, 136, 0)Join a list into text.
join(pets, ", ")Split text into a list.
split("a b c")true if it's in the list or text.
contains(pets, "cat")Swap words in text.
replace("I like cats", "cats", "dogs")true if the text begins with it.
begins("hello", "he")true if the text ends with it.
ends("hello", "lo")Where something is in the text (0 if it isn't).
find("banana", "nan")The words of some text, as a list.
words("a big dog")The letters of some text, as a list.
letters("abc")A random item.
pick(pets)Backwards.
reverse("abc")In order.
sort([3, 1, 2])Where an item is in a list (0 if it isn't).
index(pets, "dog")Some of the items, from one spot to another.
slice(pets, 2, 3)A list of numbers.
range(1, 10)The list in a random order.
shuffle(cards)The list without repeats.
unique([1, 1, 2])How many times something is in it.
count(rolls, 6)The field names of a record.
keys(pet)The sprite's x.
xpos()The sprite's y.
ypos()Which way the sprite points.
direction()Seconds since the program started (or reset timer).
say timer3.14159…
say pi * 2The hour now (0–23).
say hourThe minute now.
say minuteThe second now.
say secondToday's date.
say todayToday's day, like Friday.
say weekdayInside oops: what went wrong.
say problemA surprise number between two numbers, or a random color.
random 1 to 6true when the sprite touches another sprite, the edge, or the mouse.
if touching edge thenmouse x, mouse y, mouse down.
goto mouse x mouse ytrue while a key is held down.
if key "left" down thenOne item of a list (item -1 is the last).
item 1 of petsSparky for Arduino: read a pin (A0–A5 give 0–1023).
read pin A0Examples show command syntax. A block opener such as if needs its body and end; an expression needs a command such as say to display its result.