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
Username The username of the account being used to play the project.
Time The current Unix timestamp in seconds.
Year The current year.
Month The current month.
Day The current day.
Hour The current hour.
Minute The current minute.
Second The current second.

Game variables

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

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

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
Rotation The rotation of the object in degrees.
X Position The X position of the object in pixels from the left side of the project.
Y Position The Y position of the object in pixels from the bottom side of the project.
Invisibility as a % The "invisibility" of the object as a whole number ranging from 0 to 100. "Invisibility" is the opposite of opacity.
Size as a % The scale of the object multiplied by 100 as a whole number.
Speed The "speed" of the object.
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.
Total Clones The total clones an object has, including the initial object.
Width The width of the object in pixels.
Height The height of the object in pixels.
Z Index The z-index of the object.
Origin X The X position of the bottom left corner of the object in pixels from the left side of the project.
Origin Y The Y position of the bottom left corner of the object in pixels from the bottom side of the project.
Name The name of the object.

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
Game Starts Runs once when the project is started.
Game is Playing Unconditionally runs every frame.
(object) 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.
(object) 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.
(object) is Not Pressed Reverse case of (object) is Pressed.
I Get a Message (value) Runs once if a message was broadcasted matching the value given.
Message Matches (regex) Runs once if a message was broadcasted matching the regex pattern.
Object is Cloned Analogous to Game Starts, running once for the new clone.
📱 Hears a Loud Noise Runs once if the device picks up a loud noise.
📱 is Shaken Runs once if the device is shaken.
(object) is Swiped Right Runs once if the object or screen is pressed and the press quickly drags to the right.
(object) is Swiped Left Runs once if the object or screen is pressed and the press quickly drags to the left.
(object) is Swiped Up Runs once if the object or screen is pressed and the press quickly drags upwards.
(object) is Swiped Down Runs once if the object or screen is pressed and the press quickly drags downwards.
(object A) Bumps (object B) Runs once when object A comes into contact with object B.
(object A) is Touching (object B) Runs while object A is in contact with object B.
(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
Move Forward (pixels) Moves the object forward a set amount of pixels over time relative to its rotation and current speed.
Turn (degrees) Rotates the object a set amount of degrees over time relative to its current speed.
Set Position (x) (y) Sets the object's center to a specific coordinate from the bottom left of the project.
Flip Flips the object's texture horizontally.
Change X by (pixels) Moves the object horizontally a set amount of pixels over time relative to its current speed.
Change Y by (pixels) Moves the object vertically a set amount of pixels over time relative to its current speed.
Set Speed (amount) Sets the speed of the object. The default is 400.
Set Angle (degrees) Sets the angle of the object in degrees.
Set Origin (x) (y) Sets the object's bottom left corner to a specific coordinate from the bottom left of the screen.

Looks

Looks abilities change the visual appearance of an object.

Ability Description
Set Background (color) Sets the background of the project to a specific color.
Set Color (color) Sets the color of the object to a specific color.
Set Image (texture) Changes the texture of the object to a different pre-set one.
Set Text (color) (text) Changes the texture of the object to the provided text.
Set Size (percent) Changes the size of the object as a percent.
Set Width and Height Changes the width and height of the object in pixels.
Grow by (percent) Increases the size of the object as a percent.
Shrink by (percent) Decreases the size of the object as a percent.
Start Sound (sound) Starts playing a pre-set sound.
Set Invisibility (percent) Sets the "invisibility" of the object as a percent. Invisibility is the opposite of opacity.
Bring to Front Places the object in front of all other existing objects.
Send to Back Places the object below all other existing objects.
Change Pose Cycles the pose once for an object if it has a compatible texture.
Set Z Index (index) Sets the z-index of an object.
Show Pop-up (prompt) Presents a pop-up to the user.
Set Text to Input (color) (prompt) Presents a pop-up to the user with an input box to set the text of the object to.

Drawing

Drawing abilities allow objects to draw trails on the background.

Ability Description
Draw a Trail (color) (width) 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.
Set Trail Color Overwrites the color of the trail.
Set Trail Width Overwrites the width of the trail.
Set Trail Opacity 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.
Set Trail Cap (type) 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.
Clear Clears the background to white.

Variables

Variables abilities modify existing variables.

Ability Description
Set (variable) to (value) Sets an existing user-defined variable to a value.
Increase (variable) by (value) Increases an existing user-defined variable by a set value.
Save Input (variable) (prompt) Presents a pop-up to the user with an input box to set the user-defined variable to.

Controls

Controls abilities affect control flow and other miscellaneous functions.

Ability Description
Check Once If (condition) Runs the blocks within if the condition is true.
Repeat (times) Repeats the blocks within a set amount of times.
Check If Else (condition) Runs one set of blocks if the condition is true, and a separate set of blocks if otherwise.
Repeat Forever Repeats the blocks within indefinitely.
Wait (seconds) Yields execution of any further blocks in the rule for a set amount of seconds.
Wait (milliseconds) Yields execution of any further blocks in the rule for a set amount of milliseconds.
Create a Clone Creates a new clone of the object.
Destroy Removes the object.
Open Project (URL) Opens a published project from its URL.
Change Scene Switches to another scene.
Broadcast Message (value) Broadcasts a value for all objects.

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
= Checks if two values are equal, ignoring type.
Checks if two values are not equal, ignoring type.
< Checks if one value is less than another.
> Checks if one value is greater than another.
<= Checks if one value is less than or equal to another.
>= Checks if one value is greater than or equal to another.
and Returns true if both of its values are truthy.
or Returns true if either of its values are truthy.
not Returns true if its value is falsy.
flipped Returns true if the object's texture is currently flipped.
matches Checks if a string matches a regex pattern.

Math

Math can be used where values are supplied.

Operation Description
Add Adds two values together. This acts like concatenation if either value evaluates to a string.
Subtract Subtracts two values. This evaluates to NaN if either value isn't a number.
Multiply Multiples two values. This evaluates to NaN if either value isn't a number.
Divide Divides two values. This evaluates to NaN if either value isn't a number.
Random (lower) (upper) Returns a random integer between a lower and upper bound.
Power Performs exponentiation on two values. This evaluates to NaN if either value isn't a number.
Square Root Returns the square root of a value. This evaluates to NaN if the value isn't a number.
Sine Returns the sine of a value. This evaluates to NaN if the value isn't a number.
Cosine Returns the cosine of a value. This evaluates to NaN if the value isn't a number.
Tangent Returns the tangent of a value. This evaluates to NaN if the value isn't a number.
Inverse Sine Returns the arcsine of a value. This evaluates to NaN if the value isn't a number.
Inverse Cosine Returns the arccosine of a value. This evaluates to NaN if the value isn't a number.
Inverse Tangent Returns the arctangent of a value. This evaluates to NaN if the value isn't a number.
Maximum Returns the bigger of two values.
Minimum Returns the smaller of two values.
Round Rounds a value to the nearest integer. This evaluates to NaN if the value isn't a number.
Floor Rounds a value down. This evaluates to NaN if the value isn't a number.
Ceiling Rounds a value up. This evaluates to NaN if the value isn't a number.
Absolute Value Returns the absolute value of a value. This evaluates to NaN if the value isn't a number.
Modulo Returns the modulus of two values. This evaluates to NaN if either value isn't a number.

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
Check If Else
▶️ n
%
3

=

0
Check If Else
▶️ n
%
5

=

0
Set Text to
FizzBuzz
color
black
Else
Set Text to
Fizz
color
black
End
Else
Check If Else
▶️ n
%
5

=

0
Set Text to
Buzz
color
black
Else
Set Text to
▶️ n
color
black
End
End
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