Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Johan-Mi/ScratchCompiler

Repository files navigation

ScratchCompiler

Compiles code into scratch projects.

Language reference

If you've ever used Python, you will probably find the syntax familiar.

The stage

stage:
	...

There can only be one stage. It can contain variables, lists, costumes and procedures.

Sprites

sprite name_of_sprite:
	...

You can create as many sprites as you want. Sprites can, just like the stage, contain variables lists, costumes and procedures.

Costumes

costumes {
	"costume1.png", "costume2.svg"
}

Sprites and the stage contain a list of costumes. The costumes are referred to by their file names.

Variables

foo : var

Declares a variable named foo. Variables can either be declared in the global scope or in a sprite.

foo = 5

Assign a value to a variable.

foo += 10
foo -= 10
foo *= 10
foo /= 10

These statements are equivalent to the following:

foo = foo + 10
foo = foo - 10
foo = foo * 10
foo = foo / 10

Lists

lst : list

Declares a list named lst.

lst[n]

Returns the nth element of lst. List indices start at 1.

lst += value

Appends value to the end of lst.

List procedures

lst.append(value)

Appends value to the end of lst.

lst.clear()

Removes all elements from lst.

lst.insert(index, value)

Inserts value at index in lst.

TODO: Add more list function and procedures.

Procedures

def my_procedure(a, b, c):
	doSomething()
	doSomethingElse()

Creates the procedure my_procedure that takes the arguments a, b and c. When called, it will run the indented code block. Procedures can belong to sprites or the stage.

warp def render():
	...

The warp keyword applies "run without screen refresh" to a procedure.

If statements

if a_condition:
	doSomething()

Run doSomething() if a_condition is true.

if a_condition:
	branch1()
else:
	branch2()

Run branch1() if a_condition is true, otherwise run branch2().

if a_condition:
	branch1()
elif another_condition:
	branch2()

Run branch1() if a_condition is true. If it's not true, continue down and run branch2() if another_condition is true. elifs can be chained and the chain can optionally end with an else that will run if all of the conditions fail.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages