We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Hopscotch (Hopscotch Technologies)

From Esolang
Jump to navigation Jump to search
Hopscotch (Hopscotch Technologies)
Designed by Jocelyn Leavitt, Samantha John
Appeared in 2013
Computational class Turing-complete
Reference implementation [1]
File extension(s) .hopscotch

Hopscotch is a visual programming language developed by Hopscotch Technologies (founded by Samantha John), created to allow children to code games. A game, referred to as a "project", is a collection of "scenes", which are independent instances that each contain a set of objects. Each object has its own set of events that it listens for, each running code.

Objects

Before a scene is played, each object is given a position, rotation, size as a percentage, and a texture. The texture is either a pre-set image or plain text. Excluding the texture, each of these properties can be accessed as an #object variable.

While a scene is playing, each object is able to have clones that are associated with it. An object and its clones are able to be removed ("destroyed") from the scene at any time, with the clones remaining even if the original object is destroyed. Clones are able to create additional clones.

Variables

Variables are grouped into four separate scopes, those being user, game, object, and local variables. With the exception of local variables, any variable can be accessed by all objects in the scene, and each come with a set of read-only variables. All variables are either a number or a string, and can be coerced to either type according to JavaScript coercion rules.

User variables

User variables function like save data that persists between plays of the project. User variables cannot be accessed unless the project was created with a Hopscotch subscription or in the web editor.

Read-only variables
Variable Description ID
📱 Username
The username of the account being used to play the project. 2500
📱 Time
The current Unix timestamp in seconds. 2501
📱 Year
The current year. 2502
📱 Month
The current month. 2503
📱 Day
The current day. 2504
📱 Hour
The current hour. 2505
📱 Minute
The current minute. 2506
📱 Second
The current second. 2507

Game variables

Game variables are accessible to all scenes, persisting until the project is restarted or closed.

Read-only variables
Variable Description ID
▶️ Width
The width of the project in pixels. 3000
▶️ Height
The height of the project in pixels. 3001
▶️ Tilt Up %
How much the device is tilted upwards, as a whole number ranging from -100 to 100. 3002
▶️ Tilt Down %
How much the device is tilted downwards, as a whole number ranging from -100 to 100. 3003
▶️ Tilt Left %
How much the device is tilted leftwards, as a whole number ranging from -100 to 100. 3004
▶️ Tilt Right %
How much the device is tilted rightwards, as a whole number ranging from -100 to 100. 3005
▶️ Last Touch X
The X coordinate that the project was last touched at, in pixels from the left side of the project. 3006
▶️ Last Touch Y
The Y coordinate that the project was last touched at, in pixels from the bottom side of the project. 3007

Object variables

Object variables are properties local to each instance of an object. Every instance is able to access its own object variables, and can see the object variables of other non-clone objects, including its ancestor.

Read-only variables
Variable Description ID
Self
Rotation
The rotation of the object in degrees. 2000
Self
X Position
The X position of the object in pixels from the left side of the project. 2001
Self
Y Position
The Y position of the object in pixels from the bottom side of the project. 2002
Self
Invisibility as a %
The "invisibility" of the object as a whole number ranging from 0 to 100. "Invisibility" is the opposite of opacity. 2003
Self
Size as a %
The scale of the object multiplied by 100 as a whole number. 2004
Self
Speed
The "speed" of the object. 2005
Self
Clone Index
The unique index given to the object. The initial object has an index of zero, while subsequent clones are one above the previous clone. 2006
Self
Total Clones
The total clones an object has, including the initial object. 2007
Self
Width
The width of the object in pixels. 2008
Self
Height
The height of the object in pixels. 2009
Self
Z Index
The z-index of the object. 2010
Self
Origin X
The X position of the bottom left corner of the object in pixels from the left side of the project. 2011
Self
Origin Y
The Y position of the bottom left corner of the object in pixels from the bottom side of the project. 2012
Self
Name
The name of the object. 2018

Local variables

Local variables are only accessible in the block that it was defined in and cannot be accessed by other objects.

Rules

Rules are blocks of code which are ran each frame if a certain condition is met. Rules are processed in sequential order, with objects evaluated from first created to last created.

Rule Description ID
game starts
Runs once when the project is started. 7000
game is playing
Unconditionally runs every frame. 7021
📱 My device
is tapped
Runs once when the selected object was tapped. The object can also be the screen, which is only triggered if no other object is tapped. 7001
📱 My device
is pressed
Runs while an object is being pressed down. The object can also be the screen, which is only triggered if no other object is tapped. An object is only considered pressed if it was also tapped, and remains pressed even if the pointer is moved off of the object. 7003
📱 My device
is not pressed
Reverse case of (object) is Pressed. 7020
touch ends
Runs once when a touch ends, regardless of where it is on the screen. 7022
I get a message
Runs once if a message was broadcasted matching the value given. 7023
message matches
Runs once if a message was broadcasted matching the regex pattern. 7024
object is cloned
Analogous to Game Starts, running once for the new clone. 7015
📱 hears a loud noise
Runs once if the device picks up a loud noise. 7008
📱 is shaken
Runs once if the device is shaken. 7009
📱 My device
is swiped right
Runs once if the object or screen is pressed and the press quickly drags to the right. 7011
📱 My device
is swiped left
Runs once if the object or screen is pressed and the press quickly drags to the left. 7012
📱 My device
is swiped up
Runs once if the object or screen is pressed and the press quickly drags upwards. 7013
📱 My device
is swiped down
Runs once if the object or screen is pressed and the press quickly drags downwards. 7014
Self
bumps
Any object
Runs once when object A comes into contact with object B. 7010
Self
is touching
Any object
Runs while object A is in contact with object B. 7002
Self
is not touching
Any object
Runs while object A is not in contact with object B. 7025
(condition) Runs while the condition is true.

Abilities

Abilities are functions placed within rules that perform a specific action, typically on the object.

Movement

Movement abilities change the object's position and rotation.

Ability Description ID
Move Forward
100
Moves the object forward a set amount of pixels over time relative to its rotation and current speed. 23
Turn degrees
90
Rotates the object a set amount of degrees over time relative to its current speed. 24
Set Position to x
200
y
200
Sets the object's center to a specific coordinate from the bottom left of the project. 41
Flip
Flips the object's texture horizontally. 50
Change X by
100
Moves the object horizontally a set amount of pixels over time relative to its current speed. 27
Change Y by
100
Moves the object vertically a set amount of pixels over time relative to its current speed. 28
Set Speed to
1000
Sets the speed of the object. The default is 400. 34
Set Angle
30
Sets the angle of the object in degrees. 39
Set Origin to x
200
y
200
Sets the object's bottom left corner to a specific coordinate from the bottom left of the screen. 59

Looks

Looks abilities change the visual appearance of an object.

Ability Description ID
Set Background color
purple
Sets the background of the project to a specific color. 70
Set Color
purple
Sets the color of the object to a specific color. 54
Set Image
Changes the texture of the object to a different pre-set one. 56
Set Text to
color
black
Changes the texture of the object to the provided text. 40
Set Size percent
110
Changes the size of the object as a percent. 51
Set width
200
height
200
Changes the width and height of the object in pixels. 57
Grow by percent
50
Increases the size of the object as a percent. 48
Shrink by percent
50
Decreases the size of the object as a percent. 49
Start Sound
click
wait
0.5
Starts playing a pre-set sound. 62
Set invisibility percent
50
Sets the "invisibility" of the object as a percent. Invisibility is the opposite of opacity. 47
Bring to front
Places the object in front of all other existing objects. 43
Send to back
Places the object below all other existing objects. 42
Change pose
Cycles the pose once for an object if it has a compatible texture. 33
Set Z Index
0
Sets the z-index of an object. 58
Show Pop-up message
The message to show
Presents a pop-up to the user. 72
Set Text to Input
black
prompt
Type here
Presents a pop-up to the user with an input box to set the text of the object to. 64

Drawing

Drawing abilities allow objects to draw trails on the background.

Ability Description ID
Draw a Trail color
purple
width
10
End
Begins drawing a trail with a pre-set color and width. Any movement abilities ran within this block draw a line from the object's previous position to its new position. 26
Set Trail Color to
purple
Overwrites the color of the trail. 32
Set Trail Width to
2
Overwrites the width of the trail. 31
Set Trail Opacity percent
50
Sets the opacity of the trail as a percent. This ability cannot be accessed unless the project was created with a Hopscotch subscription or in the web editor. 73
Set Trail Cap to
round
Sets the caps of each line. "Round" draws circles at the ends of each line, "square" extends each line by half the width, while "butt" draws no caps. This ability cannot be accessed unless the project was created with a Hopscotch subscription or in the web editor. 71
Clear
Clears the background to white. 30

Variables

Variables abilities modify existing variables.

Ability Description ID
Set
to
10
Sets an existing user-defined variable to a value. 45
Increase
by
1
Increases an existing user-defined variable by a set value. 44
Save Input
prompt
Type here
Presents a pop-up to the user with an input box to set the user-defined variable to. 63

Controls

Controls abilities affect control flow and other miscellaneous functions.

Ability Description ID
Check Once If
End
Runs the blocks within if the condition is true. 122
Repeat times
5
End
Repeats the blocks within a set amount of times. 120
Check Once If
Else
End
Runs one set of blocks if the condition is true, and a separate set of blocks if otherwise. 124
Repeat Forever
End
Repeats the blocks within indefinitely. 121
Wait seconds
0.5
Yields execution of any further blocks in the rule for a set amount of seconds. 61
Wait Milliseconds
500
Yields execution of any further blocks in the rule for a set amount of milliseconds. 35
Create a Clone of This Object
Creates a new clone of the object. 53
Destroy
Removes the object. 55
Open Project
Opens a published project from its URL. 68
Change Scene to
0
Switches to another scene. 125
Broadcast Message named
Broadcasts a value for all objects. 126

Operators

Operators can be used where values are supplied.

Conditionals

Conditionals are only typically used by rules, the Check Once If ability, and the Check If Else ability. These evaluate to 0 (false) or 1 (true) when placed outside of conditionals.

Conditional Description ID
7
=
7
Checks if two values are equal, ignoring type. 1000
6
≠
7
Checks if two values are not equal, ignoring type. 1001
6
<
7
Checks if one value is less than another. 1002
8
>
7
Checks if one value is greater than another. 1003
5
<=
7
Checks if one value is less than or equal to another. 1006
8
>=
7
Checks if one value is greater than or equal to another. 1007
and
Returns true if both of its values are truthy. 1004
or
Returns true if either of its values are truthy. 1005
not
Returns true if its value is falsy. 1009
flipped
Returns true if the object's texture is currently flipped. 1010
matches
Checks if a string matches a regex pattern. 1008

Math

Operation Description ID
2
+
3
Adds two values together. This acts like concatenation if either value evaluates to a string. 4000
5
−
2
Subtracts two values. This evaluates to NaN if either value isn't a number. 4001
2
×
3
Multiples two values. This evaluates to NaN if either value isn't a number. 4002
5
÷
2
Divides two values. This evaluates to NaN if either value isn't a number. 4003
random
1
to
100
Returns a random integer between a lower and upper bound. 4004
2
^
3
Performs exponentiation on two values. This evaluates to NaN if either value isn't a number. 4005
√
25
Returns the square root of a value. This evaluates to NaN if the value isn't a number. 4006
sin
45
Returns the sine of a value. This evaluates to NaN if the value isn't a number. 4007
cos
45
Returns the cosine of a value. This evaluates to NaN if the value isn't a number. 4008
tan
45
Returns the tangent of a value. This evaluates to NaN if the value isn't a number. 4012
arcsin
0.5
Returns the arcsine of a value. This evaluates to NaN if the value isn't a number. 4013
arccos
0.5
Returns the arccosine of a value. This evaluates to NaN if the value isn't a number. 4014
arctan
0.5
Returns the arctangent of a value. This evaluates to NaN if the value isn't a number. 4015
max
100
200
Returns the bigger of two values. 4016
min
0
10
Returns the smaller of two values. 4017
round
2.5
Rounds a value to the nearest integer. This evaluates to NaN if the value isn't a number. 4009
floor
0.5
Rounds a value down. This evaluates to NaN if the value isn't a number. 4018
ceiling
0.5
Rounds a value up. This evaluates to NaN if the value isn't a number. 4019
absolute value
-10
Returns the absolute value of a value. This evaluates to NaN if the value isn't a number. 4010
5
%
2
Returns the modulus of two values. This evaluates to NaN if either value isn't a number. 4011

Text

Conditional Description ID
character in
at
0
Returns a single character in the string. Negative values and values at and after the length of the string return an empty string. This is not UTF-8 safe. 9000
character in
between
0
and
1
Returns a substring of the string. Negative values and values at and after the length of the string do not wrap around. This is not UTF-8 safe. 9001
length
Returns the length of the string. This is not UTF-8 safe. 9002
join
with
Concatenates two strings together. 9003

Custom rules and abilities

Custom rules and abilities are analogous to functions, where they have a set of arguments that are evaluated as local variables and contain blocks within. Note that local variables defined outside of a custom rule or ability cannot be accessed within the custom rule or ability.

Custom abilities are capable of recursion, and unlike the Repeat and Repeat Forever abilities, do not have a delay for each recursion, so long as the call is wrapped in a conditional. This makes them superior for repeated actions.

Optimization

Programming in Hopscotch requires a surprising amount of optimization consideration, as abilities can only run so fast. Detailed information regarding the performance of abilities and rules are provided by Spy Guy 96 in the project Hopscotch performance test.

Examples

A+B problem

Program
Text
When
game starts
Save Input
▶️ A
prompt
A
Save Input
▶️ B
prompt
B
Set Text to
▶️ A
+
▶️ B
color
black
End
End

FizzBuzz

Program
Text
When
game is playing
Increase
▶️ n
by
1
Set
▶️ Text
to
characters in
FizzBuzz
between
4
×
min
▶️ n
%
3
1
and
8
−
4
×
min
▶️ n
%
5
1
Check Once If
▶️ Text
=
0
Set Text to
▶️ n
color
black
Else
Set Text to
▶️ Text
color
black
End
End
End

99 bottles of beer on the wall

The fastest method is to recursively create clones until the entire string is built.

Song
Text
Set
▶️ 99Bstr
to
When
Self
Total Clones
<
99
Create a Clone of This Object
End
When
object is cloned
Set
▶️ 99Bstr
to
▶️ 99Bstr
+
100
−
Self
Clone Index
+
bottles of beer on the wall,\n
+
100
−
Self
Clone Index
+
bottles of beer.\nTake one down, pass it around,\n
+
100
−
Self
Clone Index
−
1
+
character in
bottles
between
0
and
5
+
100
−
Self
Clone Index
+
of beer on the wall.\n
Check Once If
Self
Clone Index
=
98
Show Popup message
▶️ 99Bstr
+
1 bottle of beer on the wall,\n1 bottle of beer.\nTake one down, pass it around,\nNo more bottles of beer on the wall.
End
End
End

This can be costly due to the amount of clones used and may not be applicable in all situations, thus a loop is the second best method.

Song (alternative)
Text
When
game starts
Set
▶️ Bottles
to
99
Set
▶️ 99Bstr
to
Repeat times
98
Set
▶️ 99Bstr
to
▶️ 99Bstr
+
▶️ Bottles
+
bottles of beer on the wall,\n
+
▶️ Bottles
+
bottles of beer.\nTake one down, pass it around,\n
+
▶️ Bottles
−
1
+
character in
bottles
between
0
and
5
+
▶️ Bottles
+
of beer on the wall.\n
Increase
▶️ Bottles
by
-1
End
Show Popup message
▶️ 99Bstr
+
1 bottle of beer on the wall,\n1 bottle of beer.\nTake one down, pass it around,\nNo more bottles of beer on the wall.
End
End

Kolakoski sequence

Sequence
Text
Set
▶️ Sequence
to
2,
Set
▶️ Text
to
,12
When
game is playing
Set
▶️ Text
to
join
▶️ Text
with
character in
▶️ Sequence
at
0
Set
▶️ Sequence
to
join
characters in
▶️ Sequence
between
2
and
length
▶️ Sequence
with
characters in
characters in
1,1,2,2,
between
character in
▶️ Sequence
at
length
▶️ Sequence
−
2
%
2
×
4
and
8
between
0
and
character in
▶️ Sequence
at
0
×
2
End
End
Printer
Text
When
game is playing
Set Text to
join
,
with
characters in
▶️ Text
between
max
length
▶️ Text
−
15
1
and
length
▶️ Text
color
black
End
End

Bitwise Cyclic Tag

Playable at https://www.gethopscotch.com/6300784/15cov53yqe.

Program
Text
When
game starts
Save Input
▶️ Program
prompt
Input the program. 1 is represented by `i`, 0 is represented by `o`.
Save Input
▶️ Queue
prompt
Input the queue. 1 is represented by `i`, 0 is represented by `o`.
End
When
▶️ Queue
≠
0
Set
▶️ Queue
to
join
characters in
▶️ Queue
between
▶️ Program
matches
^o
and
length
▶️ Queue
with
character in
character in
▶️ Program
at
1
at
1
−
▶️ Program
matches
^i
and
▶️ Queue
matches
^i
Set
▶️ Program
to
join
characters in
▶️ Program
between
1
+
▶️ Program
matches
^i
and
length
▶️ Program
with
characters in
▶️ Program
between
0
and
1
+
▶️ Program
matches
^i
End
End
Display
Text
When
game is playing
Set Text to
Program: 
+
▶️ Program
+
\nQueue: 
+
▶️ Queue
color
black
End
End

See also

External links