Skip to main content

cloudtrigger

Watch a Scratch project's cloud variables and set cloud variables when something changes.

pip install cloudtrigger          # or from this folder: pip install .

Heads up: Scratch has changed its cloud server so outside programs can no longer read cloud variables on scratch.mit.edu. The bot can still log in and connect, but it won't see any changes there. Use TurboWarp mode (below) and have people play your project at turbowarp.org/<project id>.

Python

from cloudtrigger import CloudWatcher

cloud = CloudWatcher(1234567890, "blockblock2", password="...")

# rule: when door becomes 1, set light to 1
cloud.when("door", equals=1, set={"light": 1})

# rule with a number check, copying the new value
cloud.when("score", above=100, set={"winner": lambda c: c.value})

# copy one variable into another every time it changes
cloud.mirror("score", "echo")

# full control with a handler
@cloud.on_change("request")
def answer(change):
    print(change.name, change.old, "->", change.value)
    change.set("response", change.number * 2)

cloud.run()          # blocks; or cloud.start() to run in the background

Variable names are written without the ☁ — it's added for you.

What a handler gets (change): .name, .value (string), .old, .number, .set(name, value). You can also call cloud.get("name") and cloud.set("name", value) anywhere.

Text

Cloud variables only hold numbers (max 256 digits). encode("hi") → "0809", decode("0809") → "hi". Each character is two digits: its position in cloudtrigger.encoding.CHARS plus 1 — use the same character list in your Scratch project to decode.

Command line

# just print changes
cloudtrigger watch 1234567890 -u blockblock2

# rules
cloudtrigger run 1234567890 -u blockblock2 \
  --rule "door=1 -> light=1" \
  --rule "score>100 -> winner=\$value, flash=1" \
  --rule "ping=* -> pong=1"

Ops: = != > <, * = any change, $value = the value that just changed. Rules can also go in a JSON file (--rules rules.json):

[{"var": "door", "op": "=", "value": "1", "set": {"light": "1"}}]

Password comes from a prompt or SCRATCH_PASSWORD; you can pass --session-id / SCRATCH_SESSION_ID instead.

TurboWarp (works even when Scratch's cloud is down)

Run your project at turbowarp.org/<project id> and point the bot at TurboWarp's cloud server. No password or Scratcher status needed:

cloud = CloudWatcher(1394305521, "blockblock2", server="turbowarp")
cloudtrigger watch 1394305521 -u blockblock2 --server turbowarp

The username is just a display name there. TurboWarp may reject names that look rude or impersonate someone. You can also pass any wss:// URL as server for other cloud servers.

Good to know

  • The account needs to be a Scratcher (not "New Scratcher") to use cloud variables.
  • Values Scratch sends right when you connect are stored but don't fire handlers (pass fire_on_initial=True to change that).
  • Sets are spaced ~0.11 s apart because Scratch drops faster ones.
  • It reconnects automatically if the connection drops.
  • One handler throwing an error doesn't stop the others.

Metadata

Release files for cloudtrigger 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudtrigger 0.2.0
File Size Uploaded Provenance
cloudtrigger-0.2.0.tar.gz 13.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cloudtrigger 0.2.0
File Interpreter ABI Platform
cloudtrigger-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.4 kB

Release files / cloudtrigger-0.2.0.tar.gz

Download URL cloudtrigger-0.2.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5238399e74fe20165ef7eb5bdd78d3c991fd7313fc9755b209f3bbf9df865698
BLAKE2b-256 checksum
How to use checksums
88d0b259ecdec296493e832b236ffb41d46412ca9a71e7e9ac1ee93b24fa82ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / cloudtrigger-0.2.0-py3-none-any.whl

Download URL cloudtrigger-0.2.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a13b79a1bb3578674c2b9ab6c7eb2c66a67e027d231cb7f81fb417fe90f0601
BLAKE2b-256 checksum
How to use checksums
1fc2e0236b668777b7864afbd10af22ab51878fbab928c264bd6539decea77f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for cloudtrigger 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page