Log In  

How do I communicate between 2 or more PICO-8 instances on the desktop? Maybe you could make virtual GPIO pins that communicate with other PICO-8 instances on the host OS? What do you think, @zep?

P#63259 2019-04-05 12:50 ( Edited 2019-04-05 12:56)

Yes. Maybe some functions that transmit data between PICO-8's.

My idea is when the 1st PICO-8 instance is opened, it's given a temporary number, 1, and registered to a global table shared between all PICO-8's on the desktop. When you open another PICO-8, it's given 2, and registered to the same table that 1 was registered to. When you close PICO-8 instance 1, it would remove 1 from the table.

Here are some mock-up API functions that would allow this linking:

If n is omitted:
Returns the current PICO-8's instance number on the desktop (1, 2, 3, etc.)
If n is a number:
Returns the instance n's status: exists,cart,link
exists is true if the nth instance exists on the desktop, false otherwise.
cart is the cartridge file (or BBS ID) currently running by the nth instance.
link is the link that the nth instance is connected to.

Returns a table containing all instance numbers running on the desktop. For example, if instances 1, 3, and 4 are running, then the table contains 1, 3, and 4. As such:

name is the link name, as a string. If no name link exists on the desktop, the link is created automatically. If it already exists, then the current PICO-8 will connect to the link.
A link consists of a counter that represents how many PICO-8's are connected to it, and its Lua variable data. When a new PICO-8 connects to the link, it's incremented by 1. When a cartridge that connected to the link is reset or stopped, it's decremented by 1. When all PICO-8's have disconnected (the counter is 0), the link is deleted.

If name is omitted:
The current PICO-8 will disconnect from all connected links.
If name is a string:
The current PICO-8 will disconnect from name.
DISCONNECT() is automatically called without arguments when the cartridge is reset or stopped. This prevents excessive RAM usage on the host computer.

Returns the link the current PICO-8 is connected to.

Returns the value of the current link's variable var.

Sets the current link's variable var to the value of val.

Clears all variables in the current link, but doesn't affect the counter.

Please feel free to add more suggestions!

P#63393 2019-04-10 22:38

Maybe something like that could work. I haven't thought about it much. I think the exported HTML games for PICO-8 have the GPIO pins in a Javascript array, so in theory it should be possible, but I haven't really played around with the GPIO pins.

P#63688 2019-04-19 14:26

GPIO is only enabled for raspbian builds, for generic OSes you’d have to use serial communication (see manual) with standard streams (stdin/stdout) or filenames paramenters (-i path/to/input/file / -o path/out), with a wrapper program for the inter-program communication. One example here: https://www.lexaloffle.com/bbs/?tid=38732

P#91330 2021-04-30 16:31

GPIO can be used to communicate between multiple PICO-8 instances when they are exported as HTML. It requires additional javascript for interfacing. This code then communicates with the PICO-8 client via GPIO, and with a back end service, for example via WebSockets.

This is the approach I used in the online multi-player game Martian Dice which I shared earlier this week. Here the back end is actually running in the cloud, so that you can chat/play with anyone, but you can of course simply connect two or more clients running on the same machine, in different tabs/windows of your browser.

Martian Dice uses a custom GPIO protocol, very specific to the game and quite messy, as it evolved together with the game. However, a more generic protocol as StinkerB06 suggests is definitely possible. There is obviously no need to run the service in the cloud if you want to connect clients on the same machine. In that case, you can run a local service. This is the approach I used during development and testing.

In case anyone is interested, full source code is available on GitHub

P#91335 2021-04-30 18:27

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2023-02-09 00:24:17 | 0.016s | Q:16