Skip to content

penderact13/coconutscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 

Repository files navigation

Coconut Script

The home of Coconut Script. AKA Colon Script. Still in development, and still working on a compiler, but this is all I've made. Coconut Script is inspired by C++ and scratch.mit.edu Planning for the compiler to first be made in GoLang, then maybe 2.0 in C++ or Rust.

Update Log

2025/05/26
Release
Added Sample
Added Table
Table Complete; Version 0.2!

General Info

Here is some general info. This coding language does not use parentheses. Actually the text inside of a parentheses is a comment. It uses colons and curly brackets. Practically nothing else. Most scripts do what they're called too.

Sample code

Here's some sample code I made:
Sample Code
This makes a object that follows the mouse, but bounces when it reaches the corners of the screen.

Table of Code

Script Explanation and more
start:coconut:0:1 Starts up the coconut script, like DOCTYPE. (numbers after are coconut script version)
on:start { } When the code is started, code inside the {} are executed.
forever { } Code inside is repeated as long as the script is running:
repeat:2 { } The second number determines how long the loop repeats.
insert:images:folder Inserts costumes from a folder inside of the same folder as the script. 
insert:image:image.png Inserts one costume from the same directory as a costume. (a gif will become multiple costumes representing each frame)
if(condition) { } If statement
if(condition) { } else { } If else statement
if:(condition) { } else:if:(condition) { }  If else if statement, also can become a if else if else, and a if else if else… and so on.
var:x: xDeclares a variable, can happen outside of the on start script. “ are needed  for text, ‘ is also excepted. Also supports true and false. 
var:x:45 Declares and assigns a variable, cannot happen outside of the on start script. “ are needed  for text, ‘ is also excepted.
arr:y:1:2:3:4:5 Declares and assigns an array or list with items. No clear limit on the length. Items can be assigned to variables, which will change when the variable changes, but will not change the variable when it is changed.
mat:z:1,2,3:4,5,6:7,8,9 This will create a matrix called z with 3 rows and columns. Separate items with commas and rows with colons. Same rule as lists for assigning variables, but size cannot change later. (for lists and matrices, the first value is 1, not 0.)
mat:z:[3,3] Creates a matrix with a size of 3 by 3.
while:(condition) { } While loop
before:(condition) { } Repeats until the statement is true.
x+y Value is the sum of the variables
x+=y x=y+x
x*y Multiplies 2 sums
x*=y X=x*y
x-y Subtracts 2 numbers
x-=y x=x-y
x/y Divides two numbers
x/=y x=x/y
<, <=, >, >= Operators that give true or false. Must be in between colons. See and / or for example.
true:&:true Only outputs true if both statements are true (and)
true:|:false Outputs true if at least one side is true. (or)
1::1 = sign, outputs true if both are the same. A≠a
1:!:2 Not equals sign. Outputs true if both are not the same.
!:1::2 Makes the condition to its right (separated by colon) false.
true:#:false Like or, but if both symbols are the same, it is false. xor
arr:1 Gets the nth value of an array
mat:1:1 Gets the nth value of the nth row of a matrix. (row:column)
costume::1 Sets the current costume to the nth costume.
costume:n A variable that stores the current costume.
costume:+=:1 Next costume, can become -= for previous.
key:space Space key press boolean.
key:space:rel Space key released boolean.
key:mouse:1 Checks if the mouse is down. 1 is primary, 2 is middle, 3 is secondary, boolean
key:mouse:1:rel Checks if the mouse is released. 1 is primary, 2 is middle, 3 is secondary, boolean
scroll:down Checks if the mouse is scrolling down (can be replaced with up)
mouse:x Mouse x pos
mouse:y Mouse y pos
sprite:character {} Contains the code for a sprite. Outside of the on start, contains the on start actually. A script can have multiple of them, resembling different characters. Variables are not shared between them, unless specified.
var:score If a variable/ list / array is made outside of a sprite specific code, it is automatically global.
pos:x::0 Sets the x position. += and -= can be added in between the colons.
pos:y::0 Sets the y position. Same rule of = as x.
x:pos, y:pos Value of the x / y position.
print:”Hello World” Prints text to the console at the current x and y position.
print:”Center”:0:0 Print text at a defined x and y position.
erase: Erases printed text
wait:sec:1 Waits one second, can become wait:ms:1, which would make it milliseconds.
erase:1 Erases the nth print.
print:”Variable x =”:x Prints text and a variable
print:”Hello World!”:bl:”- From Coconut”: Prints a two texts on separate lines, you can use any combination of strings, numbers, variables, lists, arrays, and break lines in print.
plugin:physics:0:1 Imports a plugin version (in this case, physics v0.1)
dir:=:90 All sprites start off with a direction of 90, and 90 is towards the right. 0 is up, 180 is down, -90 is left. Can be changed to dir:+=:0 (clockwise) and -=.
dir Direction variable (premade)
pos:x::0:y::0 Sets both x and y in the same script.
mv:10 Moves the sprite  in the current direction of the sprite
rot:styl:lr Changes the rotation style. Default is ar, (all around), then lr (left and right only), and nr (no visible rotation).
dir:tow:0:0 Points the direction to a x and y coordinate.
glide:sec:2:0:0 Glides to a location in defined seconds.
size::100 Sets the size. 100 is default.
size Size variable
visible::1 1 is visible, 0 is not
shown value of visibility. Is boolean
sprite:clicked {} Goes outside of the on start. Starts when this sprite is clicked.
when:message1 {}  Goes outside of the on start. Starts when the message is broadcasted. 
broadcast:message1 Broadcasts a message ⤴️
broadcast:message1:td Broadcasts a message but waits till all the when message scripts are completed.
wait:till:(condition) Stops the script and will continue once the condition becomes true.
stop:all Stops the entire script
stop:this Stops the current script. ie if its is inside of a forever loop, stops it. Stops a function. Just stops the local script.
new:clone:sprite Creates a clone of a sprite, ⤵
when:cloned { } Goes outside of the on start. Runs when cloned. 
delete:clone Deletes the clone. Can only go inside of a when:cloned {}
(Comment!) Comment
touching:mouse Boolean. Mouse can be replaced with edge and other sprites
distance:0:0 Sees the distance to a x and y position
distance:mouse Sees the distance to a object (mouse or a sprite)
layer::front Changes the layer to the frontmost layer. layer:back changes it to the back most layer. You can also 
layer:+=:1 Goes up n layers. Can be changed to layer:-=:1 to go down n layers.
ghost::0 Set Ghost effect 
ghost:+=:5 Change ghost effect.
sound:music.mp3 Starts a mp3 from the same directory as the script.
sound:music.mp3:wait Starts a mp3, but delays the script until the mp3 is done. (good for loops)
sound:stop Stops all sounds
volume::100 Sets the volume. (add += and -= to change)
volume Value of the volume
ask:”What’s your name”:name Displays a text and asks for input. Input is assigned to a variable. (if the variable doesn’t exist, it will create a variable)
var:of:sprite Value is the variable of another sprite. Not just variables, but position (x:of:sprite, y:of:sprite), costume (cos:of:sprite), and size. (size:of:sprite.
draggable::0 If it is draggable,(1) then when the sprite is clicked and held on, it will move with the mouse.
drag Boolean of whether the sprite is draggable. (preset at 0)
touching:[255, 255, 255] Checks whether the sprite is touching a color (supports hex and rgb)
current:color Value of the current color being touched. Works best on small sprites, as big sprites cover more color, and they all get merged to one color.
rand:0:100 Value is a random value from a to b. (including a and b)
letter:1:”apple” Output is the nth character of an input
length:”banana” Output is the length of an input.
apple:cont:a Boolean. True is if input 1 contains input 2.
1:mod:2 Mod of two numbers
round:3.4 Rounds input to a whole number
abs:1 Self explanatory⤵
floor:1.6                             ↓ 
ceil:1.2                             ↓ 
cos:1                             ↓ 
sin:1                             ↓ 
tan:1                             ↓ 
asin:1                             ↓ 
acos:1                             ↓ 
atan:1                             ↓ 
in:1                           ↵ 
10p:1 10^(input)
ep:1 e^(input)
pi Pi
delete:1:lis Deletes the nth item of a list.
delete:1:1:arr Deletes the nth item of the nth row of a matrix
delete:arr Deletes the entire list or matrix
reset:mat:4:4 Resets a matrix, unlike delete, you can now define a new size.
rep:1:list:”new” Replaces the nth item of a list with an input
rep:1:1:mat:”new” Replaces the nth item of the nth row in a matrix with a input.
itn:”Second”:list The index of an item in a list or matrix. (value)
length:list Length of a list (value). Length of a matrix will give the area of the matrix. 
rows:mat (or) col:mat The rows/columns of a matrix.
list:cont:”item” Boolean. Checks whether a list or matrix contains an item.
function:[(input)] Calls a function. Also will return a input.
def:function:(inputs) { } Defines a function. For adding an input, it would look like def:function:x, and multiple would look like def:function:x:y. Goes outside of the on start, but only inside of a sprite function cause sprites cannot share functions.
return:x Returns a value in a function
shell:ls Runs a terminal command
insert:images:(url) Imports costumes from a url.
time:now Returns the current time.
break Breaks out of a loop.
continue Skips a loop.
const:pi Declares a constant. Also, you could use “const:pi:4” To also assign it. Constants are assigned only once, never changed.
split:listname:”a,b,c”:”,” Makes a list out of a string. (in this case, the comma is the separator,.)
join:list:"," Makes a list into a string with the separator ,.
del:myvar (or a list/matrix) Delete a variable.
setup:fps:60 Sets the fps
setup:color:rgb Sets the color values
setup:size:1080:720 Sets the screen size of the game.
setup:cropstyle:fit Sets the style of the resize (when needed)
db:(make a variable) Makes a variable and stores it. When the window is closed, then opened again later, the variable is the same. When addressing it later, just use the name of the variable. (stands for data block)
null Empty value. AKA false. When variables are declared, but not assigned they are this.
sqrt:2 Finds the square root.
cbrt:8 Finds the cube root
the secret word is smash smash (include smash in your form, don't make it obvious)

About

The home of Coconut Script.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published