<aside> 🧟 This page is still a draft!
</aside>
In almost all cases you should not assign a new value to a variable that stores a p5.party shared object. Let’s look at an example.
Imagine we want to share a single point: an x and a y value.
let shared;
function preload() {
partyConnect(server_url, "hello_party");
shared = partyLoadShared("shared");
}
function setup() {
shared = {x: 10, y: 10} // WRONG!!!
}
This code runs, but won’t do what we want. Here is what it does do:
shared
in the global scope.preload()
it loads a shared object with partyLoadShared()
and assigns that object to shared
.setup()
it creates a new object (that isn’t shared) with x and y properties and assigns that new object to the shared
.<aside> 🧟 Since there are no variables that hold the shared object, it will get garbage collected.
</aside>
function preload() {
partyConnect(server_url, "hello_party");
shared = partyLoadShared("shared");
}
function setup() {
shared.x = 10; // RIGHT!!!
shared.y = 10; // RIGHT!!!
}