Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Multiplayer Network Games - Broadcasting Messages to All

Multiplayer Network Games - Broadcasting Messages to All

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 930 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

     

    In traditional MIT Scratch, we can broadcast a message that all sprites running on the stage can receive and handle. For multiplayer network games, this capability is extended so you can broadcast a message to all players’ computers.

    The message will be sent to the game server first, which then relays the message to all other players. Therefore, there might be some delay before all players receive that message.

     
     

    Broadcast Block

     

    To broadcast the message, you can use the following block in the multiplayer category:

    248b5341-4278-4f0b-ba8a-326942c62082-image.png

     
    It accepts these inputs:

    • Message Type: you can define any message type using the “when I receive” block, then choose that message type in this dropdown.

    • Parameter: you can optionally attach a parameter to this message

    • Receiver Scope: you can choose between “All Sprites” or “Original Sprites”. If “All Sprites” is selected, all sprites on all players’ playgrounds will be able to receive this message using the “when I receive” block. If “Original Sprites”, then only the original sprites added to the game will be able to receive this message, and the copies made by the game server on other computers/tabs will not receive this message, neither would the local sprites. For example, if a message is about giving a reward to a sprite, then it should only be handled once by the original sprite (not the copies).

     
    This block is an easy way to do almost anything synchronously across all the player computers. For example, to make a sprite change its costume, you can broadcast a message to all players, and then change the sprite’s costume when the message is received by each player’s computer.

    The only exception is that you should not change the speed or position of sprites using this method, since the game server takes full control of the motion and position of every sprite added to the game network.

     
     

    Demo 1 - Broadcast to All Sprites

     

    In this demo project, we repeatedly broadcast a message to all sprites, with the current timer value as the parameter. And for every sprite, when it receives this message, it will “say” it on the stage.

    https://play.creaticode.com/projects/6607f888b57a3da838c32b3f

     
    To run it, follow these steps:

    1. Create a game as the host on one computer/tab, and add the “BlueBall” sprite to the game network. Also, add a handler for the event of “greeting” that prints out the parameter briefly:

    8037ac27-5bfb-4cb5-a3fa-407e950d0625-image.png

     
    2. In another computer or an incognito tab, run the project as the guest, and add the obstacle sprite to the game network. Also, add a handler for the event of “greeting” that prints out the parameter briefly:

    6c67c990-f782-40b3-a339-b0c26d638901-image.png

     
    3. Switch back to the host player, and run the repeat loop to broadcast the “greeting” message to all sprites on all computers every 2 seconds:

    28755b5c-8257-4f03-8ac0-75b60cbf79e5-image.png
     
    As a result, all sprites on both computers, we will see both sprites saying the timer value every 2 seconds:

    msg.gif

     
     

    Demo 2 - Broadcast to Original Sprites Only

     

    For the same project, let’s change the broadcast target to “Original Sprites”:

    f38fcd25-fe6e-4ad7-a3e7-5d2b7b50a098-image.png

     
    As a result, only the original sprites (ball on left and square on right) will receive this message:

    msg2.gif

    1 Reply Last reply
    1

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode