Giter Site home page Giter Site logo

gitter-badger / scratch3-bridge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paulolc/scratch3-bridge

0.0 0.0 0.0 1.06 MB

Javascript library to exchange data with Scratch 3 online projects using cloud variables

License: MIT License

JavaScript 100.00%

scratch3-bridge's Introduction

scratch3-bridge

Javascript library to exchange data with Scratch 3 online projects using cloud variables

Introduction

This library allows you to develop programs in JavaScript, on any platform that JavaScript runs (PC, Android, Mac, even on a server running in the Cloud) to communicate with Scratch 3 projects. Since JavaScript is a high level programming language, you can develop programs that do not have the Scratch 3 restrictions but which can communicate and extend your Scratch 3 projects. This will allow you to do virtually anything from your Scratch 3 projects like performing complex calculations, controlling robots or other kind of devices, accessing the internet and much more!

How to use

If on node.js install the dependency using npm

npm install scratch3-bridge

On your code

  1. On Scratch online you'll need to Remix the template project "S3BRIDGE: node.js connector"

  2. Initialization: On your javascript program, instantiate and initialize a scratch bridge object with your MIT Scratch credentials and the target scratch project id:

    const projectId = 12345678;
    let msgrbridge = new ScratchBridge( "ascratchuser", "theuserpassword", projectId);

    HINT: If you don't pass any parameters to the ScratchBridge constructor, it will prompt the user for them.

  3. Open the connection: Call connect() on the newly instantiated scratch bridge object.

    msgrbridge.connect();
  4. Connection started (OPTIONAL): Get notified of when the connection with the Scratch project is established by defining a listener function for the 'connect' event

    msgrbridge.on('connect', () => {
          console.log( "Connected!! Ready to send to and receive data from Scratch."
    }
  5. Receive data from Scratch: Define a listener function to the 'data' event which is raised on messages coming from the target scratch project. Two objects are passed as parameters to the listener function:

    • The message which can be either a string or an array of strings

    • The sender id of the message (Integer). (see the "sender id" section below)

      msgrbridge.on('data', ( msg, asender ) =>{
        // 
      }
  6. Send data to Scratch:

    msgrbridge.send( sender, `Message written on the server: ${msg}` );

The sender id

It is an integer with the identifier of which scratch project running instance sent the message. You can use this sender id later to respond back to the specific scratch project running instance that sent the original message. For instance, if your scratch project is a game and if multiple people are playing, the sender id will be able to distinguish from multiple running instances of the game.

scratch3-bridge's People

Contributors

paulolc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.