Description

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.

Syntax

partyWatchShared(shared, [path], callback)

Parameters

shared

sharedObject: the shared object to watch

path (optional)

string: a path on the shared object to watch, e.g. position.x

callback

function: the function to call when shared is updated.

receives the new value as a parameter.

Returns

nothing

Examples

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);
}