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?
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!
[Please log in to post a comment]