Eng:Mesh

Mesh is a method of having multiple Scratch projects interact, even if they are on different computers. Mesh allows projects to share variables and broadcasts, opening up a surprisingly large field of new project opportunities since technically sharing these two features is actually all that is needed to write most interacting programs.

How to get Mesh
There are three ways to access Mesh in Scratch 1.4:

Mesh by Beta 1.4
The early beta version of Scratch 1.4 had Mesh enabled. This version was shared at the first formal Scratch Day. Only a few Scratchers were able to get this version. The public beta from October had it enabled as well. Mesh could be enabled by shift-clicking on the Share button.

An IMAGE File of this build can be downloaded here.

Mesh by External Application
Many Scratch modifications come with Mesh already included, without having to alter anything. One mod intended solely for the enabling of Mesh is available for download here.

Snap! and Panther also come with Mesh pre-enabled; the latter has many blocks to use mesh.

Mesh by Modification of Scratch
This requires editing of Scratch's System Browser.
 * 1) Shift-click the R in the Scratch logo.
 * 2) Select turn fill screen off.
 * 3) A white area at the bottom and right side of the Scratch program will appear. Click on the white area and select open....
 * 4) Select 'browser''.
 * 5) The System Browser will appear. Select Scratch-UI-Panes - ScratchFrameMorph - menu/button actions - addServerCommandsTo:.
 * 6) Change the "t2 ← true" text in the code to "t2 ← false".
 * 7) Right-click on the System Browser and select accept. (If you are on a Mac or using Linux, then you will need to hold the Control key and then click).
 * 8) Enter in your initials and click accept.
 * 9) Close the System Browser.
 * 10) Shift-click the R again and select turn fill screen on.


 * If you wish to save the edits to the System Browser, Shift-click the R and select save image for end-user to save the IMAGE file.
 * If Mesh has been saved but is not wanted anymore, the steps to enable Mesh can be reverted to remove it.
 * To get the ← symbol, press _ ( [Shift] + [-] ).

How to Host and Join Mesh sessions
A Scratch program that has Mesh available looks like an un-edited Scratch program. However, Shift-clicking Share will reveal two new buttons: Host Mesh and Join Mesh. To host Mesh: To join a Mesh session:
 * Host Mesh begins a Mesh session.
 * Join Mesh allows you to join a Mesh session.
 * 1) Select Host Mesh.
 * 2) The hosting computer's IP address will be shown. However, this is not the only IP address that can be used to access the Mesh session, as you may want to use others (like your external IP address or one provided by another program).
 * 1) Select Join Mesh.
 * 2) Enter in the IP address of the computer that is hosting the Mesh session.

If the IP address of the computer has been forgotten, the Share button can be Shift-clicked and the button Show IP address selected.

A Mesh session can contain unlimited Scratch programs.

Connecting Over the Internet
Normally, Mesh only works over a LAN (Local Area Network); however, certain programs (such as LogMeIn Hamachi) allow users to create their own Mesh network, thereby allowing users from across the world to play Scratch projects together.

If you want to be able to let others join a Mesh hosted by you without using a program or configuring anything on their end, forward port 42001 on your router. For more information, see port-forwarding on Wikipedia or search for "port-forwarding" on the Internet. This can also be done with a port-forwarding program such as grappl.

The beta of 1.4 had a built-in system to allow Mesh to be used across the Internet without external programs or configuration.

How to Program With Mesh's Features
Programming with Mesh is the same as programming without it - the interface is the same as always. But when a Mesh session is in activity, it changes: If a broadcast is created on one Scratch program, it does not show up in the broadcast list on the other Scratch programs - however, broadcasts will still be received on all Scratch programs. To create a broadcast for use in all Scratch programs, the broadcast has to be made on each Scratch program.
 * Broadcasts are received on all Scratch programs.
 * Each Scratch program's variables are available for use on the others.

To use variables that are from a different Scratch program, the Sensor Value block can be used - all the variables from the other Scratch programs will show in the drop-down menu. That is the only place they will be available - the Variables section will only show the variables made on the Scratch program that is being used.

How to Send a List
To send a list over Mesh, use this to transmit: when I receive [send list v] set [# v] to [1] repeat (length of [list to send v]) set [list v] to (join (list) (join (|) (item (#) of [list to send v])) change (#) by (1) end broadcast [list is ready v] To receive a list, use this: when I receive [list is ready v] set [# v] to [1] repeat (length of ([list v] sensor value)) if <(letter (#) of ([list v] sensor value)) = [|]> add [] to [List v] else replace item (last v) of [List v] with (join (item (last v) of [List v]) (letter (#) of ([list v] sensor value))

Troubleshooting
A lot of things can go wrong when activating and using Mesh, so here's a few things to check:
 * Make sure you shift-click share rather than just clicking it to access Mesh
 * Make sure there is a period after 'false' in the System Browser
 * If you did not save your changes to the System Browser, next time you open Scratch, Mesh does not work anymore
 * If you have installed a program such as Hamachi, make sure you use your Hamachi IP rather than your computer's one
 * Scratch sometimes gives you an incorrect IP; find out your IP through other means
 * Make sure you are connecting over a LAN network rather than over the Internet (unless you have properly configured your router)
 * Make sure that the variables and broadcasts are called exactly the same (it's case-sensitive) in each project

Internals of Mesh
Mesh, in its rawest form, is simply remote sensor connections. As a matter of fact, any program that communicates through remote sensor connections can communicate through mesh with no modifications. Instead of enabling remote sensor connections, you would host mesh.

Because of remote sensor connections, any broadcast or variable gets sent to any computer listening on the socket (it is mainly this loophole that allows for 4 player meshes). Mesh "servers" take advantage of remote sensor connections, as remote sensor connections allows for multiplayer. FireMMO is a good example of remote sensor connections used for multiplayer servers.