Watches a shared object shared
and calls the provided callback
when any of its properties change. You can optionally provide a path on the object to watch.
partyWatchShared(shared, [path], callback)
sharedObject: the shared object to watch
string: a path on the shared object to watch, e.g. position.x
function: the function to call when shared
is updated.
receives the new value as a parameter.
nothing
Watch for any changes on shared
.
let shared;
...
shared = partyLoadShared("shared");
partyWatchShared(shared, onChange);
...
function onChange(data) {
console.log("received new data on shared!", data);
}
Watch for changes to property x
on shared
.
let shared;
...
shared = partyLoadShared("shared", {x: 0});
partyWatchShared(shared, "x", onChange);
...
function onChange(data) {
console.log("x changed!", data);
}