Skip to content

docs: add a recipes section #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions docs/recipes/workarounds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Workarounds

- **[Switch to previous costume](#switch-to-previous-costume)**
- **[Switch to last costume](#switch-to-last-costume)**
- **[Sense if sprite is shown or hidden](#sense-if-sprite-is-shown-or-hidden)**
- **[Set pen color to a RGB (or RGBA) value](#set-pen-color-to-a-rgb-or-rgba-value)**
- **[Point towards X, Y](#point-towards-x-y)**
- **[Rotate around X, Y](#rotate-around-x-y)**

## Switch to previous costume

```goboscript
%define previous_costume switch_costume "previous_costume"
```

## Switch to last costume

```goboscript
%define last_costume switch_costume 0
```

## Sense if sprite is shown or hidden

```goboscript
proc _show { visible = true; show; }
proc _hide { visible = false; show; }
%define show _show
%define hide _hide
```

You can extend this recipe to implement sensing of other sprite properties, which
Scratch does not provide a reporter block for. For example, you can implement
sensing of the ghost effect of a sprite.

## Set pen color to a RGB (or RGBA) value

Use the `RGB()` and `RGBA()` macros provided in the standard library header `std/math`.

```goboscript
%include std/math
set_pen_color RGB(red, green, blue);
```

## Point towards X, Y

```goboscript
proc point_towards_xy x, y {
point_in_direction atan($x - x_position() / $y - y_position());
if $y < y_position() {
turn_right 180;
}
}
```

## Rotate around X, Y

```goboscript
%include std/math

proc rotate_around x, y, degrees {
local dir = direction();
local dist = DIST($x, $y, x_position(), y_position());
point_towards_xy $x, $y;
goto
$x + dist * sin(direction() + 180 + $degrees),
$y + dist * cos(direction() + 180 + $degrees);
point_in_direction dir;
turn_right $degrees;
}
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ nav:
- Visual Studio Code: editor-integration/vscode.md
- Sublime Text: editor-integration/sublime-text.md
- Notepad++: editor-integration/notepad++.md
- Recipes:
- Workarounds: recipes/workarounds.md
theme:
name: material
features:
Expand Down
Loading