UCanCode

From Esolang
Jump to navigation Jump to search

UCanCode is a programming language created in 2021 for Windows Poop Edition 3.0, an operating system by CrapOS. Out of context, Windows PE is a series of fake operating system simulators created by User:Viba, who also created UCanCode. The original implementation transpiles code into Lua and runs it. The language consists primarily of commands that are structured almost like plain English, and are influenced by Scratch.

The name 'UCanCode' is "a blatant lie, as you will almost certainly not succeed in writing a program in UCanCode. We don't feel like changing the name to 'UCantCode', so you're just gonna have to deal with this."

Overview

A program consists of a sequence of commands separated by newlines. Each command follows a specific structure, which arguments may be substituted into (eg. A is B plus C). An argument is frequently a variable name, but might also be a constant in some commands. When describing commands on this page, A B C will refer to arguments that represent variable names, while X will refer to arguments representing constants. A variable name consists of alphanumeric characters. A constant also consists of alphanumeric characters, but may sometimes consist of a sequence of characters enclosed by quotation marks.

Consider the following code:

a is 2
b is 3
c is a plus b
write c

A is X is a command that assigns the constant X to the variable A. In this code, 2 and 3 are assigned to the variables a and b respectively. The line c is a plus b is actually it's own command, as opposed to just being A is X where X is substituted for an expression; this command will compute the sum of the values of a and b and store it in the variable c. Finally, write c outputs the variable c. (Specifically, in the original Windows Poop Edition implementation, write A will display text in a window at whatever position the "pen" is currently set to, which is 0,0 by default.)

Starting with UCanCode version 1.1, a line starting with # is a comment.

Implementation Drawbacks

The original implementation included in Windows PE 3 and Windows PE 4 does not properly handle lines with surrounding whitespace, eg. tabulation. However, version 1.1 of the UCanCode runtime, which fixes this issue, was included in the Public Beta 7.0 release of Windows PE 5.

Another issue with the original version of the UCanCode runtime is that arithmetic commands would internally store their results as numbers instead of strings, which causes so many horrible bugs that I have no idea how this wasn't discovered for so long. This was also fixed in version 1.1 of the runtime.

Commands

Indices start from 1.

List of commands
Syntax Description
A is X Set the value of variable A to constant X. X may be a sequence of characters enclosed in quotation marks (allowing strings containing non-alphanumeric characters).
A is the value of B Set the value of variable A to the value of variable B.
A is a list Declare variable A as an empty list.
add A to B Append A to list B.
insert A into position B of C Insert A into position B of list C.
replace item A of B with C Set the value of the item at position A of list B with C.
remove item A from B Remove the item at position A from list B.
A is the item at position B of C Store the item at position B of list C into A.
A is B plus C Add B to C and store the result in A.
A is B minus C Subtract B and C and store the result in A.
A is B times C Multiply B and C and store the result in A.
A is B divided by C Divide B and C and store the result in A.
A is B modulo C Modulo B and C and store the result in A.
A is whether B equals C Set A to "true" if B equals C, "false" otherwise.
A is whether B is more than C Set A to "true" if B is greater than C, "false" otherwise.
A is whether B is less than C Set A to "true" if B is less than C, "false" otherwise.
A is whether B is at least C Set A to "true" if B is greater than or equal to C, "false" otherwise.
A is whether B is at most C Set A to "true" if B is less than or equal to C, "false" otherwise.
A is whether B and C are true Set A to "true" if both B and C are "true", "false" otherwise.
A is whether B or C is true Set A to "true" if either B or C is "true", "false" otherwise.
A is whether B is false Set A to "true" if B is "false", "false" otherwise.
A is B joined with C Concatenate B and C and store the result in A.
A is the length of B Store the length of B into A.
A is the letter at position B of C Store the character at position B of C into A.
A is a random number between B and C Generate a random number between B and C, and store the result in A.
if A is true Branch if A equals "true".
elseif A is true Branch if A equals "true" and the previous branch didn't execute.
else Branch if none of the preceding "if" branches executed.
while A is true Loop branch while A equals "true".
when program loads Defines a block of code that runs when the program first starts.
when program updates Defines a block of code that runs every frame to update the program state. Executes before when program draws.
when program draws Defines a block of code that runs every frame to draw the screen. Executes after when program updates.
when button X is clicked Defines a block of code that runs when the button with identifier X is clicked.
when prompt X is answered Defines a block of code that runs when the user has submitted a response to the text input prompt with identifier X. The variable answer is set to the response.
when mouse is clicked Defines a block of code that runs when the left mouse button is clicked.
when the X key is pressed Defines a block of code that runs when the key with code X is pressed. (In the original implementation, the key codes are the same as the key strings used in LÖVE).
end End branch or code block.
move to A B Sets the X and Y position of the "pen" to A and B. (The pen is at 0,0 by default, which would be the top-left corner of the window in the original implementation.)
change x by A Changes the X position of the pen by A.
change y by A Changes the Y position of the pen by A.
write A Displays text A at the current pen position.
draw button X that says A Displays button with identifier X and text B at the current pen position.
ask A with id X Request text input from the user with prompt A and identifier X. Note that this does not pause execution of the program (the code block defined by when prompt X is answered will be run when the user finishes inputting text.)
show message box that says A Shows a Windows Poop Edition message box with text A and an "OK" button to close it.
set color to A B C Sets the RGB value of the pen's current color to A B C (0-255). The pen color is 0,0,0 by default.
draw rectangle with size A B Draws a rectangle at the current pen position with width A and height B.
draw image A with size B C Draws an image from the Windows Poop Edition filepath A at the current pen position with width B and height C.
A is the time since the program started Stores the current value of the timer into A. Contrary to the command's name, the timer may be reset at any time during the program's execution using reset the timer
reset the timer Resets the value of the timer to 0.
define A Defines variable A as a block of code that may be executed later.
do A Executes the block of code at A.
A is whether the mouse is down Set A to "true" if the left mouse button is currently pressed, "false" otherwise.
A is whether the X key is down Set A to "true" if the key with code X is pressed, "false" otherwise.
A is the x position of the mouse Stores the current x position of the mouse into A. (In the original implementation, this position is relative to the window, as opposed to the entire screen.)
A is the y position of the mouse Stores the current y position of the mouse into A. (In the original implementation, this position is relative to the window, as opposed to the entire screen.)

Examples

Hello world

when program loads
hello is "Hello, world!"
end

when program draws
write hello
end

Truth machine

when program loads
0 is 0
1 is 1
output is ""
prompt is "Enter 0 or 1"
ask prompt with id p
end

when prompt p is answered
c is whether answer equals 0
if c is true
output is 0
end
c is whether answer equals 1
if c is true
output is 1
end

when program updates
l is the letter at position 1 of output
c is whether l equals 1
if c is true
output is output joined with 1
end
end

when program draws
write output
end

move.ucc

This program is included in the "Sample Files" folder in Windows Poop Edition 3.0. It displays a black square which may be moved using the arrow keys.

when program loads
x is 0
y is 0
0 is 0
dx is 0
speed is 5
rsize is 40
instructions is "Use the arrow keys to move the square!!!\nWARNING: there will likely be lag. probably because UCanCode is so TERRIBLE"
end

define move
x is x plus dx
y is y plus dy
end

when program updates
up is whether the up key is down
down is whether the down key is down
left is whether the left key is down
right is whether the right key is down

dx is 0
dy is 0

if up is true
dy is 0 minus speed
end

if down is true
dy is the value of speed
end

if left is true
dx is 0 minus speed
end

if right is true
dx is the value of speed
end

do move
end

when program draws
move to x y
draw rectangle with size rsize rsize

move to 0 0
write instructions
end

External links

  • Windows Poop Edition 3, the OS simulator for which UCanCode was developed which includes the canonical implementation. (Later versions also include UCanCode.)