THE SPARKY LANGUAGE

Small words.
Big possibilities.

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

Commands

say

Say something in a speech bubble and the console.

say "Hello!"
Commands

think

Show a thought bubble.

think "Hmm..."
Commands

speak

Say it out loud with the computer's voice.

speak "Hello"
Commands

ask

Ask a question and keep the answer in a variable.

ask "Your name?" into name
Commands

write

Write text on the stage where the sprite is.

write "Score: {score}" size 24 bold
Commands

set

Make a variable, or change what it holds.

set score to 0
Commands

change

Add to a variable (use a minus number to take away).

change score by 1
Commands

add

Put something at the end of a list (or add to a number).

add "fish" to pets
Commands

remove

Take something out of a list.

remove "cat" from pets
Commands

insert

Put something into a list at a spot.

insert "fish" at 1 in pets
Commands

save

Keep a value for next time, even after Sparky closes.

save score as "best"
Commands

load

Get a saved value back (0 if nothing was saved).

load "best" into best
Commands

reset

Start the timer from 0 again.

reset timer
Commands

repeat

Do the lines inside again and again.

repeat 4 times
  move 50
  turn 90
end
Commands

forever

Keep going until you press Stop.

forever
  turn 5
end
Commands

if

Only do it when something is true.

if score > 5 then
  say "Wow!"
end
Commands

else

What to do when the if wasn't true.

if x > 0 then
  say "yes"
else
  say "no"
end
Commands

for

Count, or go through every item of a list.

for i from 1 to 10
  say i
end
Commands

wait

Pause for some seconds, or until something is true.

wait 0.5
Commands

stop

Jump out of a loop, or end the program.

stop loop
Commands

try

Catch a problem without stopping the program.

try
  say 1 / 0
oops
  say problem
end
Commands

oops

What to do when the try had a problem. `problem` says what it was.

oops
  say problem
Commands

use

Use the commands taught in another file.

use "shapes.spark"
Commands

end

Closes a repeat, forever, if, for, try, when, tell or teach.

end
Commands

teach

Teach Sparky a new command.

teach square side
  repeat 4 times
    move side
    turn 90
  end
end
Commands

do

Use a command you taught.

do square 50
Commands

give

Give back an answer from a command you taught.

give back n * 2
Commands

return

Same as give back.

return n * 2
Commands

when

Run some lines when something happens.

when key "space" pressed
  say "jump!"
end
Commands

broadcast

Send a message to every `when message` block.

broadcast "go"
Commands

next

Wait for the next frame (60 a second), or switch costume.

next frame
Commands

make

Make a new sprite.

make sprite rocket with costume "rocket"
Commands

tell

Give commands to one sprite.

tell rocket
  move 50
end
Commands

costume

Change how a sprite looks: a name like cat or rocket, or any emoji.

costume "cat"
Commands

ghost

See-through: 0 is solid, 100 is invisible.

ghost 50
Commands

layer

Bring a sprite to the front (or the back).

layer front
Commands

bounce

Turn around at the edge of the stage.

bounce if on edge
Commands

glide

Slide smoothly to a spot.

glide to 100 50 in 2 seconds
Commands

move

Walk forward (a minus number walks backward).

move 100
Commands

back

Walk backward.

back 50
Commands

turn

Turn right (or left) by degrees.

turn left 90
Commands

point

Face a direction: 0 up, 90 right, 180 down, 270 left.

point 90
Commands

goto

Jump to a spot. 0 0 is the middle.

goto 100 -50
Commands

home

Back to the middle, facing up.

home
Commands

hide

Make the sprite invisible.

hide
Commands

show

Make the sprite visible again.

show
Commands

size

Make the sprite bigger or smaller (100 is normal).

size 150
Commands

stamp

Leave a copy of the sprite on the stage.

stamp
Commands

speed

How fast: 1 slow, 10 instant.

speed 8
Commands

pen

Draw while moving: pen down, pen up, pen color, pen size, pen style, pen opacity.

pen color "orange"
Commands

clear

Erase every drawing.

clear
Commands

background

Paint the whole stage one color.

background "ink"
Commands

backdrop

A picture behind everything: space, ocean, grass, sunset, night, grid.

backdrop "space"
Commands

circle

A circle around the sprite.

circle 50
Commands

rectangle

A rectangle around the sprite.

rectangle 80 by 40
Commands

polygon

A shape with that many sides.

polygon 6 sides 40
Commands

star

A star with that many points.

star 5 points 40
Commands

dot

A filled dot.

dot 10
Commands

arc

Part of a circle.

arc 90 radius 50
Commands

fill

Fill the shapes that come next.

fill color "yellow"
Commands

no

Stop filling shapes.

no fill
Commands

play

Play 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.5
Commands

tempo

Beats per minute, from 20 to 300. Songs use one beat per note unless you give seconds with for.

tempo 120
Commands

instrument

Pick piano, xylophone, guitar, organ or flute.

instrument "guitar"
Commands

rest

Wait silently for this many beats at your tempo.

rest 1
Commands

beep

A little beep.

beep
Commands

pin

Sparky for Arduino: turn a pin on or off, or set its power 0–255.

pin 13 on
Commands

servo

Sparky for Arduino: turn a servo motor to an angle.

servo 9 to 90
Commands

buzzer

Sparky for Arduino: where the buzzer is plugged in.

buzzer 8
Functions

length

How many items (or letters).

length(pets)
Functions

upper

TEXT IN CAPITALS.

upper("hi")
Functions

lower

text in small letters.

lower("HI")
Functions

trim

Text without spaces at the ends.

trim("  hi ")
Functions

capital

Text with a capital first letter.

capital("sparky")
Functions

text

Turn anything into text.

text(42)
Functions

number

Turn text into a number.

number("42")
Functions

sqrt

Square root.

sqrt(16)
Functions

power

A number times itself, again and again.

power(2, 10)
Functions

round

Round to a whole number, or to some decimal places.

round(3.14159, 2)
Functions

abs

Without the minus sign.

abs(-5)
Functions

floor

Round down.

floor(3.7)
Functions

ceil

Round up.

ceil(3.2)
Functions

log

How many 10s multiply to make it.

log(1000)
Functions

ln

The natural logarithm.

ln(10)
Functions

clamp

Keep a number between two others.

clamp(x, 0, 100)
Functions

sin

Sine (degrees).

sin(30)
Functions

cos

Cosine (degrees).

cos(60)
Functions

tan

Tangent (degrees).

tan(45)
Functions

min

The smallest.

min(3, 7, 1)
Functions

max

The biggest.

max(scores)
Functions

sum

All the numbers in a list added up.

sum([1, 2, 3])
Functions

distance

How far the sprite is from a spot.

distance(0, 0)
Functions

angle

Which way to point to face a spot.

angle(100, 50)
Functions

rgb

A color from red, green and blue (0–255 each).

rgb(255, 136, 0)
Functions

join

Join a list into text.

join(pets, ", ")
Functions

split

Split text into a list.

split("a b c")
Functions

contains

true if it's in the list or text.

contains(pets, "cat")
Functions

replace

Swap words in text.

replace("I like cats", "cats", "dogs")
Functions

begins

true if the text begins with it.

begins("hello", "he")
Functions

ends

true if the text ends with it.

ends("hello", "lo")
Functions

find

Where something is in the text (0 if it isn't).

find("banana", "nan")
Functions

words

The words of some text, as a list.

words("a big dog")
Functions

letters

The letters of some text, as a list.

letters("abc")
Functions

pick

A random item.

pick(pets)
Functions

reverse

Backwards.

reverse("abc")
Functions

sort

In order.

sort([3, 1, 2])
Functions

index

Where an item is in a list (0 if it isn't).

index(pets, "dog")
Functions

slice

Some of the items, from one spot to another.

slice(pets, 2, 3)
Functions

range

A list of numbers.

range(1, 10)
Functions

shuffle

The list in a random order.

shuffle(cards)
Functions

unique

The list without repeats.

unique([1, 1, 2])
Functions

count

How many times something is in it.

count(rolls, 6)
Functions

keys

The field names of a record.

keys(pet)
Functions

xpos

The sprite's x.

xpos()
Functions

ypos

The sprite's y.

ypos()
Functions

direction

Which way the sprite points.

direction()
Values

timer

Seconds since the program started (or reset timer).

say timer
Values

pi

3.14159…

say pi * 2
Values

hour

The hour now (0–23).

say hour
Values

minute

The minute now.

say minute
Values

second

The second now.

say second
Values

today

Today's date.

say today
Values

weekday

Today's day, like Friday.

say weekday
Values

problem

Inside oops: what went wrong.

say problem
Values

random

A surprise number between two numbers, or a random color.

random 1 to 6
Values

touching

true when the sprite touches another sprite, the edge, or the mouse.

if touching edge then
Values

mouse

mouse x, mouse y, mouse down.

goto mouse x mouse y
Values

key

true while a key is held down.

if key "left" down then
Values

item

One item of a list (item -1 is the last).

item 1 of pets
Values

read

Sparky for Arduino: read a pin (A0–A5 give 0–1023).

read pin A0

Examples 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.