The object returned by partyLoadShared()
is automatically watched and its property values are synchronized. Don't try to update all the values of the shared object at once by assigning a new object to the root variable. This will replace the shared object with an unshared one and break syncing.
DONT overwrite the the shared object with a new value.
shared = partyLoadShared("globals")
...
shared = {x: 10, y: 10}
DO assign values to properties on the shared object.
shared = partyLoadShared("globals")
...
shared.x = 10;
shared.y = 10;
DO use partySetShared() to replace all properties at once
shared = partyLoadShared("globals")
...
partySetShared(shared, **{x: 10, y: 10});**
Instead of storing references to the properties of your shared object in global variables, either access them directly when needed or store them in local variables.
DON'T:
var myX,myY;
function setup() {
shared = partyLoadShared("globals");
myX=shared.x;
myY=shared.y;
}
function draw() {
circfill(myX,myY,30);
}
DO:
var shared;
function setup() {
shared = partyLoadShared("globals");
}
function draw() {
let myX = shared.x;
let myY = shared.y;
ellipse(myX, myY, 30, 30);
}
var shared;
function setup() {
shared = getSharedData("globals");
}
function draw() {
ellipse(shared.x, shared.y, 30, 30);
}
Don’t repeatedly set a property every frame in the draw loop, if you can set it just when it needs to change.
Don't set shared object values every frame.