Skip to content

Commit 268787f

Browse files
committed
Add extensions/delta/sync.md
1 parent 3a5e6d7 commit 268787f

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

extensions/delta/sync.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# CLΔ Sync Plugin
2+
Enables list/variable synchronization between players for CLΔ Core.
3+
4+
CLΔ Sync is a powerful plugin that allows you to synchronize Scratch variables and lists between different players in real-time without needing any additional code. It's built to be highly efficient, de-duplicating redundant data and batching events to keep your project running fast with minimal network traffic.
5+
6+
## What is a Tag?
7+
8+
A **Tag** is the most important concept in this plugin. Think of it as a **public, network-safe nickname** or a **mailing label** for your variable.
9+
10+
* **The Problem:** Your "my variable" on "Sprite1" is not the same as your friend's "my variable" on their "Sprite1." They are two different variables with different internal IDs.
11+
* **The Solution:** You both agree on a unique, shared "tag," like `"player_1_x_position"`.
12+
* **You (Player 1)** link *your* variable to the tag `"player_1_x_position"`.
13+
* **Your Friend (Player 2)** links *their* variable to the *exact same tag*.
14+
15+
Now, when you update your variable, the plugin sends a message saying: "Hey everyone, the variable tagged `"player_1_x_position"` just changed to `120`." Your friend's plugin, which is listening for that tag, receives the message and automatically updates *their* bound variable to `120`.
16+
17+
**Tags *must* be unique for each variable or list you want to sync.**
18+
19+
---
20+
21+
## Getting Started
22+
*CLΔ Core is required for the sync plugin to work. Make sure you load it first before loading CLΔ Sync.*
23+
24+
Let's sync a "global variable" (on the Stage) between two players.
25+
26+
### Player A (Sender)
27+
1. Go to the Stage and create a new variable named `(Player A X)`.
28+
2. Drag out this block and set it up like this:
29+
* **[enable]** broadcast of **[global variable]** **[Player A X]** in channel **[default]** and assign it as tag **[p1_x]**
30+
31+
Now, any time you change `(Player A X)`, its new value is broadcast to everyone in the "default" channel with the tag "p1_x".
32+
33+
### Player B (Receiver)
34+
1. Go to the Stage and create a new variable named `(Player A's X)`.
35+
2. Drag out the *exact same* block. The only difference is your local variable name.
36+
* **[enable]** broadcast of **[global variable]** **[Player A's X]** in channel **[default]** and assign it as tag **[p1_x]**
37+
38+
### Result
39+
Now, whenever Player A changes their `(Player A X)` variable, Player B will instantly see their `(Player A's X)` variable update to match. You have successfully synced a variable!
40+
41+
To stop syncing, simply run the same block with **[disable]** selected. This will un-link the variable and restore it to a normal, non-networked state.
42+
43+
---
44+
45+
## How It Works
46+
47+
* **Change Detection** - The plugin wraps your variable in a special "proxy" object that instantly detects when its value changes.
48+
* **De-duplication** - If you set a variable to the *same value* it already has (e.g., `set [my_var v] to (10)` when it's already 10), the plugin knows not to send an unnecessary network message. This dramatically reduces network spam.
49+
* **Event Batching** - Instead of sending a message for every single change (which can be 30 times a second!), the plugin collects all unique changes that happen in a small time window (e.g., 100ms) and sends them as a single, efficient packet.
50+
* **Idle Detection** - If nothing changes for more than a second, the sync engine goes to sleep to save resources, waking up instantly when a new change occurs.
51+
52+
---
53+
54+
## Reference
55+
56+
### Sync Commands
57+
Use these blocks to start or stop syncing a variable.
58+
59+
> **[MODE] broadcast of [TYPE] [VAR] in channel [CHANNEL] and assign it as tag [TAG]**
60+
> This is the main block. It links a local variable/list to a network tag and sends any changes to *everyone* in that channel.
61+
> * **MODE:** `enable` or `disable`.
62+
> * **TYPE:** The scope and type of your variable (e.g., `global variable`, `local list`).
63+
> * **VAR:** The name of your variable or list.
64+
> * **CHANNEL:** The "room" to send the data to.
65+
> * **TAG:** The unique network nickname for this variable.
66+
67+
> **[MODE] multicast of [TYPE] [VAR] in channel [CHANNEL] with peers in [MCAST] list [LIST] and assign it as tag [TAG]**
68+
> Same as broadcast, but it only sends changes to the peers whose usernames are in your specified **[LIST]**. Useful for teams.
69+
> The value of **[LIST]** can be changed during runtime, and accordingly, the peers you multicast to.
70+
71+
> **[MODE] unicast of [TYPE] [VAR] with [PEER] in channel [CHANNEL] and assign it as tag [TAG]**
72+
> Same as broadcast, but it only sends changes to a *single* peer, specified by their username. Useful for direct messages or trading.
73+
74+
### Sync Tags (Reporters)
75+
Use these blocks to check the status of your tags.
76+
77+
> **is tag [TAG] in use?**
78+
> Returns `true` if you have already used this tag to sync a variable/list.
79+
80+
> **tag [TAG] currently bound to**
81+
> Reports what a tag is linked to on your machine (e.g., "global variable: Player A X").
82+
83+
> **is tag [TAG] broadcasting in channel [CHANNEL]?**
84+
> Returns `true` if the tag is currently set to broadcast mode in that specific channel.
85+
86+
> **is tag [TAG] multicasting...**
87+
> Returns `true` if the tag is currently set to multicast mode with that specific list.
88+
89+
> **is tag [TAG] unicasting...**
90+
> Returns `true` if the tag is currently set to unicast mode with that specific peer.
91+
92+
---

0 commit comments

Comments
 (0)