# Multiplayer with hardware and blocks?

**URL:** <https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171>\
**Category:** Arcade\
**Created:** [February 8, 2020, 5:57pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171 "2020-02-08T17:57:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![EnteroPositivo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/enteropositivo/32/213_2.png) [@EnteroPositivo](https://forum.makecode.com/u/EnteroPositivo)\
**Post date:** [February 8, 2020, 5:57pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/1 "2020-02-08T17:57:02Z")

</div>

Hi All.

I have made some games using the multiplayer blocks avaliable ( _move player 2 with buttons, change player 2 score , …_ ) , also i’ve tested other ones made buy users

When i upload those games to two consoles joined with jacdac, **those games made with blocks don’t work in hardware they are only playable within the simulator**

I thought that making a multiplayer game with blocks will act as multiplayer games **once detected a jacdac connection** but seems that this doesn’t work like i expected.

**- Am i right or i am missing somehting ???**

Then i’ve fount the forum thread

> [@Hardware Multiplayer (game)](https://forum.makecode.com/t/hardware-multiplayer-game/132):
>
> Hey folks, For those lucky enough to get their hands on some Arcade hardware (by GHI or Kittenbot) here’s a sample that shows how to do multiplayer between devices! To play the game, load the UF2 on two devices and connect them via the headphone jack. Please note that the APIs I use here are subject to change. Also, this game cannot be played in the simulator right now (hardware only). Want to learn more about how it works? Check out JACDAC at [https://jacdac.org/](https://jacdac.org/) and our recent blog post [ht…](https://makecode.com/blog/ozette/ozette)

were there is a **real multiplayer game** that i can play in my consoles connected via jacdac, but that game is made using JavaScript instead of using blocks, so users learning makecode arcade with blocks can not make their own multiplayer games.

There is an existing jacdac-game extension but there isn’t information about how to use it neither how to use ControllerServices class. An extract of a portion of code from that class is:

```
...    
private askJoin(device: JDDevice): boolean {
            game.eventContext(); // initialize the game
            control.pushEventContext();
            game.showDialog("Arcade Detected", "Join?", "A = OK, B = CANCEL");
            let answer: boolean = null;
            controller.A.onEvent(ControllerButtonEvent.Pressed, () => answer = true);
            controller.B.onEvent(ControllerButtonEvent.Pressed, () => answer = false);
            pauseUntil(() =>
                // user answered
                answer !== null
                // server got joined
                || this.hasPlayers()
                // other driver dissapeared
                || !jacdac.devices().find(d => d.device_address == device.device_address)
            );
            // wait until we have an answer or the service
            control.popEventContext();

            // cache user answer
            if (answer !== null)
                this.promptedServers.push(device.udidl);

            // check that we haven't been join by then
            return !!answer
                && !this.hasPlayers()
                && !!jacdac.devices().find(d => d.device_address == device.device_address);
        }
...

```

so i see that there is code made for this purpose

**Is this class which make possible to have a real hardware multiplayer game done using blocks** without doing any more, or anybody has any sample on how to use jacdac-game extension or this class ?

---

<div class="post-metadata">

**Author:** ![EnteroPositivo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/enteropositivo/32/213_2.png) [@EnteroPositivo](https://forum.makecode.com/u/EnteroPositivo)\
**Post date:** [February 10, 2020, 12:53pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/2 "2020-02-10T12:53:46Z")

</div>

Perhaps was a big post, so i only want to know.

Can anybody make a multiplayer game to play with real consoles (syncthing sprites, …) using blocks ( not JavaScript) ?

( If not, then i will make an extension to do it )

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [February 10, 2020, 6:31pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/3 "2020-02-10T18:31:16Z")

</div>

Nope, we do not have blocks yet for hardware multiplayer. The only sample we really have for jacdac right now is the game you linked. There is some more info about jacdac and some helpful debugging tools here: [https://jacdac.org/](https://jacdac.org/)

---

<div class="post-metadata">

**Author:** ![EnteroPositivo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/enteropositivo/32/213_2.png) [@EnteroPositivo](https://forum.makecode.com/u/EnteroPositivo)\
**Post date:** [February 11, 2020, 12:22pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/4 "2020-02-11T12:22:21Z")

</div>

Thank you @richard

It’s almost done. I’ve made an extension to allow Real Multiplayer based on your JavaScript code

You can create a multiplayer game to play both on simulator and also download to consoles, it syncs any kind of srpites and shares images between consoles.

At the moment here is a screenshot, i must make some improvement and refactoring and i’ll make a post showing how to use the extensión 😉

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/ee134f90ff593a86c7084225c209785e1ac59cf0.png)

---

<div class="post-metadata">

**Author:** ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)\
**Post date:** [February 11, 2020, 1:04pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/5 "2020-02-11T13:04:02Z")

</div>

Excellent! Do you have a github repo for this extension?

---

<div class="post-metadata">

**Author:** ![EnteroPositivo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/enteropositivo/32/213_2.png) [@EnteroPositivo](https://forum.makecode.com/u/EnteroPositivo)\
**Post date:** [February 11, 2020, 8:56pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/6 "2020-02-11T20:56:28Z")

</div>

Yes i have it, give me one or 2 days more to make a stable versión and i will post all details

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [February 12, 2020, 11:03pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/7 "2020-02-12T23:03:39Z")

</div>

@EnteroPositivo you can usually detect whether or not you are in simulator by checking the available RAM so that the user doesn’t need to remember to flip that switch.

I think internally we use `control.ramSize() > 1024 * 200` to check if we are in the sim

---

<div class="post-metadata">

**Author:** ![mmoskal](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mmoskal/32/20_2.png) [@mmoskal](https://forum.makecode.com/u/mmoskal)\
**Post date:** [February 13, 2020, 2:48am UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/8 "2020-02-13T02:48:03Z")

</div>

Alternatively control.deviceDalVersion should return string sim. It will be linux on RPi and sem version otherwise.

Some sort of feature detection might be eventually needed though…

---

<div class="post-metadata">

**Author:** ![EnteroPositivo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/enteropositivo/32/213_2.png) [@EnteroPositivo](https://forum.makecode.com/u/EnteroPositivo)\
**Post date:** [February 13, 2020, 8:00am UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/9 "2020-02-13T08:00:40Z")

</div>

The switch is needed for this cases:

### 1- When you want to test your custom wait screen in the sim

 ![testing_wait_screen](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/7852f49c298134ab6ec9a8c004d5a35638f2788c.png)

### 2- When you need to play the game in the sim

 ![testing_game](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/8894a38160815467ec60929f95fafcb404674976.png)

Anyway you have give me a good idea, to use your check sim formula and when in console **“wait allways for connection”** no matther the possition of that switch

So that switch will only works in sim mode

---

<div class="post-metadata">

**Author:** ![Eretick](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/eretick/32/3954_2.png) [@Eretick](https://forum.makecode.com/u/Eretick)\
**Post date:** [April 18, 2021, 2:21am UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/10 "2021-04-18T02:21:18Z")

</div>

Hi! i`m new here, but this is looks great. So what about github link for extension you promised dew messages earlier? And maybe some kind of tutorial?

---

<div class="post-metadata">

**Author:** ![Moobot](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Moobot](https://forum.makecode.com/u/Moobot)\
**Post date:** [April 25, 2021, 4:52pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/11 "2021-04-25T16:52:44Z")

</div>

Hi @Eretick , [EnteroPositivo](https://forum.makecode.com/u/EnteroPositivo) posted the github extension and a tutorial both over here: [New Extension: Real Multiplayer (with blocks) - #3 by EnteroPositivo](https://forum.makecode.com/t/new-extension-real-multiplayer-with-blocks/1202/3)

Cheers

---

<div class="post-metadata">

**Author:** ![Moobot](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@Moobot](https://forum.makecode.com/u/Moobot)\
**Post date:** [April 25, 2021, 4:55pm UTC](https://forum.makecode.com/t/multiplayer-with-hardware-and-blocks/1171/12 "2021-04-25T16:55:03Z")

</div>

However, I was not able to get it to work. Import does not give errors, but I don’t see any new blocks.
