Discuss Scratch

Wars-X
Scratcher
3 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

Woah
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

I've published v1.0.0

Some of the new features:

`def` was renamed to `proc`, because in the future I will be adding `func` for functions which can return values.

Added `local` variables, define local variables inside procedures.

Added enums:

enum MyEnum {
Variant1,
Variant2
}

onflag {
say MyEnum.Variant1;
say MyEnum.Variant2;
}

During compilation, these will be replaced with numbers starting from 0, so `MyEnum.Variant1` becomes `0` and so on…

I've also changed the syntax for some list operations:

insert value at list[index];
delete list[index];
sly_i
Scratcher
10 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

Wow this is great. Does VSCode support auto complete for keywords/scratch built-in functions?
julmik6478
Scratcher
500+ posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

Cool

Last edited by julmik6478 (June 9, 2024 07:41:50)

ninjaMAR
Scratcher
1000+ posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

bump
pkhead
Scratcher
1000+ posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

aspizu wrote:

`def` was renamed to `proc`, because in the future I will be adding `func` for functions which can return values.
ooh, i've always wanted that in scratch…

how do you think it'll be implemented? by assigning to variables or using a list as a stack?

also, how would a potential implementation of it handle the multi“thread”ed nature of scratch? i've been thinking about it and the fact that scratch is multi“thread”ed really had my head scratching on how a potential generally applicable implementation of functions would work. since on a screen refresh it's possible that another script could set the value of the return variable or list stack.
pkhead
Scratcher
1000+ posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

…how do you declare lists in a sprite?

i'm assuming you're supposed to do this?
costumes "alien-in-suit.png";

onflag
{
mylist = [];

forever
{
change_x 2;
}
}
yet I get this error
error: unrecognized token
╭→ main.gs:6:1

6 │
│ ─
error: cannot continue due to syntax errors
I'm going insane over this does anyone know

edit: nvm figured it, i had to use delete list; to declare a list. that's… very unintuitive.

Last edited by pkhead (Sept. 16, 2024 15:43:24)

aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

pkhead wrote:

aspizu wrote:

`def` was renamed to `proc`, because in the future I will be adding `func` for functions which can return values.
ooh, i've always wanted that in scratch…

how do you think it'll be implemented? by assigning to variables or using a list as a stack?

also, how would a potential implementation of it handle the multi“thread”ed nature of scratch? i've been thinking about it and the fact that scratch is multi“thread”ed really had my head scratching on how a potential generally applicable implementation of functions would work. since on a screen refresh it's possible that another script could set the value of the return variable or list stack.
My solution to that problem is to only allow calling functions inside run-without-screen-refresh custom blocks. My potential solution will make use of one variable per call-site. The call-site variable will be set to the return variable (unique to each function) after calling the function. Still need to work out the algorithm to separate nested call-sites.
aespibr
Scratcher
72 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

perhaps i oughta do more advertising of scrybe… feel free to copy borrow my implementation of return variables if you so desire
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

I did a rewrite of goboscript, I've pushed it to master but it has some things which are broken.

new features are: structs, includes, macro processing. some old features like enums were nuked, they will come back slowly.

ive also replaced the error reporting module with the one from rust, so the errors now look the same as the ones from rustc
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

i've implemented functions with return values. its not stable yet so not pushed.

func cat(a, b) {
return $a & $b;
}

onflag {
say cat(cat("A", "B"), cat("C", "D"));
}
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

The factorial function
func factorial(n) {
if $n == 0 {
return 1;
}
return $n * factorial($n - 1);
}

I've also added the pipe operator for convenience, It let's you pass the left hand side as the first argument of a function/reporter.

%include std/string
onflag {
say "$who likes $what"
|> replace("$who", "aspizu")
|> replace("$what", "goboscript");
}

Notice the
%include std/string
? Thats goboscripts standard library. It will include a plethora of custom blocks (procedures), functions, macros. Currently, I have std/math for mathematical macros and functions, std/string for string manipulation and std/algo for algorithms (such as sorting). The source is in the std folder in the git repository. Let me know if you guys have any functions or macros to contribute.

If you don't use a function/procedure it won't be included in the final compilation. So using the std library will not spam your code with lot of code.
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

New pre-processor feature, conditional compilation. This is very useful for library authors.

%if macro_name
code
%endif

%if not macro_name
code
%endif
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

goboscript now has a package manager – backpack

backpack lets you fetch a package (which is a github repository with version tags) listed in your goboscript.toml

Add dependencies to your project by adding them to `goboscript.toml`:

[dependencies]
dependencyName = "https://github.com/aspizu/dependencyName@v1.0.0"

then backpack/dependencyName will be linked to the repository clone. you can then include goboscript files from it.
pkhead
Scratcher
1000+ posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

sick !!
mybearworld
Scratcher
1000+ posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

This is really cool!

Recursive functions seem to have a bit of a problem though, for example with this code:
costumes "blank.svg";

list calls;

func eat_number(x) {
if $x == 0 {
return $x;
}
add $x to calls;
return eat_number($x - 1);
}

onflag {
show calls;
say eat_number(7);
}
With the number 7, it works fine – but the function is still called 127 times which seems a bit excessive.
The number 20 made the function get called 1,048,575 times.
100 crashed Turbowarp, so I don't know how many times it's added the number
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

mybearworld wrote:

This is really cool!

Recursive functions seem to have a bit of a problem though …

This is a known issue, calling a function in the last return stmt causes the function call to be duplicated.
https://github.com/aspizu/goboscript/issues/78
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

goboscript has new statements and keywords:

Properties

Sprite properties can be set using statements similar to blocks which set those properties at runtime.

Note:
These statements are top-level, outside any declaration block.
Sprite default X position
set_x 100;
Sprite default Y position
set_y 100;
Sprite default size
set_size 100;
Sprite default direction
point_in_direction 100;
Sprite default volume
set_volume 100;
Set sprite default visibility to hidden
Hide sprite by default.
hide;
Set Sprite default rotation style to left-right
set_rotation_style_left_right;
Set Sprite default rotation style to all around
set_rotation_style_all_around;
Set Sprite default rotation style to don't rotate
set_rotation_style_do_not_rotate;
Set Sprite layer order
Set the layer order of the sprite. The layer order is the order in which the sprites are drawn, and scripts are executed.
set_layer_order 100;
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

I am thinking of adding a Recipes section to the documentation. Recipes are a collection of practical, real-world examples or step-by-step guides demonstrating how to achieve specific tasks using goboscript. If you guys have any pre-built solutions for common use cases for goboscript, please add it to the discussions page for recipes.
aspizu
Scratcher
44 posts

goboscript - Convert text code to Scratch blocks, Scratch compiler written in Rust.

I've added a basic font rendering engine to the goboscript standard library. Include the std/font header to use it.

Copy font.txt from the std repo to your project directory and include it in your project as a list:
list font_data = file ```font.txt```;

Basic Text Rendering:
font_render_begin;
font_render_text "Hello, Goboscript!";

Soft Wrapped Text Rendering:
font_render_begin;
font_render_text_softwrap "This is a longer sentence that will automatically wrap based on the set boundaries.";

Variables:
+-------------------+---------------------------------------+
| font_offset | Offset value into the font data. |
| font_x, font_y | Current drawing position. |
| font_scale | Scaling factor for the rendered font. |
| font_x1, font_x2 | Define the text boundary limits. |
| font_char_spacing | Spacing between characters. |
| font_line_spacing | Spacing between lines. |
+-------------------+---------------------------------------+

Powered by DjangoBB